dev-utilz
v0.0.7
Published
Module intended to be used by developers to help with development
Downloads
8
Readme
dev-utilz
Utility functions to speedup development
Table of contents
Number #TODO
Install
Install with npm:
$ npm install --save dev-utilz
String utilities
This library will support following string utility functions
isString
Check whether the given value is string or not. if valid string return tru else false.
usage
import { isString } from "dev-utilz";
console.log(isString("string")); // true
console.log(isString(1)); // false
isNotEmpty
Check whether the string is empty or not.
- If empty return false else not.
- If it's string, check whether it's empty or not else return false
- If doTrim is true, trim the string before check. default value is false.
import { isNotEmpty } from "dev-utilz";
console.log(isNotEmpty("string")); // true
console.log(isNotEmpty(1)); // false
console.log(isNotEmpty("")); // false
console.log(isNotEmpty(" ")); // true
console.log(isNotEmpty(" ", true)); // false
returnValidString
If value is string return value else return empty string.
import { returnValidString } from "dev-utilz";
console.log(returnValidString("string")); // "string"
console.log(returnValidString(1)); // ""
capitalize
Capitalize the string
import { capitalize } from "dev-utilz";
console.log(capitalize("string")); // String
console.log(capitalize("test String")); // Test string
capitalizeAll
Capitalize each word in string
import { capitalizeAll } from "dev-utilz";
console.log(capitalizeAll("string")); // String
console.log(capitalizeAll("test string")); // Test String
throwErrorIfNotString
Throw error if value is not a string else return string
import { throwErrorIfNotString } from "dev-utilz";
console.log(throwErrorIfNotString("string")); // string
console.log(throwErrorIfNotString("")); // ""
console.log(throwErrorIfNotString(1)); // throw error
toLowerCase
Convert entire string to lowercase
import { toLowerCase } from "dev-utilz";
console.log(toLowerCase("string")); // string
console.log(toLowerCase("TEST String")); // test string
toUpperCase
Convert entire string to uppercase
import { toUpperCase } from "dev-utilz";
console.log(toUpperCase("string")); // STRING
console.log(toUpperCase("TEST String")); // TEST STRING
getFirstLetters
Function to get the first n letters of a string
import { getFirstLetters } from "dev-utilz";
console.log(getFirstLetters("string", 2)); // st
getSubString
Function to get substring from given string
import { getSubString } from "dev-utilz";
console.log(getSubString("John", 1, 3)); // oh
getLastLetters
Function to get the last n letters of a string
import { getLastLetters } from "dev-utilz";
console.log(getLastLetters("string", 2)); // ng
startWith
Check whether the string is start with given string
import { startWith } from "dev-utilz";
console.log(startWith("string", "str")); // true
console.log(startWith("TEST String", "John")); // false
endWith
Check whether the string is end with given string
import { endWith } from "dev-utilz";
console.log(endWith("string", "ing")); // true
console.log(endWith("TEST String", "John")); // false
times
Function to repeat string n times and return array
import { times } from "dev-utilz";
console.log(times("string", 2)); // ["string","string"]
padStart
Pads string on the left side if it's shorter than length. Padding characters are truncated if they exceed length.
import { padStart } from "dev-utilz";
console.log(padStart("abc", 6)); // ' abc'
console.log(padStart("abc", 6, "_")); // '___abc'
padEnd
Pads string on the right side if it's shorter than length. Padding characters are truncated if they exceed length.
import { padEnd } from "dev-utilz";
console.log(padEnd("abc", 6)); // 'abc '
console.log(padEnd("abc", 6, "_")); // 'abc___'
stringSize
Gets the number of symbols in string
.
import { stringSize } from "dev-utilz";
console.log(stringSize("qwerty")) // 6