npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

utilitylib-js

v2.0.0

Published

little util library

Downloads

11

Readme

Utilitylib-js

utilitylib is a little utils library for javascript developper

Open Source Love Maintainability Test Coverage GitHub top language example workflow

Installation, import and usage

install library

npm install utilitylib-js

import all library

// import
const util = require('utilitylib-js');

// usage
util.object.clone(objectToClone);

or import just a part of library

// import
const { object } = require('utilitylib-js');

//usage
object.clone(objectToClone);

or just import one method

// import
const { clone } = require('utilitylib-js/src/object');

// usage
clone(objectToClone);

Functions

isNumber(number) ⇒ boolean

check if entry is number

Kind: global function
Returns: boolean - return true if value is a number
Categry: Number
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | number | any | value for check is number |

Example

isNumber(5)
// => true

merge(array, arrayToMerge) ⇒ Array

merge two array

Kind: global function
Returns: Array - return array merged
Category: Array
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | array | Array | first array | | arrayToMerge | Array | array for merge |

Example

merge([1, 2], [3, 4])
// => [1, 2, 3, 4]

clone(array) ⇒ Array

clone an array

Kind: global function
Returns: Array - return new instance of array
Category: Array
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | array | Array | array for clone |

Example

clone([1, 2])
// => [1, 2]

diff(arrayOne, arrayTwo) ⇒ Array

Compare two array and return diff

Kind: global function
Returns: Array - return array of diff between two array
Category: Array
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | arrayOne | Array | first array | | arrayTwo | Array | array for comparaison |

Example

diff([1, 2], [1, 3])
// => [2, 3]

isArray(array) ⇒ boolean

check if entry is array

Kind: global function
Returns: boolean - return true if value is a array
Category: Array
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | array | any | value for check is array |

Example

isArray([1, 2])
// => true

removeAll(array, values) ⇒ Array

remove values in array

Kind: global function
Returns: Array - return array without value to remove
Category: Array
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | array | Array | array contain values for check | | values | Array | array of values to remove |

Example

removeAll([1, 2, 2, 3, 4], [2, 4])
// => [1, 3]

remove(array, ...values) ⇒ Array

remove values in array

Kind: global function
Returns: Array - return array without value to remove
Category: Array
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | array | Array | array contain values for check | | ...values | any | any values to remove |

Example

remove([1, 2, 3, 4], 1, 2)
// => [3, 4]

uniq(array) ⇒ Array.<any>

return array of uniq value work with array of object

Kind: global function
Returns: Array.<any> - return array of uniq values
Category: Array
Since: 1.2.0

| Param | Type | Description | | --- | --- | --- | | array | Array.<any> | of values any type |

Example

uniq([1, 2, 4, 5, 5, 123, 123, 132])

// => [1, 2, 4, 5, 123, 132]

randomNum(min, max) ⇒ number

generate random num beetween two number

Kind: global function
Returns: number - return number generated beetween two values
Category: Number
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | min | number | min value | | max | number | max value |

Example

randomNum(1, 8)
// => 6

isPrime(number) ⇒ boolean

check if number is prime

Kind: global function
Returns: boolean - return true if this number is a prime number
Category: Number
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | number | number | number for check |

Example

isPrime(7)
// => true

even(number) ⇒ boolean

check if number is even

Kind: global function
Returns: boolean - return true if number is even
Category: Number
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | number | number | number for check |

Example

even(4)
// => true

odd(number) ⇒ boolean

check if number is odd

Kind: global function
Returns: boolean - return true if number is odd
Category: Number
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | number | number | number for check |

Example

odd(5)
// => true

isEqual(objectOne, objectTwo) ⇒ boolean

compare object equality

Kind: global function
Returns: boolean - return true if two object is equal
Category: Object
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | objectOne | object | first object to compare | | objectTwo | object | other object for comparaison |

Example

isEqual({ name: 'test' }, { name: 'test' })
// => true

clone(objectToClone) ⇒ object

clone object

Kind: global function
Returns: object - new instance of this object
Category: Object
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | objectToClone | object | object to clone |

Example

clone({ name: 'test' })
// => { name: 'test' }

clones(objectsToClone) ⇒ Array.<object>

clone all object in array

Kind: global function
Returns: Array.<object> - return array of object cloned
Category: Object
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | objectsToClone | Array.<object> | array of object |

Example

clones([{ name: 'test' }])
// => [{ name: 'test' }]

isEmpty(object) ⇒ boolean

check if object is empty

Kind: global function
Returns: boolean - return true if object is empty
Category: Object
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | object | object | object for check |

Example

isEmpty({})
// => true

merge(object, objectToMerge) ⇒ object

merge two object

Kind: global function
Returns: object - return merged object
Category: Object
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | object | object | one object | | objectToMerge | object | object for merge |

Example

merge({ name: 'snow' }, { firstname: 'jhon' })
// => { name: 'snow', firstname: 'jhon' }

isObject(object) ⇒ boolean

check if entry is object

Kind: global function
Returns: boolean - return true if value is a object
Category: Object
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | object | any | value for check is object |

Example

isObject({ name: 'test' })
// => true

isVowel(letter) ⇒ boolean

check if letter is vowel

Kind: global function
Returns: boolean - return true if letter is vowel
Category: String
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | letter | string | string letter |

Example

isVowel('A')
// => true

isVowels(letters) ⇒ array

check if letters have vowel or consumn

Kind: global function
Returns: array - return array of boolean
Category: String
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | letters | array | array of letters |

Example

isVowels(['a', 'c', 'e'])
// => [true, false, true]

isConsumn(letter) ⇒ boolean

check if letter is consumn

Kind: global function
Returns: boolean - return true if letter is consumn
Category: String
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | letter | string | string letter |

Example

isConsumn('b')
// => true

isConsumns(letters) ⇒ array

check if letters have consumn or vowel

Kind: global function
Returns: array - return array of boolean
Category: String
Since: 1.0.0

| Param | Type | Description | | --- | --- | --- | | letters | array | array of letters |

Example

isConcumns(['a', 'b', 'c'])
// => [false, true, true]

getInitialName(fullname, separator) ⇒ string

get initial in full name

Kind: global function
Returns: string - return initial J S
Category: String
Since: 1.0.0

| Param | Type | Default | Description | | --- | --- | --- | --- | | fullname | string | | fullname 'jhon snow' | | separator | string | " " | separtor is string for separate initial default ' ' |

Example

getInitialName('jhon snow', '-')
// => 'J-S'

isString(string) ⇒ boolean

check if entry is string

Kind: global function
Returns: boolean - return true if value is a string
Category: String
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | string | any | value for check is string |

Example

isString('test')
// => true

camelCaseToOtherCase(value, separator) ⇒ string

convert value in camelCase to kebab-case or snake_case

Kind: global function
Returns: string - return value in kebab-case or snake_case
Category: String
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | value | string | value for convert | | separator | string | separator beetween words |

Example

camelCaseToOtherCase('testTest', '_')
// => test_test

toKebabCase(value) ⇒ string

convert string in camelCase to kebab-case

Kind: global function
Returns: string - return value in kebab-case
Category: String
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | value | string | value for convert |

Example

toKebabCase('testTest')
// => test-test

toSnakeCase(value) ⇒ string

convert string in camelCase to kebab-case

Kind: global function
Returns: string - return value in kebab-case
Category: String
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | value | string | value for convert |

Example

toSnakeCase('testTest')
// => test_test

toPascalCase(value) ⇒ string

convert string in camelCase to PascalCase

Kind: global function
Returns: string - return value in PascalCase
Category: String
Since: 1.1.0

| Param | Type | Description | | --- | --- | --- | | value | string | value for convert |

Example

toPascalCase('testTest')
// => TestTest

uuid() ⇒ string

generate a uuid

Kind: global function
Returns: string - return a uuid
Category: String
Since: 1.2.0
Example

uuid()
// => '557abf46-ecf7-4464-a37b-c8cc54bcffb2'