Aleppo
Overview
Aleppo is utility functions written in JavaScript.
Usage
Validation - IS
- npm package
- isUn
- isNull
- isValid
- isObj
- isBool
- isNum
- isStr
- isFn
- isArr
- isZeroLength
- isStrEmpty
- isArrEmpty
Function execution - DOO
Time and date
Other
Getting Started
clone the repo:
git clone git@github.com:jimmy02020/aleppo.gitcd aleppo
Using npm:
$ npm install aleppo
Validation - IS
Boolean validation functions. IS-functions can deal with one argument or multiple arguments as it accepts the spread syntax.
$ npm i aleppo.is
isUn (...inputs)
Checks if undefined returns true, otherwise returns false.
Examples
const isUn = // true // false // false. one of parameters failed to pass.
isNull(...inputs)
Checks if null returns true otherwise returns false.
Examples
const isNull = // true // false, one of the parameters failed. // false
isValid(...inputs)
Checks if not being undefined or null returns true otherwise returns false.
Examples
const isValid = // true // false, one of the parameters failed. // false
isObj(...inputs)
Checks if object returns true otherwise returns false.
Examples
const isObj = // true // false
isBool(...inputs)
Checks if Boolean returns true otherwise returns false.
Examples
const isBool = // true // false
isNum(...inputs)
Checks if numbers returns true otherwise returns false.
Examples
const isNum = // false // true
isStr(...inputs)
Checks if string returns true otherwise returns false.
Examples
const isStr = // true // false
isFn(...inputs)
Checks if function returns true otherwise returns false.
Examples
const isFn = // true // false
isArr(...inputs)
Checks if arrays returns true otherwise returns false.
Examples
const isArr = // true // false
isZeroLength(...inputs)
Checks if strings zero length returns true otherwise returns false.
Examples
const isZeroLength = // true // false
isStrEmpty(...inputs)
Checks if strings are empty returns true otherwise returns false.
Examples
const isStrEmpty = // true // false
isArrEmpty(...inputs)
Checks if arrays are empty returns true otherwise returns false.
Examples
const isArrEmpty = // true // false
Function execution - DOO
Executes multiple arguments with multiple functions in one call. Returns the results in required form. It passes each argument to all functions, after it's done with the first argument, it moves to process the second argument, so on so forth.
$ npm i aleppo.doo
doo.iterator([...funcs], [...args])
Returns iterator object of results.
Example : doo.iterator
const doo = // suppose we have two functions { return `hello ` } { return `goodbye !` } const result = doo// pass the first argument to the first function.resultnext // { value: 'hello Jimmy', done: false } // pass the first argument to the second function.resultnext // { value: 'goodbye Jimmy!', done: false } // done with first argument, pass the second one to the first function.resultnext // { value: 'hello Catherine', done: false } // pass the second argument to the first function.resultnext // { value: 'goodbye Catherine!', done: false } // done will be true when finishingresultnext // { value: undefined, done: true }
doo.array([...funcs], [...args])
Returns array of results.
Example
// continue working with same functions aboveconst result = dooconsole;// will print 'hello Jimmy' 'goodbye Jimmy!' 'hello Catherine' 'goodbye Catherine!'
doo.object([...funcs], [...args])
Returns array of objects [{func: 'Function name', result: 'result of the function'}]
Example
// continue working with same functions aboveconst result = dooobjectgreetings bye 'Jimmy' 'Catherine'console;// will print func: 'greetings' result: 'hello Jimmy' func: 'bye' result: 'goodbye Jimmy!' func: 'greetings' result: 'hello Catherine' func: 'bye' result: 'goodbye Catherine!'
Time and date
A set of functions to deal and manipulate with time and date.
Delay
Calculates delay time according to given option then returns it in milliseconds.
$ npm i aleppo.delay
const delay =
Types of options formats are:
year/years/yrs/y/yy/yyy/yyyy
: delay by years.d/dd/day/days
: delay by days.h//hr/hrs/hour/hours
: delay by hours.w/week/weeks
: delay by weeks.mo/mos/month/months/mth/mths
: delay by months.m/min/mins/minute/minutes
: delay by minutes.s/sec/secs/second/seconds
: delay by seconds.ms/mili/milisec/milisecs/milisecond/miliseconds
: delay by milliseconds.
Example
const delay = // 3600000.;// will print hello form the other side after ten minutes from now.
Date:
Deals with time and date, in readable form. It has nine major helper functions to compute time and date.
$ npm i aleppo.date
date.now([, options])
Returns current date or time format according to required option.
options
is String. Here all valid options.- Default value is current local time.
- Date format can use one of the following separators.
now
throws an error when options is not String or valid.
Example
const date = // default is local time.date // 6/17/2017, 3:00:03 PM date// return current timestamp 1495989532977. date // 18:Sunday:5:21/** hr --> current hour* hr --> current day* hr --> current month* hr --> current week* : --> separator*/ date // 2017:Sunday:21:May:52// same as above but more complex request and different separator. date // 2017date // 17date // 6date // Jundate // Junedate // 23
date.later(Xoptions[, ts|fullDate])
Returns later date or time according to required option. Later
computes the difference of time accurately, taking into consideration year type and days count in each month.
Xoptions
is String. Combined of number of times with valid options. X is 1 by default.ts
If you want to return value in timestamp, pass 'ts'.fullDate
If you want to return full date object, contains { yr, mo, dy, hr, min, sec}- Complex date format is not allowed.
later
throws an error when options is missing, not String or invalid.
Example
const date = /** Today is Sunday, June 18, 2017*/ date // Wednesdaydate // 3date // Wed date // 26date // 1499015984347date // { yr: 2017, mo: 7, dy: 2, hr: 19, min: 20, sec: 0 } date // 6date // Jundate // June
date.ago(Xoptions[, ts|fullDate])
Returns any required format for time or date happened ago from now. ago
computes the difference of time accurately, taking into consideration year type and days count in each month.
Xoptions
is String. Combined of number of times with valid options. X is 1 by default.ts
If you want to return value in timestamp, pass 'ts'.fullDate
If you want to return full date object, contains { yr, mo, dy, hr, min, sec}- Complex date format is not allowed.
ago
throws an error when options is missing, not String or invalid.
Example
const date = /** let's try time here since we tried date above.* Today, time is 7: 30 PM*/ date // 18date // 18date // 6: 30 pmdate // 5:30 pmdate // 1497803572706
date.readTs(timestamp)
Returns readable timestamp object. Contains yr, mo, dy, hr, min, sec.
timestamp
can be Number or String.readTs
throws an error when timestamp is missing or invalid.
Example
const date = date// returns yr: 2017 mo: 5 dy: 23 hr: 19 min: 15 sec: 45
date.isLeap([, year])
Returns Boolean. True if the year is leap. False for otherwise.
- Default value is current year.
isLeap
throws an error when year is not valid number or valid value.
Example
const date = date // falsedate // true // default is the current year 2017.date // false
date.isCommon([, year])
Returns Boolean. True if the year is common. False for otherwise.
- Default value is current year.
isCommon
throws an error when year is not valid number or valid value.
Example
const date = date // falsedate // true // default is the current year 2017.date // true
date.yearType([, year])
Returns String of year type common or leap.
year
is Number- Default value is current year.
yearType
throws an error when year is not valid number or valid value.
Example
const date = const date = gettersdate date // leap date // common date // leap // default is the current year 2017.date // common
date.daysCountInMonth([, monthNum] [, year])
Returns number of days in required month. Taking into consideration whether the year is common, or leap to return the right number of days for February.
monthNum
andyear
are Numbers- Default value for
monthNum
is current month number,year
is current year. daysCountInMonth
throws an error if:- Month number is not correct.
- One of the input date is not valid number.
Example
const date = // February in common yeardate // 28 // February in leap yeardate // 29 // regular month numberdate // 31 // default, returns the current month(June) days for the current year(2017).date // 30
date.countBtw(type[, [, from|timestamp] [, to|timestamp ]] [-i])
date.countBtw(type)
date.countBtw(type, to)
date.countBtw(type, from, to, i)
Computes the difference between two dates and returns objects of results.
type
is type of request, all/year/month/week/day. All relevant options are valid.from
String or Number.- Default value is 1/1/currentYear.
- String for date format request should be "dd/mm/yyyy".
- Number will be explained according to request type.
- If your request type is
year
number will be converted to 1/1/year. month
to 1/month/currentYear.day
to day/1/currentYear.
to
String or Number. Same asfrom
with major difference.to
converts number to current date instead of beginning of the year.- Default value is currentDay/currentMonth/currentYear.
- If your request type is
year
number will be converted to: currentDay/currentMonth/year. months
to currentDay/month/currentYear.day
to day/currentMonth/currentYear.
i
A flag constiable, false by default. If you want to include the last day in the result, pass 'i' to include it.- returns object of request type and remainder of calculations if there is any.
Note:
- Both
from
andto
accepts timestamp as numbers. - One date argument is considered as
to
. - Date format can use one of the following separators.
countBtw
throws an error if:- No type is provided.
- One of the input date is not valid.
- Type of request is not valid or missing.
Example
const date = date// returns: years: 0 months: 5 days: 15 /* * since there is no from and to. * from will be: 1/1/2017 * to will be now: 16/6/2017 (current date) * returns object of all forms since no specific type was entered. */ date// returns: years: 0 months: 5 days: 15 /* same result as above.* one date argument is to.* number with year it means year number.* year number will be converted tp date form including now parameters.* 2017--> 16/6/2017 (current month and day date)* from of course 1/1/2017*/ date// returns years: 33 months: 5 days: 16 /* from : 2017--> 1/1/2017* to : 2015--> 16/6/2050 (current month and day date)* i: include last day 16/6/2050*/ date// returns years: 79 months: 4 days: 12 // let's pass timestamp for "Thu, 01 Jun 2017 17:21:31 GMT"// which it's 1496337691025 date // returns years: 27 months: 5 days: 0 date// returns: months: 5 days: 15 /** default:* from --> 1/1/2017* to --> 16/6/2017 (current year and day date)*/ date// returns: months: 9 days: 15 /** default from is 1/1/2017* converted to is 16/10/2017 (current year and day date)*/ date// returns: months: 2 days: 16 /** default from is 1/10/2017* converted to is 16/12/2017 (current year and day date)* plus one day because of i - include last day*/ date// returns: months: 952 days: 12 date// returns days: 166 /** default:* from --> 1/1/2017* to --> 16/6/2017 (current year and day date)*/ date// returns days: 174 /** default from is 1/1/2017* converted to is 10/6/2017 (current month and day date)*/ date// returns: days: 28987 date// returns: weeks: 52 days: 1 date// returns object difference: inDays: 7930 inWeeks: weeks: 1132 days: 6 inMonths: months: 260 days: 17 inYears: years: 21 months: 8 days: 17
Available options format:
year/years/yrs/yyyy
: full year/ four digits.y/yy/yyy
: two digits year.mo/mon/mos/mons
: month number.mth/mths
: month short name.month/months
: month full name.w/wk/week/weeks
: week number.d
: day number in the week.dd
: day short name.day/days
: day full name.h/hr/hrs/hour/hours/h24/hr24/hrs24/hour24/hours24
: 24-hour form.h12/hr12/hrs12/hour12/hours12
: 12-hour form.m/min/mins/minute/minutes
: minutes.s/sec/secs/second/seconds
: seconds.ms/mili/milisec/milisecs/milisecond/miliseconds
: milliseconds.ts/timestamp
: timestamp. (available only for now function)local
: local date and time. (available only for now function)local date/localDate
: local date.(available only for now function)local time/localTime
: local time. (available only for now function)utc
: UTC time. (available only for now function)
Types of valid separators are:
-
or/
or.
or:
or,
or<space>
Tests
$ npm test
License
This project is licensed under the MIT License