0.0.7 • Published 8 months ago

@erbelion/utils v0.0.7

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

javascript utils

No longer maintained Get package from npm Downloads views likes

A collection of simple javascript utility functions for use in browser and node.js apps.

If you have any ideas what functions to add, feel free to open an issue.

Warning: This package is in experimental state, updates may be critical.

Installation

yarn

yarn add @erbelion/utils

npm

npm i @erbelion/utils

Functions

Time

Numbers

URLs

Time

sleep(ms)

source

import { sleep } from '@erbelion/utils'

await sleep(5000)
// 5 seconds have elapsed

Numbers

compactNumber(number)

source

import { compactNumber } from '@erbelion/utils'

compactNumber(1555) // 1.6K
compactNumber(1555555) // 1.6M
compactNumber(1555555555) // 1.6B
compactNumber(1555555555555) // 1.6T

random() || random(max) || random(min, max)

import { random } from '@erbelion/utils'

random() // 0 or 1
random(69) // random from 0 to 69
random(69, 420) // random from 69 to 420

URLs

isUrl(url) || isUrl(url, strict)

source1 source2

import { isUrl } from '@erbelion/utils'

isUrl('https://github.com/erbelion/utils') // true
isUrl('bruh://man.com') // false
isUrl('broher') // false

isUrl('github.com/erbelion/utils') // true
isUrl('github.com/erbelion/utils', true) // false

urlParams(url)

source

import { urlParams } from '@erbelion/utils'

urlParams('https://github.com/erbelion/utils?a=1&b=2') // { a: 1, b: 2 }
urlParams('') // {}

// if no arg is given, then browser url is taken (window.location.href)
urlParams() // {}

updateUrlParams(newParams) || updateUrlParams(newParams, url) || updateUrlParams(newParams, oldParams)

check vue example here

import { updateUrlParams } from '@erbelion/utils'

updateUrlParams({ a: 1 }, 'https://github.com/erbelion/utils?b=2') // { a: 1, b: 2 }
updateUrlParams({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }

// if no second arg is given, then browser url (window.location.href) is updated without reload
updateUrlParams({ a: 1 }) // updates current window url to https://github.com/erbelion/utils?a=1

// remove url params
updateUrlParams({a: ''}, 'https://github.com/erbelion/utils?a=1') // {}
0.0.7

8 months ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago