1.0.9 • Published 15 days ago

will-util v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
15 days ago

will-util

Utilities functional

Installation

npm install will-util

Arguments

Arguments handle for reading parameter value from command line arguments

import { Arguments } from "will-util";

let args = process.argv.slice(2);
//this will read from specified arguments with option -user if not defined return tester as default
let user = Arguments.getString(args,'tester','-user');
//this will read from specified arguments with option -p or -pwd if not defined return null as default
let pwd = Arguments.getString(args,null,'-p','-pwd');
//this will read from command line arguments directly
let count = Arguments.getInteger(null,0,'-count');

Iterator

Iterator handle for iterate array of object

import { Iterator } from "will-util";

let ary = ["hello","new","world"];
let it = new Iterator<string>(ary);
while(it.hasNext()) {
    console.log(it.next());
}

RandomUtility

Utility for randomize number or alphabets with min/max range

import { RandomUtility } from "will-util";

console.log(RandomUtility.getRandomNum(1,10));
console.log(RandomUtility.random(6)); 
console.log(RandomUtility.randomNumber(6));

StringTokenizer

StringTokenizer handle for token raw string with delimiters.

default delimiter is blank or space and new line with no return separator

import { StringTokenizer } from "will-util";

let str = "Hello new world";
let token = new StringTokenizer(str);
let result = token.tokenize();
console.log(result); 
//result is [ 'Hello', 'new', 'world' ]

specified with delimiter and return separator

import { StringTokenizer } from "will-util";

let str = "Hello ? world";
let token = new StringTokenizer(str,"?",true);
let result = token.tokenize();
console.log(result);
//result is [ 'Hello ', '?', ' world' ]

Utilities

The utilities functional

import { Utilities } from "will-util";

console.log(Utilities.compareString("AAA","BBB")); // result is -1
console.log(Utilities.compareString("AAA","AAA")); // result is 0
console.log(Utilities.compareString("BBB","AAA")); // result is 1
FunctionDescription
getWorkingDirTo get base directory if base name is src or dist.
getDateNowTo get date in format dd/MM/yyyy.
getTimeNowTo get time in format HH:mm:ss.
getDateTimeNowTo get datetime in format dd/MM/yyyy HH:mm:ss.
getYMDTo get date in format yyyy-MM-dd.
getDMYTo get date in format dd/MM/yyyy.
formatDateTo format Date to dd/MM/yyyy or yyyy-MM-dd.
formatTimeTo format time HH:mm:ss.
formatDateTimeTo format date into dd/MM/yyyy HH:mm:ss or yyyy-MM-dd HH:mm:ss.
getHMSTo format time HH:mm:ss.
currentDateTo format Date to yyyy-MM-dd.
currentTimeTo format time to HH:mm:ss.
currentDateTimeTo format Date to yyyy-MM-dd HH:mm:ss.
currentTimeMillisTo get current time in milli seconds.
addDaysTo add number of days into Date.
compareDateTo compare between date. (returns number, -1 = lesser than, 0 = equal , 1 = greater than)
compareTimeTo compare between time. (returns number, -1 = lesser than, 0 = equal , 1 = greater than)
compareDateTimeTo compare between datetime. (returns number, -1 = lesser than, 0 = equal , 1 = greater than)
compareStringTo compare string value. (returns number, -1 = lesser than, 0 = equal , 1 = greater than)
equalsIgnoreCaseTo check string equals with ignore case.
isStringTo check data is string or not.
hasAttributesTo check attributes is in object element.
parseIntegerTo parse integer (especially from string).
parseFloatTo parse float (especially from string).
parseBooleanTo parse boolean (especially from string).
parseDateTo parse Date with data value string in format dd/MM/yyyy, yyyy-MM-dd, dd/MM/yyyy HH:mmss, yyyy-MM-dd HH:mm:ss.
nowTo get current date/time.
translateVariablesTo replace all variables in markup ${variable-name}.

Configure

Configure class implements for reading config/default.json and environment variables

import { Configure } from "will-util";
import config from "will-util";

console.log(Configure.hasConfig("SECTION"));
console.log(Configure.getConfig("SECTION"));
console.log(Configure.getEnv("SECTION"));
console.log(Configure.getEnv("SECTION","TEST"));

console.log(config.has("SECTION"));
console.log(config.get("SECTION"));
console.log(config.env("SECTION"));
console.log(config.env("SECTION","TEST"));

getEnv and env will return environment variables when found or else return value from default.json and default value in order

1.0.9

15 days ago

1.0.8

23 days ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

9 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago