1.3.0 • Published 12 months ago

js-tools-base v1.3.0

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

js-tools-base

NPM Version A lightweight javascript tool library for various needs.

Version 1.2.0

List of tools: isObject, isEmptyOrOnlySpacesString, getTimeZone, doesObjectHaveEmptyProps, isSorted, shuffleArray, generateRandomIntList, randomInt.

Installation

$ npm install js-tools-base

Usage

const { ExampleTool } = require("js-tools-base");

List of tools

isObject(object)

Check is that object in argument of function or not.

console.log(isObject({ "id": 123, "message": "hello Iphone" })); //true
console.log(isObject('some string')); //false

isEmptyOrOnlySpacesString(string)

Checks is string empty or has only spaces.

console.log(isEmptyOrOnlySpacesString('Apple')); //false
console.log(isEmptyOrOnlySpacesString('')); //true
console.log(isEmptyOrOnlySpacesString('    ')); //true
console.log(isEmptyOrOnlySpacesString('Ap  p le')); //false

getTimeZone()

Gets the requester's time zone.

console.log(getTimeZone()); //europe/kiev

doesObjectHaveEmptyProperties(object)

checks does object have blank properties.

const obj = {
    name: "John",
    dataOfBirth: "",
    externalId: 2548,
    email: "john@email.com",
    mobile: ""
}

const data = {
    name: "Sal",
    dataOfBirth: "12.12.2012",
    externalId: 83838,
    email: "sal@email.com",
    mobile: "122344566"
}
console.log(doesObjectHaveEmptyProps(obj)); //dataOfBirth is empty, mobile is empty, other keys are filled
console.log(doesObjectHaveEmptyProps(data)); //other keys are filled

IsSorted(array)

Checks is sorted array in argument of function or not.

console.log(isSorted([1,3,4,9,13])); //true
console.log(isSorted([5, 7, 1, 67])); //false

shuffleArray(array)

Shuffles the values of an array, returning a new array.

let arr = [4, 6, 7, 9];
console.log(shuffleArray(arr)); //[7, 4, 9, 6]

generateRandomIntList(length, max)

Generates an array with random int values. First argument is the length of array, second is the max possible integer.

console.log(generateRandomIntList(8, 100)); //[ 41, 4, 52, 9, 82, 50, 19, 60 ]
console.log(generateRandomIntList(5, 5)); //[ 1, 0, 2, 0, 4 ]

randomInt(min, max)

Generates an integer between the minimum given value and the maximum given value.

console.log(randomInt(3, 576)); // 207
console.log(randomInt(50, 60)); // 58

capitalizeFirstLetter(string)

Capitalizes the first letter of a string.

console.log(capitalizeFirstLetter('hello')); // Hello
console.log(capitalizeFirstLetter('')); // ''

debounce(func, wait) Debounces a function to limit its execution rate.

const log = debounce(() => console.log('Debounced!'), 1000);
log();
log();
log(); // Only this call will log 'Debounced!' after 1 second

getQueryParams(url) Parses URL query parameters into an object.

console.log(getQueryParams('https://example.com?page=1&sort=asc')); // { page: '1', sort: 'asc' }

flattenArray(arr) Flattens a nested array.

console.log(flattenArray([1, [2, [3, [4]], 5]])); // [1, 2, 3, 4, 5]

Follow me and my email to cooperate

Twitter

delaklovp@gmail.com

at least if one of the tools you like, please star the repo. if you have free time feel free to contribute to this library

To do

add to do

1.3.0

12 months ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago