humbl3man / helpful.js

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

Home Page:https://togatech.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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])

About

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

https://togatech.org/

License:GNU General Public License v3.0


Languages

Language:JavaScript 100.0%