1.2.2 • Published 2 years ago

@danielszuk/utilities v1.2.2

Weekly downloads
8
License
ISC
Repository
github
Last release
2 years ago

Utilities

npm package License: ISC Node.js CI David npm bundle size Coverage Status

Commonly used utilities for Typescript/Javascript projects.

Installation

npm install @danielszuk/utilities

Usage

Always import only the used functions from the package.

Typescript

import { degreeToRadian, randomBoolean, forEach } from '@danielszuk/utilities'

degreeToRadian(45);
// 0.785398

randomBoolean();
// true OR false

forEach([1,2,3], (number) => console.log(number));
// 1
// 2
// 3

Javascript

const { degreeToRadian, randomBoolean, forEach } = require('@danielszuk/random-boolean');

degreeToRadian(45);
// 0.785398

randomBoolean();
// true OR false

forEach([1,2,3], (number) => console.log(number));
// 1
// 2
// 3

List of available functions

For detailed description, check the definition of the imported function (either by your IDE, or from the source code).

For detailed examples, check the corresponding name.spec.ts file in the __tests__/ folder

NameShort DescriptionExample
forEachExecutes a provided function once for each array element (breakable)forEach([1,2,3], (element) => {if (element === 2) return false; }
forEachSyncExecutes a provided async function synchronously once for each array element (breakable)await forEachSync([1,2,3], async (element) => { await asyncFn(element); if (element === 2) return false; }
forEachAsyncExecutes a provided async function asynchronously once for each array element (awaitable)await forEachAsync([1,2,3], async (element) => { await asyncFn(element); }
cloneCreates a new object from the given one with the exact same values, but without the reference.const obj2 = clone(obj1)
deepAssignAssign an object's values into a target object, value by value deeply.deepAssign({ a: 1, b: { ba: 21, bb: 22 } }, { b: { ba: 42 } }) // { a: 1, b: { ba: 42, bb: 22 } }
getSafeExecutes a getter and returns with the value. If the execution runs on error, returns with undefined.getSafe(() => result.attribute.value)
isEmptyDetermines whether an object is empty or not.isEmpty({}) // true
isEquivalentDetermines whether two objects are equivalent (means all their properties values are the same).isEquivalent({ a: 1 }, { a: 1 }) // true
removeElementsRemoves elements from an array. Modify the original array.removeElements([ 1, 2, 3 ], 2, 3) // [ 1 ]
circulateArrayCirculates over the elements of an array.const next = circulateArray([12, 21, 39]); next(); next(); next(); next(); // 12 21 39 12
degreeToRadianConverts an angle in degree to radian.degreeToRadian(30) // 0.5235987755982988
htmlToTextRemoves all html markup from a string.htmlToText(`<b>Name</b>`) // 'Name'
randomBooleanGenerates a random boolean value.randomBoolean() // true OR false
roundRounds a number to a given decimal place.round(1.237, 2) // 1.24
timeoutDelay the execution for a specified number of milliseconds.await timeout(1000)
asStrict type checking a single value.as<IExample>({ a: 1, b: 2 })
DeepPartialMakes all attributes optional and all its nested object's attributes optional as well.const toModify: DeepPartial<IExample>
1.2.2

2 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.0

4 years ago