Nomenclature Processing Machine
    Have ideas to improve npm?Join in the discussion! »

    TypeScript icon, indicating that this package has built-in type declarations

    2.2.2 • Public • Published


    Statements Branches Functions Lines
    Statements Branches Functions Lines

      Simple javascript utility, lodash alternative, to help with type validation, with no dependencies.

    • esmodule supports esnext, es2015 and umd
    • Lightweight, minified  


    Website docs at:  


    Full coverage details at:  


    $/ 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  


    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>
        const {...} = window.xutils // get access to all utils


    Example overview

    For full detail refer to website docs:


    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 promise sq()

    # 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 of isFalse()

    # isFalse()

    Check if item is lt < 1, false, null or undefined

    # 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 delay is 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{} and source{}

    # exactKeyMatch()

    Test if ALL keys match between object{} and source{}

    # 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 to trueVal()

    # trueProp()

    Object with true entities will be returned

    # typeCheck()

    Examines element for its type, provided value, and primitive value

    # isEmpty()

    Check item has some value, set of props, or length

    # 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 with undefined keeping index position

    # pickFromArray()

    Array selection tool. Filter items in array[item,item] by picks[Types|primitives,values] conditions

    # dispatcher()

    Lightweight Event Dispatcher, allowing dispatch anywhere in code, very handy in callback/hell situations, 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_THROW is 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, produces green color output

    # onerror()

    Extends console.error with [error] prefix, produces red color output

    # warn()

    Extends console.log with [warn] prefix, produces bright white color output

    # attention()

    Extends console.log with [attention] prefix, produces blue color output

    # alert()

    Extends console.log with [alert] prefix, produces yellow color 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]



    Have questions, or would like to submit feedback contact


    npm i x-utils-es

    DownloadsWeekly Downloads






    Unpacked Size

    212 kB

    Total Files


    Last publish


    • avatar