qp-utility v1.5.14
install
npm install qp-utility --save
<script src="qp-utility.min.js"></script><link href="qp-utility.min.css" rel="stylesheet">
build
cd qp-utility
node build
void noop()
no operation
string escape_re(string reg_exp)
reg_expregular expression string
escape special chars in a regular expression string
return escaped string
boolean is_number(object value)
valueto check
return true if value is a function
boolean is_function(object value)
valueto check
return true if value is a function
number random(number min, number max)
numberminimum valuenumbermaximum value
return a random number between minimum and maximum values
boolean is_empty(object value)
valueto check
return true if value is undefined, null or length === 0
boolean not_empty(object value)
valueto check
return inverse of is_empty
string trim(string value, string chars)
valuethe string to trimcharsthe characters to trim fromvalue
return remove characters from both sides of the string
string ltrim(string value, string chars)
valuethe string to trimcharstrim characters
return remove the trim characters from the left side of the string
string rtrim(string value, string chars)
valuethe string to trimcharstrim characters
return remove the trim characters from the right side of the string
string build(string | string[] value, ...)
valueany combination of strings, string arrays and arguments...furthervalues
flatten and compact values into a flat array and then joins them
return string
qp.build(
'<h1>',
'hello world',
'</h1>'
);
=> <h1>hello world</h1>string escape(string html)
htmlstring to escape
return escape special chars to html entities
string unescape(string html)
htmlstring to unescape
return unescape html entities to special chars
string lpad(string value, string pad, number len)
valuethe string to padpadpadding characterslenpad to length
return pad left side of value
string rpad(string value, string pad, number len)
valuethe string to padpadpadding characterslenpad to length
return pad right side of value
boolean starts(string value, string match)
valuethe string to testmatchstarts with
return does the string start with match
boolean ends(string value, string match)
valuethe string to testmatchends with
return does the string end with match
string between(string value, string left, string right)
valuethe string to processleftleft hand delimiterrightright hand delimiter (defaults toleft)
return the string between the delimiters
qp.between('<div>hello world</div>', '<div>', '</div>');
=> hello worldstring camel_case(string value)
valuethe string to process
return converted to CamelCase
string kebab_case(string value)
valuethe string to process
return converted to kebab-case
string snake_case(string value)
valuethe string to process
return converted to snake_case
string repeat(string value, number times, string delimiter)
valuethe string to repeattimesthe number of times to repeat the stringdelimiterthe delimiter between the repeats (defaults to'')
return repeated string
string replace_all(string value, string search, string replace)
valuethe string to processsearchthe string to search for. optionally a regular expressionreplacethe replacement string
return replace all occurrences of one string within another
string get_utf8_length(string value)
see http://stackoverflow.com/a/12206089
valuethe string to process
return the string length in bytes with regard for the encoding
string stringify(object value, boolean simple)
valuethe object to convert to a stringsimpleif true, produces simplified output, does not process children
return string representation of value
qp.stringify({ one: 'two', three: { four: 'five' } });
> "{ one: two, three: { four: five } }"array map(array items, function map, object context)
itemsthe source arrayobject function map(object item, number index, array items)itemcurrent item being processedindexcurrent item indexitemsthe source arrayreturnthe item to be added to the mapped array
contextcontext of map function
return a new array produced via the map function
object reduce(array items, function reduce, object value)
itemsthe source arrayreducethe reduce functionvaluethe initial reduce value
return
array arg(arguments args)
argsthe arguments object
return containing the passed arguments
array to_array(object value)
valuethe value to convert to an array
attempts to convert the passed value to an array. converts array like objects, strings are split to chars, single values are placed inside a new array, otherwise an empty array is returned
return value converted to array
array union(array items, ...)
itemsarray of items...further items to concatenate
concatenate arrays passed as items
return a single array
array flatten(object | array value, ...)
value...
concatenates items, arrays and arguments to a single array
return a one dimensional array
array compact(array items)
itemsthe items to compact
return items with falsey values removed
now()
timer()
date()
file_date()
date_time()
object bind(object source, object context)
sourcesource of functions to bindcontextcontext object (defaults to source object)
Iterates functions of source object and binds them to the context object
return source object
object invoke(function fn, object context)
fnthe function to invoke (also function[])contextthe context object
return the return value of fn (or array if function[] is passed)
void function invoke_after(function fn, number n, object context)
fnthe function to invokenthe number of timesfnis called before it is to be invokedcontextthe context object
return the wrapped function
void invoke_delay(function fn, number milli)
fnthe function to invokemillithe delay in milliseconds
void invoke_next(function fn, function check, number milli)
fnthe function to invokecheckthe check function must returntrueforfnto be invokedmillithe interval to invokecheckat
string typeof(object value, boolean ctor)
valuethe value on which to callObject.prototype.toStringctorpass true to returnconstructor.nameif available (defaults to false)
if ctor is true and the class name is object then pojo is returned if a constructor name is not available.
possible values of class name (lower case);
object, array, function, date, regexp, string, number, boolean, error, math, json, arguments, null & undefined
return the class name of value
var example = { str: 's', int: 1, bool: true };
qp.typeof(example);
> 'object'
qp.typeof(example, true);
> 'pojo'
qp.typeof(example.bool)
> 'boolean'
function Shape() { }
Shape.prototype.draw = function() { };
var s = new Shape();
qp.typeof(s);
> 'object'
qp.typeof(s, true);
> 'shape'boolean is(object value, string class, ...)
valuethe value to testclassthe class name (or constructor name) to match...further class names to match
return if the class name of value equals class
boolean is_not(object value, string class, ...)
valuethe value to testclassthe class name (or constructor name) to match...further class names to match
return if the class name of value does not equal class
number size(object value)
valueto test
if value is an array then length is returned else Object.keys().length
return the "size" of value
boolean each(object value, function fn, object context)
valueboolean function fn(object item, number index, object value)itemindexvaluereturn
context
return if the loop exited early
boolean each_own(object value, function fn, object context)
valueboolean function fn(object item, number index, object value)itemindexvaluereturn
context
return if the loop exited early
object assign(object target, object source, ...)
targetsource...
return
object assign_own(object target, object source, ...)
targetsource...
return
object assign_if(object target, object source, ...)
targetsource...
return
boolean equals(object value_a, object value_b)
value_afirst objectvalue_bsecond object
performs a deep comparison of objects, and arrays
return true if value_a exactly equals value_b
object clone(object value)
valuethe value to clone
performas a deep clone of object and arrays. also clones Date objects
return a copy of value
object copy(object value)
valuethe value to copy
performs a shallow copy
return a copy value
object merge(object target, object source, ...)
targetthe destination objectsourcethe values to merge intotarget...furthersourceobjects
merges source objects into target, working from left to right
return the target object
object extend(object target, function | object source, ...)
targetthe object to extendsourcefunctionthe function is called and the return value is used assource...the arguments passed tofunctionobjectcopysourcekeys totarget
copy keys from source to target. if source is function its return value is used as source
return the extended target object
object override(object value_a, object value_b)
value_avalue_b
return
object | array first(array items, number count)
itemscount
return the first item in items, or first count items
object | array last(array items, number count)
itemscount
return the last item in items, or last count items
array rest(array items, number from)
itemsfrom
return
object at(array items, number index)
itemsindex
return
array range(array items, number from, number to)
return
boolean in(object item, array items)
return
boolean not_in(object item, array items)
return
function find_predicate(function | object | string arg1, object arg2)
arg1functionobjectstring
arg2objectcontextundefinedobjectvalue to match
return
find()
return
any()
return
find_all()
return
find_index()
return
remove()
return
pick_predicate()
return
pick()
return
pick_own()
return
pairs()
return
keys()
return
values()
return
pick_values()
return
sort()
return
sort_on()
return
group_on()
return
group_by()
return
ns()
return
options()
return
id()
return
uuid()
return
series()
return
each_series()
return
parallel()
return
each_parallel()
return
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago