Package Exports
- x-utils-es
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (x-utils-es) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
x-utils-es
| Statements | Branches | Functions | Lines |
|---|---|---|---|
Simple javascript utility, lodash alternative, to help with type validation, with no dependencies.
- esmodule supports
esnext,es2015andumd - Lightweight, minified
Documentation
Website docs at: utils.eaglex.net
Coverage
Full coverage details at: utils.eaglex.net/coverage
Install
$/ npm i x-utils-es
Why use it
- Validate data
- Good with naming conventions
- Similar to lodash
- No dependencies
- UMD support so you can use in most environments: (AMD, common.js/Node, or browser)
- @types supported, can be used with typescript
@types
Definitly typed (DT) support on all version
Version support
For production with gulp/webpack ..etc, use source (1) version, otherwise use any other.
import {} from 'x-utils-es' // src e-module (1)
import {} from 'x-utils-es/esm' // (minified) (2)
import {} from 'x-utils-es/umd' // for browser and commonjs support (minified) (3)
const {} require('x-utils-es/umd') // with node/commonjs support
// browser
<script src="..path/umd"></script>
<script>
const {...} = window.xutils // get access to all utils
</script>
Example overview
For full detail refer to website docs: utils.eaglex.net
import { ... } from 'x-utils-es' # objectSize()
Check item is an array
# stringSize()
Test the length of string
# head()
Get first item from array
# shuffle()
Randomise items in array
# flatten()
Flatten 2 level array to 1 level
# flattenDeep()
Flatten all array levels to 1
# last()
Gets last item from array
# copy()
Makes item copy
# copyBy()
Copy object by property name
# copyDeep()
Makes deep copy including nested items
# asJson()
Returns in pretty json fromat
# isFunction()
Check if item is a function
# timer()
Timer callback executes on timeout
# interval()
Execute callback every interval, then exit on endTime
# validID()
Convert to string, remove spaces, toLowerCase
# isNumber()
Check item is a number
# sq()
SimpleQ / instanceof Promise, deferred simplified promise
# isPromise()
Check for
Promise/q.defer/ and xutils promisesq()
# isQPromise()
Tests for the
q.defer()node.js promise version
# cancelPromise()
Cancelable synchronous process, determines how long to wait before we exit
# uniq()
Returns new array of unique values
# uniqBy()
Selects first match ignoring others of those which prop values are repeated
# isObject()
Test item is a true object, and not array
# isArray()
Test item is a true array, and not object
# arraySize()
Test item is an array, and check the size
# chunks()
Split array to chunks by providing size number
# isString()
Test item is a string type
# isRegExp()
Check pattern is an expression of RegExp
# isFalsy()
Check if any item type is falsy, object, array, class/instance, having no props set
# isTrue()
Check if item is
gth > 0,true, basically opposite ofisFalse()
# isFalse()
Check if item is
lt < 1,false,nullorundefined
# isBoolean()
Check if item is a boolean
# isNull()
Check if item is
===null
# isUndefined()
Check if item is
===undefined
# delay()
Delay a sync/async process, to be executed after
delayis resolved
# truthFul()
Return new object excluding all undefined values in top level
# inIndex()
Test accuracy of a
match[x]in a string
# matched()
Match string value by expression
# someKeyMatch()
Test if ANY keys match between
object{}andsource{}
# exactKeyMatch()
Test if ALL keys match between
object{}andsource{}
# trueVal()
Exclude any falsy values from array, such as:
[0,null,false,{},undefined, -1,'',[]]
# trueValDeep()
Exclude any falsy values from array:
[0,null,false,{},undefined, -1,'',[]], but testing 1 level deeper, compared totrueVal()
# trueProp()
Object with true entities will be returned
# typeCheck()
Examines element for its
type, providedvalue, andprimitive value
# isEmpty()
Check item has some
value, set ofprops, orlength
# isError()
Check item is of Error object family
# isInstance()
Testing if item{} is a
new Item{}, instance of a class
# isClass()
Test item is a class{} constractor, that can be initiated
# hasPrototype()
Test item is a class{} constractor, that can be initiated, ( alias of isClass() )
# hasProto()
Check if item has access to
__proto__
# validDate()
Evaluate if data is an actual
Date
# selectiveArray()
Select data from array of objects by reference, and go down recursively in order of selectBy
['a.b']ref
# arrayWith()
Mixed array of objects and values, grab
items[]that include specific prop.
# exFromArray()
Exclude items from array matchd by
excludes[], and replace withundefinedkeeping index position
# pickFromArray()
Array selection tool. Filter items in
array[item,item]bypicks[Types|primitives,values]conditions
# dispatcher()
Lightweight Event Dispatcher, allowing dispatch anywhere in code, very handy in
callback/hellsituations, deep promises, or other computations.
# withHoc()
High order caller, concept taken from React HOC. Supports promises
# resolver()
Run some method that returns value in future, checking updates until timeout, or exit when data becomes available.
# dupes()
Duplicate item x:number of times
# loop()
Looping each item inside of callback
# noop()
No operation function
# trim()
Trim boths sides of string, including new lines, and multiple spaces to single space
# xError()
Extended Error(...) with extra
{id,name,fileName,lineNumber}used to throw exception.
# referenceError()
Extended ReferenceError(...) with extra
{name,fileName,lineNumber,columnNumber}, used to throw exception.
# xrequire()
Extended NodeRequire, does not throw when argument
ref=ERR_NO_THROWis provided. THIS METHOD ONLY WORK FOR COMMON.JS modules, and not for browser
# loggerSetting()
Allow enabling and disabling of loggers:
log/warn/error/onerror/attention/debug/alert
# resetLogging()
Change state of xutils loggers when calling at top of hoist level. Effects:
log/warn/error/onerror/attention/debug/alert
# log()
Extends console.log with
[log]prefix
# debug()
Extends console.log with
[debug]prefix, producesgreencolor output
# onerror()
Extends console.error with
[error]prefix, producesredcolor output
# warn()
Extends console.log with
[warn]prefix, produces brightwhitecolor output
# attention()
Extends console.log with
[attention]prefix, producesbluecolor output
# alert()
Extends console.log with
[alert]prefix, producesyellowcolor output. Does not work on window object ( for obvious reasons! )
# stack()
For stack tracing, prefixed with
[STACK TRACE]
# errorTrace()
For stack tracing, prefixed with
[ERROR]
# unsubscribe()
Unsubscribe from an RX/subscription, by providing array of active subs
# includes()
Compare match array items with the id, if any were found return true
# spread()
Spread data of an object as you would ...data, but with selected prop names that match the object
[#][id:77] spreadWith()
Spread only selected array items matching index number
Contact
Have questions, or would like to submit feedback contact eaglex.net