1.2.0 • Published 2 years ago

js-tools-base v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

js-tools-base

NPM Version A lightweight javascript tool library for various needs.

Version 1.1.0

There are only 8 js tools such as 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

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

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago