npm install qp-utility --save
<script src="qp-utility.min.js"></script>
<link href="qp-utility.min.css" rel="stylesheet">
cd qp-utility
node build
no operation
reg_exp
regular expression string
escape special chars in a regular expression string
return
escaped string
value
to check
return
true if value is a function
value
to check
return
true if value is a function
number
minimum valuenumber
maximum value
return
a random number between minimum and maximum values
value
to check
return
true if value is undefined
, null
or length === 0
value
to check
return
inverse of is_empty
value
the string to trimchars
the characters to trim fromvalue
return
remove characters from both sides of the string
value
the string to trimchars
trim characters
return
remove the trim characters from the left side of the string
value
the string to trimchars
trim characters
return
remove the trim characters from the right side of the string
value
any combination of strings, string arrays and arguments...
furthervalue
s
flatten
and compact
values
into a flat array and then join
s them
return
string
qp.build(
'<h1>',
'hello world',
'</h1>'
);
=> <h1>hello world</h1>
html
string to escape
return
escape special chars to html entities
html
string to unescape
return
unescape html entities to special chars
value
the string to padpad
padding characterslen
pad to length
return
pad left side of value
value
the string to padpad
padding characterslen
pad to length
return
pad right side of value
value
the string to testmatch
starts with
return
does the string start with match
value
the string to testmatch
ends with
return
does the string end with match
value
the string to processleft
left hand delimiterright
right hand delimiter (defaults toleft
)
return
the string between the delimiters
qp.between('<div>hello world</div>', '<div>', '</div>');
=> hello world
value
the string to process
return
converted to CamelCase
value
the string to process
return
converted to kebab-case
value
the string to process
return
converted to snake_case
value
the string to repeattimes
the number of times to repeat the stringdelimiter
the delimiter between the repeats (defaults to''
)
return
repeated string
value
the string to processsearch
the string to search for. optionally a regular expressionreplace
the replacement string
return
replace all occurrences of one string within another
see http://stackoverflow.com/a/12206089
value
the string to process
return
the string length in bytes with regard for the encoding
value
the object to convert to a stringsimple
if 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 } }"
-
items
the source array -
object function map(object item, number index, array items)
item
current item being processedindex
current item indexitems
the source array
return
the item to be added to the mapped array -
context
context of map function
return
a new array produced via the map
function
items
the source arrayreduce
the reduce functionvalue
the initial reduce value
return
args
the arguments object
return
containing the passed arguments
value
the 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
items
array of items...
further items to concatenate
concatenate arrays passed as items
return
a single array
value
...
concatenates items, arrays and arguments to a single array
return
a one dimensional array
items
the items to compact
return
items with falsey
values removed
source
source of functions to bindcontext
context object (defaults to source object)
Iterates functions of source object and binds them to the context object
return
source object
fn
the function to invoke (also function[])context
the context object
return
the return value of fn
(or array if function[] is passed)
fn
the function to invoken
the number of timesfn
is called before it is to be invokedcontext
the context object
return
the wrapped function
fn
the function to invokemilli
the delay in milliseconds
fn
the function to invokecheck
the check function must returntrue
forfn
to be invokedmilli
the interval to invokecheck
at
value
the value on which to callObject.prototype.toString
ctor
pass true to returnconstructor.name
if 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'
value
the value to testclass
the class name (or constructor name) to match...
further class names to match
return
if the class name of value
equals class
value
the value to testclass
the class name (or constructor name) to match...
further class names to match
return
if the class name of value
does not equal class
value
to test
if value
is an array then length
is returned else Object.keys().length
return
the "size" of value
-
value
-
boolean function fn(object item, number index, object value)
item
index
value
return
-
context
return
if the loop exited early
-
value
-
boolean function fn(object item, number index, object value)
item
index
value
return
-
context
return
if the loop exited early
target
source
...
return
target
source
...
return
target
source
...
return
value_a
first objectvalue_b
second object
performs a deep comparison of objects, and arrays
return
true
if value_a exactly equals value_b
value
the value to clone
performas a deep clone of object and arrays. also clones Date
objects
return
a copy of value
value
the value to copy
performs a shallow copy
return
a copy value
target
the destination objectsource
the values to merge intotarget
...
furthersource
objects
merges source
objects into target
, working from left to right
return
the target
object
target
the object to extendsource
function
the function is called and the return value is used assource
...
the arguments passed tofunction
object
copysource
keys totarget
copy keys from source
to target
. if source
is function
its return value is used as source
return
the extended target
object
value_a
value_b
return
items
count
return
the first item in items
, or first count
items
items
count
return
the last item in items
, or last count
items
items
from
return
items
index
return
return
return
return
arg1
function
object
string
arg2
object
contextundefined
object
value to match
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return
return