Skip to content

ovanderzee/my-lib

Repository files navigation

CircleCI Coverage Status

my-lib

Library of recurring, unconnected but pure functions

Install and usage

Install the package as npm package. Provided are a umd-formatted file in the dist folder to require or to just load

<script src="../../node_modules/dist/myLib.js"></script>
<script src="https://unpkg.com/my-lib@latest"></script>

and an es-module in the module folder to import the separate functions or to import all

import { isAlphaNumeric } from 'my-lib'
import * as myLib from 'my-lib'

API

arrayCombination(array1, array2)

Find unique values from both arrays

Parameters

  • array1 (unknown[])
  • array2 (unknown[])

Return type

the combination

unknown[]

arrayFromCommaSeparatedList(commaSeparatedList)

Process comma separated list to a sanitised array with normalised strings

Parameters

  • commaSeparatedList (string)

Return type

array with separate strings

string[]

arrayFromQuery(cssQuery)

Create a genuine array from a css-query

Parameters

  • cssQuery (string)

Return type

array with Elements

Node[]

arrayIntersection(array1, array2)

Find unique values appearing in both arrays

Parameters

  • array1 (any[])
  • array2 (any[])

Return type

the intersection

unknown[]

deepClone(variable)

Recursively copy all indivisible data to new object Pay attention to Date and RegExp objects

Parameters

  • variable (any)

Return type

the same data with different references

any

forceStringify(value)

Try generic ways to produce a string, an empty string if necessary

Parameters

  • value (any)

Return type

string represention of anything

string

greet()

The sake of package; log the console

Return type

void

hasOwnProperty(object, prop)

Check for existence of property in object

Parameters

  • object (Record<string, unknown>)
  • prop (string)

Return type

the object has the property as its own property -- not inheriting it

boolean

isAlphaNumeric(word)

Test for being a string consisting of letters and/or digits, for being undelimited

Parameters

  • word (string)

Return type

consists of letters and/or digits only

boolean

isAttachedToDom(elm)

Check node for being part of the DOM

Parameters

  • elm (Element)

Return type

true when the node is on the webpage

boolean

isChar(char)

Test value for being a character; a string with a length of one

Parameters

  • char (string)

Return type

is a single character

boolean

isDigit(char)

Test value for being a string representation of a digit

Parameters

  • char (string)

Return type

is a number 0-9

boolean

isEqualSigns(...nums)

Check all arguments for being a number with the same sign (Zero is sign-neutral)

Parameters

  • nums (number[])

Return type

equality

boolean

isExactMatch(word, regex)

Check for a match covering the string entirely

Parameters

  • word (string)
  • regex (RegExp)

Return type

all characters of the word were described in regex

boolean

isFundamental(value)

Check value for indivisible: string, number, boolean, bigint, symbol, undefined, null, function

Parameters

  • value (unknown)

Return type

boolean

isLetter(char)

Test value for being a letter

Parameters

  • char (string)

Return type

char is a letter

boolean

isLower(char)

Test value for being a lowercase letter

Parameters

  • char (string)

Return type

char is a lower-case letter

boolean

isPrimitive(value)

Check value for being a primitive but leave out the anti-value undefined;

Parameters

  • value (unknown)

Return type

is a primitive

boolean

isUpper(char)

Test value for being an uppercase letter

Parameters

  • char (string)

Return type

char is a upper-case letter

boolean

isUsableNumber(...nums)

Test for values with which calculations can be done

Parameters

  • nums (number[])

Return type

every argument is a usable number

boolean

isWrappedPrimitive(value)

Check the variable for living in an object wrapper These can be generated by new String / Number etc. see https://developer.mozilla.org/en-US/docs/Glossary/Primitive

Parameters

  • value (unknown)

Return type

is a wrapped primitive

boolean

mathAvg(seq)

Calculate average of array with Numbers

Parameters

  • seq (number[])

Return type

the average of the numbers

number

mathSum(seq)

Calculate sum of array with Numbers

Parameters

  • seq (number[])

Return type

the sum of the numbers

number

roundAtDecimals(origin, decimals)

Round at decimals

Parameters

  • origin (number)
  • decimals (number)

Return type

the rounded number

number

roundAtDigits(origin, digits)

Round at digits; round with significance

Parameters

  • origin (number)
  • digits (number)

Return type

the rounded number

number

roundAtDigitsExponent(origin, digits)

Round at digits to exponential notation; round with significance

Parameters

  • origin (number)
  • digits (number)

Return type

the rounded number as exponent

string

stringify(value)

Convert anything to a string, an empty string if necessary. Expect sensible but not consistent cross-environment behaviour on functions.

Parameters

  • value (any)

Return type

string represention of anything

string

Demo

see demo folder

About

library of recurring, unconnected functions

Resources

Stars

Watchers

Forks

Packages

No packages published