1.0.14 • Published 6 years ago
@webther/util v1.0.14
Util JavaScript Functions
List of functions
Validator
- isBlank()
- isBoolean()
- usEmail()
- isJson()
Array
- getEleByKeys()
String
- toLowerCase()
- toUpperCase()
- toCamelCase()
- toPascalCase()
- toSlugCase()
Setup the node module
Install the node module to your project.
$ cd PATH_TO_YOUR_PROJECT
$ npm i @webther/util
Load the '@webther/util' module.
var util = require("@webther/util");
or
import util from '@webther/util';
Validator functions usage
- isBlank()
util.isBlank(); // true
util.isBlank(''); // true
util.isBlank(null); // true
util.isBlank(undefined); // true
util.isBlank([]); // true
util.isBlank({}); // true
util.isBlank('0'); // false
util.isBlank('1'); // false
util.isBlank(0); // false
util.isBlank(1); // false
util.isBlank(true); // false
util.isBlank(false); // false
util.isBlank([1, 2, 3]); // false
util.isBlank({name: 'Jay'}); // false
util.isBlank(function() {}); // false
- isBoolean()
util.isBoolean(); // false
util.isBoolean(''); // false
util.isBoolean(null); // false
util.isBoolean(undefined); // false
util.isBoolean(true); // true
util.isBoolean(false); // true
util.isBoolean('true', true); // true
util.isBoolean('false', true); // true
util.isBoolean('true', false); // false
util.isBoolean('false', false); // false
util.isBoolean(1); // false
util.isBoolean(0); // false
- isEmail()
util.isEmail(); // false
util.isEmail(''); // false
util.isEmail(null); // false
util.isEmail(undefined); // false
util.isEmail('@gmail.com'); // false
util.isEmail('abc@gmail'); // false
util.isEmail('abc..abc@gmail.com'); // false
util.isEmail('.abc@gmail.com'); // false
util.isEmail('abc.@gmail.com'); // false
util.isEmail('abc@gmail.com'); // true
- isJson()
util.isJson(); // false
util.isJson(''); // false
util.isJson(null); // false
util.isJson(undefined); // false
util.isJson('[ [ "name": "Jay" ] ]'); // false
util.isJson('{ { "name": "Jay" } }'); // false
util.isJson('""'); // true
util.isJson('[]'); // true
util.isJson('{}'); // true
util.isJson('[{"name": "Jay"}]'); // true
util.isJson('{"name": "Jay"}'); // true
Array functions usage
- getEleByKeys()
var person = {
name: 'Jay',
gender: 'Male',
skills: [
'JavaScript',
'Angular',
'Vuejs'
],
ssn: '111-11-1111'
};
util.getEleByKeys(person, 'name'); // Jay
util.getEleByKeys(person, 'gender'); // Male
util.getEleByKeys(person, 'skills'); // ['JavaScript', 'Angular', 'Vuejs']
util.getEleByKeys(person, 'skills|0'); // JavaScript
util.getEleByKeys(person, 'age'); // ''
util.getEleByKeys(person, 'skills|10'); // ''
var people = [{
name: 'Jay',
gender: 'Male'
}];
for (var i = 0; i < people.length; i++) {
util.getEleByKeys(people[i], 'name'); // Jay
util.getEleByKeys(people[i], 'gender'); // Male
}
util.getEleByKeys(people, '0|name'); // Jay
util.getEleByKeys(people, '0|gender'); // Male
String functions usage
- toLowerCase()
util.toLowerCase('Hello World'); // hello world
util.toLowerCase('123'); // 123
util.toLowerCase(123); // 123
util.toLowerCase(0.25); // 0.25
- toUpperCase()
util.toUpperCase('Hello World'); // HELLO WORLD
util.toUpperCase('123'); // 123
util.toUpperCase(123); // 123
util.toUpperCase(0.25); // 0.25
- toCamelCase()
util.toCamelCase(''); // ''
util.toCamelCase(null); // ''
util.toCamelCase(undefined); // ''
util.toCamelCase(123); // 123
util.toCamelCase('123 45 6789'); // 123456789
util.toCamelCase('123 abc 6789'); // 123Abc6789
util.toCamelCase('123 45 abc'); // 12345Abc
util.toCamelCase('a'); // a
util.toCamelCase('HELLOWORLD'); // helloworld
util.toCamelCase('HELLOWorld'); // helloWorld
util.toCamelCase('HelloWorld'); // helloWorld
util.toCamelCase('helloWORLD'); // helloWorld
util.toCamelCase('Hello World'); // helloWorld
util.toCamelCase('--Hello--World--'); // helloWorld
util.toCamelCase('__Hello__World__'); // helloWorld
- toPascalCase()
util.toPascalCase(); // ''
util.toPascalCase(''); // ''
util.toPascalCase(null); // ''
util.toPascalCase(undefined); // ''
util.toPascalCase(123); // 123
util.toPascalCase('123 45 6789'); // 123456789
util.toPascalCase('123 abc 6789'); // 123Abc6789
util.toPascalCase('123 45 abc'); // 12345Abc
util.toPascalCase('a'); // A
util.toPascalCase('HELLOWORLD'); // Helloworld
util.toPascalCase('HELLOWorld'); // HelloWorld
util.toPascalCase('HelloWorld'); // HelloWorld
util.toPascalCase('helloWORLD'); // HelloWorld
util.toPascalCase('Hello World'); // HelloWorld
util.toPascalCase('--Hello--World--'); // HelloWorld
util.toPascalCase('__Hello__World__'); // HelloWorld
- toSlugCase()
util.toSlugCase('123 45 6789'); // 123456789
util.toSlugCase('Hello World'); // hello-world
util.toSlugCase('--hello--world--'); // hello-world
util.toSlugCase('..hello..world..'); // hello-world
util.toSlugCase(' hello world '); // hello-world
util.toSlugCase('helloWorld'); // hello-world
util.toSlugCase('HelloWorld'); // hello-world