sbdt
v1.0.1
Published
This is a Node.js module available through the npm registry. Before installing, it´s necesary to install Node.js to install use the npm install command: ``` $ npm install sbdt ``` ## Functions ### There are many functions that you can use with this
Downloads
148
Readme
Simple Basics Development Tools
sbdt it´s a very simple module with some very useful functions.
Installation
This is a Node.js module available through the npm registry. Before installing, it´s necesary to install Node.js to install use the npm install command:
$ npm install sbdt
Functions
There are many functions that you can use with this module.
- arrayToCSV
- castToBoolean
- combineObjects
- csvToArray
- isArray
- isEmptyArray
- isEmptyObject
- isFunction
- isNotArray
- isNotEmptyArray
- isNotEmptyObject
- isNotFunction
- isNotNull
- isNotObject
- isNotPromise
- isNull
- isObject
- isPromise
- safeExtract
- safeIsNotNull
- safeIsNull
- isBigInt
- isBoolean
- isDate
- isNotBigInt
- isNotBoolean
- isNotDate
- isNotNumber
- isNotString
- isNotSymbol
- isNumber
- isString
- isSymbol
- toArray
- toBoolean
- toDate
- toLowerCase
- toNumber
- toString
- toTimestamp
- toTitleCase
- toUpperCase
- getRandomString
- getRandomNumberString
- isUndefined
- isNotUndefined
Arrat To CSV
arrayToCSV()
Receives an array of either numbers or texts and returns a csv text
arrayToCSV([1,2,3,4]); // 1, 2, 3, 4
arrayToCSV(['Hello', 'World']); // Hello, World
Cast To Boolean
castToBoolean()
cast a variable to boolean
castToBoolean("true"); // true
castToBoolean("1"); // true
castToBoolean(1); // true
castToBoolean("false"); // false
castToBoolean("0"); // false
castToBoolean(0); // false
castToBoolean({}); // false
castToBoolean(undefined); // false
Combine Objects
combineObjects()
Receives a list or lists of objects and combines them
combineObjects([{a:1,b:2,c:3},{d:4,e:5,f:6}]); // { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }
combineObjects([{a:11,b:12,c:13},{c:14,d:15,e:16}]); // { a: 11, b: 12, c: 14, d: 15, e: 16 }
CSV To Array
csvToArray()
It convert a csv to an array
csvToArray('1,2,3,4'); // [ '1', '2', '3', '4' ]
csvToArray('Hello,World'); // [ 'Hello', 'World' ]
csvToArray('CSV,|ARRAY','|') // [ 'CSV,', 'ARRAY' ]
Is Array
isArray()
Evaluate if a value is an array
isArray([1,2,3,4]); // true
isArray([]); // true
isArray({}); // false
isArray(1); // false
Is Empty Array
isEmptyArray()
It validate if a variable is an empty array
isEmptyArray([]); // true
isEmptyArray([1,2,3]); // false
Is Empty Object
isEmptyObject()
it Verify if a variable is an empty object
isEmptyObject({}); // true
isEmptyObject({a:1}); // false
Is Function
isFunction()
It validate if a variable is a function
isFunction(()=>null); // true
isFunction(1); // false
Is Not Array
isNotArray()
Evaluate if a value is not an array
isNotArray([]); // false
isNotArray(1); // true
Is Not Empty Array
isNotEmptyArray()
It validate if a variable isn't an empty array
isNotEmptyArray([]); // false
isNotEmptyArray([1,2,3]); // true
Is Not Empty Object
isNotEmptyObject()
It Verify if a variable is not an empty object
isNotEmptyObject({}); // false
isNotEmptyObject({a:1}); // true
Is Not Function
isNotFunction()
It validate if a variable isn't a function
isNotFunction(()=>null); // false
isNotFunction(1); // true
Is Not Null
isNotNull()
Validates if a variable is not null or undefined
isNotNull(undefined); // false
isNotNull(null); // false
isNotNull(1); // true
Is Not Object
isNotObject()
It validate if a variable isn't an object
isNotObject({}); // true
isNotObject([]); // false
Is Not Promise
isNotPromise()
it validates if a variable is not a promise
isNotPromise(new Promise((resolve)=>resolve(1))); // false
isNotPromise([]); // true
Is Null
isNull()
Validates if a variable is null or undefined
isNull(undefined); // true
isNull(null); // true
isNull(1); // true
Is Object
isObject()
It validate if a variable is an object
isObject({}); // true
isObject([]); // false
Is Promise
isPromise()
It validates if a variable is a promise
isPromise(new Promise((resolve)=>resolve(1))); // true
isPromise([]); // false
Safe Extract
safeExtract()
It extract at attribute from a variable if it exists in some "level", it´s a great way to extract if a key exists without throw errors
const extractor = {a:{parameter: 1}};
safeExtract(extractor, ['a']); // { parameter: 1 }
safeExtract(extractor, ['b']); // undefined
safeExtract(extractor, ['a', 'parameter']); // 1
safeExtract(extractor, ['b', 'parameter']); // undefined
Safe Is Not Null
safeIsNotNull()
It validate if a variable (object) contains an attribute, it can be in differents "levels"
const extractor = {a:{parameter: 1}};
safeIsNotNull(extractor, ['a']); // true
safeIsNotNull(extractor, ['b']); // false
safeIsNotNull(extractor, ['a', 'parameter']); // true
safeIsNotNull(extractor, ['b', 'parameter']); // false
Safe Is Null
safeIsNull()
It validate if a variable (object) not contains an attribute, it can be in differents "levels"
const extractor = {a:{parameter: 1}};
safeIsNull(extractor, ['a']); // false
safeIsNull(extractor, ['b']); // true
safeExtract(extractor, ['a', 'parameter']); // false
safeExtract(extractor, ['b', 'parameter']); // true
Is Big Int
isBigInt()
It let you know if a variable is a BigInt
isBigInt(1n); // true
isBigInt(1); // false
Is Boolean
isBoolean()
It help you to know if a variable is a boolean
isBoolean(true); // true
isBoolean(1); // false
isBoolean(false); // true
isBoolean(0); // false
Is Date
isDate()
It help you to know if a variable is a Date ( Date class ).
isDate(new Date()); // true
isDate(1); // false
Is Not Big Int
isNotBigInt()
It let you know if a variable is not a BigInt.
isBigInt(1n); // false
isBigInt(1); // true
Is Not Boolean
isNotBoolean()
It help you to know if a variable isn't a boolean.
isBoolean(true); // false
isBoolean(1); // true
isBoolean(false); // false
isBoolean(0); // true
Is Not Date
isNotDate()
It help you to know if a variable isn't a Date ( Date class )
isDate(new Date()); // false
isDate(1); // true
Is Not Number
isNotNumber()
Help you to know if a variable isn't a number
isNotNumber(1); // false
isNotNumber('a'); // true
Is Not String
isNotString()
It help you to know if a variable isn't a String
isNotNumber(1); // true
isNotNumber('a'); // false
Is Not Symbol
isNotSymbol()
Help you to know if a variable isn't a symbol
isNotSymbol(Symbol('id')); // false
isNotSymbol('id'); // true
Is Number
isNumber()
Help you to know if a variable is a number
isNumber(1); // true
isNumber('1'); // false
Is String
isString()
It help you to know if a variable is a String
isString(1); // false
isString('1'); // true
Is Symbol
isSymbol()
Help you to know if a variable is a symbol
isSymbol(Symbol('id')); // false
isSymbol('id'); // true
To Array
toArray()
Help you to get a array from any type of variable if the variable is an array already it will return the same array
toArray(1); // [ 1 ]
toArray('1'); // [ '1' ]
toArray(['1', '2']); // [ '1', '2' ]
toArray({a:1}); // [ { a: 1 } ]
toArray(undefined); // []
To Boolean
toBoolean()
It cast a variable to boolean
toBoolean("true"); // true
toBoolean("1"); // true
toBoolean(1); // true
toBoolean("false"); // false
toBoolean("0"); // false
toBoolean(0); // false
toBoolean({}); // false
toBoolean(undefined); // false
To Date
toDate()
Help you to get a Date variable form a string variable
toDate('07-30-2000'); // 964933200000
To Low Case
toLowerCase()
Help you to convert a string or variable to a lower case string
toLowerCase('Hello World'); // hello world
toLowerCase('HELLO WORLD'); // hello world
To Number
toNumber()
Help you to cast a variable to a Number
toNumber('1231'); // 1231
toNumber('32.12'); // 32.12
toNumber(1n); // 1
toNumber(4); // 4
To String
toString()
Cast an any variable to a String
toString('Hello World'); // "Hello World"
toString(321); // "321"
toString({a:1}); // "{\"a\":1}"
toString([1,2,3]); // "[1,2,3]"
To Timestamp
toTimestamp()
Help you to cast a variable to a Timestamp number, it can be Date or String
toTimestamp(new Date()); // 1684000479.627
toTimestamp('01-01-2020'); // 1577858400
To Title Case
toTitleCase()
Help you to cast a variable or a String to a Title case
toTitleCase('hello world'); // Hello World
toTitleCase('HELLO WORLD'); // Hello World
To Upper Case
toUpperCase()
Help you to cast a variable to a String
toUpperCase('hello world'); // HELLO WORLD
toUpperCase('Hello World'); // HELLO WORLD
Get Random String
getRandomString()
Help you to get a random string with numbers
getRandomString(4); // MJWh
getRandomString(10); // ehQNovk4cI
Get Random Number String
getRandomNumberString()
Help you to get a random string of numbers
getRandomString(4); // 4761
getRandomString(10); // 8960631952
Is Undefined
isUndefined()
Validates if a variable is undefined
isUndefined(4); // false
isUndefined(null); // false
isUndefined(undefined); // true
Is Not Undefined
isNotUndefined()
Validates if a variable is not undefined
isNotUndefined(4); // true
isNotUndefined(null); // true
isNotUndefined(undefined); // false