npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

x-utils-es

v2.4.0

Published

helper tools for javascript validation

Downloads

128

Readme

x-utils-es

| 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  
     

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 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]

# 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