Skip to content
fabiocaccamoPublic

About

👷 🔧 zero dependencies vanilla JavaScript utils.

Topics

Resources

Code of conduct

Security policy

Stars

24 stars

Watchers

3 watching

Forks

Repository files navigation

OpenSSF Scorecard

utils.js

👷 🔧 zero dependencies vanilla JavaScript utils.

Table of contents

Installation

This library is available through npm:

npm install @fabiocaccamo/utils.js

Usage

CDN

<script src=" https://cdn.jsdelivr.net/npm/@fabiocaccamo/utils.js/dist/utils.min.js"></script>

Local

<script src="node_modules/@fabiocaccamo/utils.js/dist/utils.min.js"></script>

Node

var utils = require("@fabiocaccamo/utils.js");

ESM

Three import styles are supported:

// named imports from a module subpath (recommended with bundlers, most explicit)
import { debounce } from '@fabiocaccamo/utils.js/func';
import { slugify, toUpperCaseFirst } from '@fabiocaccamo/utils.js/string';

// module namespaces from the root entry (tree-shakeable with static member access)
import { func, string } from '@fabiocaccamo/utils.js';
func.debounce(250, () => {});

// default import (kept for backward compatibility)
import utils from '@fabiocaccamo/utils.js';
utils.func.debounce(250, () => {});

When using a bundler (Rollup, webpack, esbuild, Vite, ...), prefer the subpath or the named namespace imports: the package is marked as "sideEffects": false and every function is exported by name, so only the functions actually used (and their real dependencies) end up in the bundle.

The default import is kept for compatibility: it works as before, but it references the whole library object, so it can be tree-shaken only by bundlers able to track static property accesses on objects.

Every module is available as a subpath: array, base64, color (and color/cmyk, color/hex, color/rgb), date, ease, func, geom (and geom/point), hex, interpolation, json, math, number, object, random, string, test, trigo, type, url, utf8, xml.

Subpaths point to the ES modules sources: in CommonJS use require('@fabiocaccamo/utils.js').

Functions are not exported at root level because some names are shared by different modules (eg. clone, decode, encode, equals, max, min), import them from the module subpath instead.

APIs

utils.array

  • all

  • any

  • clean

  • clone

  • contains

  • equals

  • flatten

  • index

  • insert

  • max

  • min

  • paginate

  • reduce

  • remove

  • replace

  • rotate

  • shuffle

  • sort

  • sum

  • unique

  • unzip

  • zip

utils.base64

  • decode

  • encode

utils.color

  • cmykToHex

  • cmykToRgb

  • hexToCmyk

  • hexToRgb

  • rgbToCmyk

  • rgbToHex

utils.color.cmyk

  • toString

  • toStringCSS

utils.color.hex

  • average

  • distance

  • gradient

  • gradientMatrix

  • interpolateBilinear

  • interpolateLinear

  • interpolateMultilinear

  • nearest

  • toCmyk

  • toRgb

  • toString

  • toStringCSS

utils.color.rgb

  • average

  • distance

  • gradient

  • gradientMatrix

  • interpolateBilinear

  • interpolateLinear

  • interpolateMultilinear

  • nearest

  • toCmyk

  • toRgb

  • toString

  • toStringCSS

utils.date

  • clone

  • constrain

  • format

  • isFuture

  • isPast

  • max

  • min

  • parse

  • timestamp

  • today

  • tomorrow

  • yesterday

  • yyyymmdd

utils.ease

  • backIn

  • backInOut

  • backOut

  • bounceIn

  • bounceInOut

  • bounceOut

  • circularIn

  • circularInOut

  • circularOut

  • cubicIn

  • cubicInOut

  • cubicOut

  • elasticIn

  • elasticInOut

  • elasticOut

  • exponentialIn

  • exponentialInOut

  • exponentialOut

  • none

  • quadraticIn

  • quadraticInOut

  • quadraticOut

  • quarticIn

  • quarticInOut

  • quarticOut

  • quinticIn

  • quinticInOut

  • quinticOut

  • sexticIn

  • sexticInOut

  • sexticOut

  • sineIn

  • sineInOut

  • sineOut

  • waveCosine

  • waveSawtooth

  • waveSine

utils.func

  • args

  • attempt

  • bind

  • call

  • debounce

  • delay

  • memoize

  • noop

  • repeat

  • throttle

  • until

  • validate

utils.geom

utils.geom.point

  • add

  • angle

  • cross

  • distance

  • dot

  • equals

  • interpolate

  • isInRect

  • isInTriangle

  • isOnSegment

  • length

  • magnitude

  • project

  • rect

  • rotate

  • scale

  • subtract

  • translate

utils.hex

  • decodeInt

  • encodeInt

utils.json

  • decode

  • encode

utils.math

  • average

  • constrain

  • cycle

  • equals

  • euclideanDistance

  • factorial

  • gcd

  • lcm

  • lerp

  • map

  • nearest

  • normalize

  • proportion

  • roundDecimals

  • roundToMultiple

  • roundToNearest

  • roundToPower

  • sign

  • summation

utils.math.interpolation

  • bilinear

  • linear

  • multilinear

  • scalar

utils.number

  • isBetween

  • isEven

  • isFloat

  • isNegative

  • isOdd

  • isPositive

  • isPrime

utils.object

  • assign

  • clean

  • clone

  • decodeBase64

  • decodeJSON

  • decodeParameters

  • encodeBase64

  • encodeJSON

  • encodeParameters

  • equals

  • hasOwnProp

  • is

  • keypath

  • keys

  • length

  • map

  • merge

  • search

  • values

utils.random

  • argument

  • bit

  • boolean

  • color

  • element

  • float

  • index

  • integer

  • map

  • sign

  • string

utils.string

  • contains

  • endsWith

  • hash

  • icontains

  • levenshteinDistance

  • levenshteinSimilarity

  • padLeft

  • padRight

  • padZeros

  • render

  • replace

  • reverse

  • rotate

  • slugify

  • startsWith

  • toConstantCase

  • toRandomCase

  • toTitleCase

  • toUpperCaseFirst

  • trim

  • trimLeft

  • trimRight

utils.test

  • assertArray

  • assertBase64

  • assertBoolean

  • assertDate

  • assertEqual

  • assertError

  • assertFalse

  • assertFunction

  • assertJSON

  • assertNaN

  • assertNone

  • assertNotArray

  • assertNotBase64

  • assertNotBoolean

  • assertNotDate

  • assertNotEqual

  • assertNotError

  • assertNotFunction

  • assertNotJSON

  • assertNotNone

  • assertNotNull

  • assertNotNumber

  • assertNotObject

  • assertNotRegExp

  • assertNotString

  • assertNotUndefined

  • assertNull

  • assertNumber

  • assertNumberAlmostEqual

  • assertObject

  • assertRegExp

  • assertString

  • assertThrows

  • assertTrue

  • assertUndefined

utils.trigo

  • acosDeg

  • angleDeg

  • angleRad

  • asinDeg

  • atan2Deg

  • atanDeg

  • cosDeg

  • cycleDeg

  • degToRad

  • fastDeg

  • haversine

  • hypo

  • radToDeg

  • sinDeg

  • tanDeg

utils.type

  • isArray

  • isBase64

  • isBoolean

  • isDate

  • isError

  • isFunction

  • isJSON

  • isNaN

  • isNone

  • isNull

  • isNumber

  • isObject

  • isRegExp

  • isString

  • isType

  • isUndefined

  • of

utils.url

  • getDomain

  • getParameterByName

  • getParameters

  • getParametersDict

  • getParametersList

  • getParametersString

  • getURL

  • hasParameter

  • isFile

  • isHttp

  • isHttps

  • isLocalhost

utils.utf8

  • decode

  • encode

utils.xml

  • removeNamespaces

Development

Setup

  • git clone https://github.com/fabiocaccamo/utils.js.git
  • npm install

Watch

  • npm run watch

Testing

  • npm run test (run tests against dist using Gulp task runner and Mocha Javascript testing framework)

Formatting

  • npm run format (format code using Prettier code formatter, refer to .prettierrc for specific formatting options)

Build

  • npm run build

Security

Refer to SECURITY.md

License

Released under MIT License.

About

👷 🔧 zero dependencies vanilla JavaScript utils.

Topics

Resources

Code of conduct

Security policy

Stars

24 stars

Watchers

3 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages