Readme
Some non standard JavaScript features.
from Node.js > 0.12.0
Usage
; // Install all features // install specified function;1 2 3; // true // Install some module;;;;;
Contents
- console.pipe
- console.[log, info, warn, error].pipe
- Array.empty
- Array.present
- Array.prototype.first
- Array.prototype.second
- Array.prototype.last
- Array.prototype.clean
- Array.prototype.contains
- Array.prototype.clone
- Object.clone
- Object.empty
- Object.present
- Number.range
- Number.prototype.times
- String.random
console.pipe
Log value to console and pass value First value was passed next.
console.pipereturnValue: any, logValue1: any, logValue2: any, logValueN: any : any;
Install:
;
// write `123` to console with `console.log`var a = console; // write:// hello world// hello//console;
console.[log, info, warn, error].pipe
console.log.pipevalue: any, ...values: any : any;console.info.pipevalue: any, ...values: any : any;console.warn.pipevalue: any, ...values: any : any;console.error.pipevalue: any, ...values: any : any;
Install:
;
; // value was shown in console, and passed to function `executeFunction` { return ;}
Array.empty
Check if array has not elements
Array.emptytarget: array : boolean;
Install:
;
Array // trueArray // false
Array.present
Check if array has some elements
Array.presenttarget: array : boolean;
Install:
;
Array // falseArray // true
Array.prototype.first
First element in array
.first
Install:
;
var arr = 5 9 14; arrfirst // 5 arrfirst = 2; arr // [2, 9, 14]
Array.prototype.second
Second element in array
.second
Install:
;
var arr = 1 8 10; arrsecond // 8 second // undefined second = 2 // equals: [][1] = 2
Array.prototype.last
Latest element in array
.last
Install:
;
var arr = 12 34 56 78 90; arrlast // 90 arrlast == arrarrlength - 1 // true last = 1; // nothing changed
Array.prototype.clean
Clear array
.clean
Install:
;
var arr = 1 2 3 45 67; arr; arr // now `[]`
If as argument function passed, .clean
call it on every value and clean if callback return not false, 0, null or undefined
var arr = 1 2 3 4 5 6;arr;arr; // [2, 4, 6]
Array.prototype.contains
Check elements exists in array
.containsany : boolean
Install:
;
var arr = "a" "b" "c"; arr; // true arr; // true arr; // false
Array.prototype.clone
Full clone array.
.clone : any
Install:
;
var arr = 1 5; // its simplearr // [1, 5]
Object.clone
Deep clone object
Object.clonetarget: object : object;
Install:
;
var oob = name: "Foo" test: "bar" cool: yeah: true ; var wob = Object;// Object `wob` is full copy of `oob` without links in memory
Object.empty
Check if object has not keys
Object.emptytarget: object : boolean;
Install:
;
Object // trueObject // falseObject // false
Object.present
Check if object has keys
Object.presenttarget: object : boolean;
Install:
;
Object // falseObject // trueObject // true
Number.range
Create array of numbers
Number.rangemin: number, max: number, step: number = 1 : number;
Install:
;
console/* [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]*/ console/* [2, 4, 6, 8]*/
Number.prototype.times
Run callback n times
5.times : any
Install:
;
var result = 5;result // [ 2, 4, 6, 8, 10 ]
String.random
Generate random string with custom length
String.randomlength: string = 10 : string;
Install:
;
String // "778fx0hmc0"String // "u5ojh"String // "ww5z8kar8m6l4ichouw221n307xiec1wt6584qf4bib2rbsa4b379hoblsd42h3e"