inf286 v1.0.2
INF286
Lab 9 Assignment for NKU INF-286; Publishing NPM Library.
Installation
To install this library, run the following command in project terminal.
npm install inf286
Pipe Function
pipe(functions..)
receives a parameter of functions, then composes them from left to right.
// Import library
const { pipe } = require('inf286');
const lowercase = (str) => str.toLowerCase();
const capitalize = (str) => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
const reverse = (str) => str.split('').reverse().join('');
// pipe will execute in order: lowercase, captalize, reverse.
const fn = pipe(lowercase, capitalize, reverse);
// Returns: "dlrow olleH"
console.log(fn('Hello World'));
isNode Variable
isNode
is a Boolean that checks if the process is running in NodeJS
// Import library
const { isNode } = require('inf286');
console.log(isNode);
isBrowser Variable
isBrowser
is a Boolean that checks the window and document objects to see if the code is running in the Browser
// Import library
const { isBrowser } = require('inf286');
console.log(isBrowser);
isJest Variable
isJest
is a Boolean that checks the process env to see if the code is running in Jest
// Import library
const { isJest } = require('inf286');
console.log(isJest);
base64ToUint8 Function
base64ToUint8(String)
takes a string and converts it from base 64 to an Uint8 array.
// Import Library
const { base64ToUint8 } = require('inf286');
/*
Returns:
Uint8Array(7) [
29, 233, 101,
161, 106, 43,
149
]
*/
console.log(base64ToUint8("Hello World"));
isAbsoluteUrl Function
isAbsoluteUrl(String URL)
takes a URL as a string and returns a boolean if it's a valid URL.
const { isAbsoluteUrl } = require('inf286');
console.log(isAbsoluteUrl("https://google.com")); // true
console.log(isAbsoluteUrl("//google.com")); // false
repeatedSubstring Function
repeatedSubstring(String)
takes a list of characters and returns a boolean if it's repeated.
// Import Library
const { repeatedSubstring } = require('inf286');
console.log(repeatedSubstring("aa")); // true
console.log(repeatedSubstring("ab")); // false
randomIp Function
randomIp()
generates a random IP Address returned as a string.
// Import Library
const { randomIp } = require('inf286');
console.log(randomIp()); // 9.236.59.16
generateString Function
generateString(int length, String characters)
takes an integer length and String list of characters and returns a random String.
// Import Library
const { generateString } = require('inf286');
console.log(generateString(2, 'ab')); // ab, aa, ba, bb
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.