0.0.12-beta.3 • Published 11 months ago

@nerv_uk/unilib v0.0.12-beta.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

GitHub License NPM Version

@nerv_uk/unilib

Installation

npm install @nervuk/unilib

Usage

const { isString } = require "@nerv_uk/unilib/dist/strings";
import { isString } from '@nerv_uk/unilib/dist/strings';

Modules

  • dates
  • numbers
  • strings
  • arrays
  • crypt
  • universal

Documentation

Dates

dayDiff(Date, Date) - get the number of days between the dates

dayInYear(Date) - get the number of this day in the year

Numbers

average(...numbers) - calculate average

randomNumber = (min: number, max:number): number - generates a random number between the specified min and max values, inclusive

Strings

generateRandomString(length: number) - generate a random string

isString(value: any) - check if the value is a string

isEmptyString(value: any) - check if the value is empty string; throw Error if value is not a string

Arrays

isStringArray(arr: unknown[]): arr is string[] - check if an array is a string array

isNumberArray(arr: unknown[]): arr is number[] - check if an array is a number array

getRandomIndex <T>(arr: T[]): number - return the random index of the array

numberToArray(num: number): number[] - convert a single number into an array of its digits

arrayOfNumbersToNumber(arr: number[]): number - concatenate a number array into a single number

Crypt

getSaltAndHash(password, saltSize?: 16, options?: {}) - return an object with a hash and salt

options:

{
  algorithm?: THashAlgorithm,
  iterations?: number, 
  keyLen?: number, 
  saltSize?: number,
}

algorithm:

  • 'sha1'
  • 'sha224'
  • 'sha256'
  • 'sha384'
  • ...

Result:

{
  salt: '87678e...',
  hash: '29a12437606a2badd1...'
}

isHashBelongPassword(password, salt, testHash, options) - test if password's jash and testHash are equal

Universal

uniqueArray([]: any) - get an array of unique elements

License

Copyright © 2024 Volodymyr Nerovnia; Released under the MIT license.

0.0.12-beta.3

11 months ago

0.0.12-beta.2

11 months ago

0.0.12-beta.1

11 months ago

0.0.11

11 months ago

0.0.11-betta.6

11 months ago

0.0.11-betta.5

11 months ago

0.0.11-betta.2

11 months ago

0.0.11-betta.1

11 months ago

0.0.10

12 months ago

0.0.9-beta.2

12 months ago

0.0.9-beta.1

12 months ago

0.0.8

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago