Giter Site home page Giter Site logo

humbl3man / helpful.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from togatech/helpful.js

0.0 1.0 0.0 150 KB

A collection of helpful JavaScript functions, started by TogaTech.org and built by the open-source community

Home Page: https://togatech.org/

License: GNU General Public License v3.0

JavaScript 100.00%

helpful.js's Introduction

TogaTech Logo

helpful.js

Build Status Version License Monthly Downloads Total Downloads

A collection of helpful JavaScript functions, started by TogaTech.org and built by the open-source community

To contribute to helpful.js, please see the contributing guide.

Table of Contents

Imports

Browser Import

For the browser, only ./helpful.js or ./helpful.min.js is required and has all dependencies bundled inside the single file. We recommend including ./helpful.min.js.map in the same directory as ./helpful.min.js, which allows a browser to reconstruct the original unminified file in the debugger.

<script type="text/javascript" src="./helpful.min.js"></script>
<script>
	helpful.stringToArray("hello");
	helpful.duplicateArray([0, 1, 1, 3, 5]);
	...
</script>

Node.js NPM Import

Helpful.js is available through the NPM registry. To install helpful.js, use the following command in the terminal:

npm install @togatech/helpful-js

Make sure to run the test cases to ensure that helpful.js works properly:

npm test

To include helpful.js in your code:

const helpful = require("@togatech/helpful-js");
helpful.stringToArray("hello");
helpful.duplicateArray([0, 1, 1, 3, 5]);
...

To include specific helpful.js methods in your code:

const { stringToArray, duplicateArray } = require("@togatech/helpful-js");
stringToArray("hello");
duplicateArray([0, 1, 1, 3, 5]);
...

Node.js File Import

For node.js file import, place the ./helpful.js or ./helpful.min.js file in your project directory.

Make sure to run the test cases to ensure that helpful.js works properly (you will need to add the ./test folder to the project directory):

npm install mocha --save-dev
mocha

To include helpful.js in your code:

const helpful = require("./helpful.min.js");
helpful.stringToArray("hello");
helpful.duplicateArray([0, 1, 1, 3, 5]);
...

To include specific helpful.js methods in your code:

const { stringToArray, duplicateArray } = require("./helpful.min.js");
stringToArray("hello");
duplicateArray([0, 1, 1, 3, 5]);
...

Minify

If you would like to minify the code yourself instead of using the provided tenvoy.min.js (and optional tenvoy.min.js.map), you can use UglifyJS 3 to minifiy the code yourself.

To install UglifyJS 3 as a command line app through NPM, run npm install uglify-js -g.

After UglifyJS 3 has been installed, you can run the following commands in your terminal:

uglifyjs ./helpful.js -o ./helpful.min.js -c -m --source-map "filename='./helpful.min.js.map',url='helpful.min.js.map'"

Contributing

To contribute to helpful.js, please see the contributing guide and open a pull request. We look forward to reviewing your contributions!

Methods

General

stringToArray

Converts a string into an array of individual characters

let array = helpful.stringToArray("test"); // ["t", "e", "s", "t"]

Parameters:

  • string: string ("test")

Return Type: Array (["t", "e", "s", "t"])

duplicateArray

Duplicates an array by creating a new array and transferring all the elements from the first array

let array = helpful.duplicateArray(["t", "e", "s", "t"]); // ["t", "e", "s", "t"]

Parameters:

  • array: Array (["t", "e", "s", "t"])

Return Type: Array (["t", "e", "s", "t"])

differenceOfArrays

Finds the difference between two arrays (any identical elements in the second array are removed from the first array)

let differenceArray = helpful.differenceOfArrays([2, 1], [2, 3]); // [1]

Parameters:

  • array1: Array ([2, 1])
  • array2: Array ([2, 3])

Return Type: Array (Array [1])

sumOfArrays

Finds the sum of two arrays (the two arrays are combined)

let sumArray = helpful.sumOfArrays([1, 2], [3, 4]); // [1, 2, 3, 4]

Parameters:

  • array1: Array ([1, 2])
  • array2: Array ([3, 4])

Return Type: Array (Array [1, 2, 3, 4])

capitalize

Capitalizes the first letter of every word

let capitalizedWord = helpful.capitalize('heLLo'); // Hello
let capitalizedSentence = helpful.capitalize('hello javaScript world!'); // Hello Javascript World!

Parameters:

  • string: string ("heLLo")

Return Type: string ("Hello")

Hex

hex.convertFromString

Converts a string to hexadecimal

let hex = helpful.hex.convertFromString("test"); // "74657374"

Parameters:

  • string: string ("test")

Return Type: string ("74657374")

hex.convertToString

Converts hexadecimal to a string

let string = helpful.hex.convertToString("74657374"); // "test"

Parameters:

  • hex: string ("74657374")

Return Type: string ("test")

hex.convertFromBytes

Converts a bytes array to hexadecimal

let hex = helpful.hex.convertFromBytes(new Uint8Array([116, 101, 115, 116])); // "74657374"

Parameters:

  • bytes: Uint8Array (Uint8Array [116, 101, 115, 116])

Return Type: string ("74657374")

hex.convertToBytes

Converts hexadecimal to a bytes array

let bytes = helpful.hex.convertToBytes("74657374"); // Uint8Array [116, 101, 115, 116]

Parameters:

  • hex: string ("74657374")

Return Type: Uint8Array (Uint8Array [116, 101, 115, 116])

helpful.js's People

Contributors

cmeone avatar humbl3man avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.