New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lutils

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lutils

A few reliable utils.

  • 2.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source
 

lutils

TypesSript documented

  • merge for deep merging of objects
  • clone for deep cloning of objects & arrays
  • typeOf for consistant type checking
import { typeOf, merge, clone } from 'lutils'

merge

Merge objects together, traversing objects & arrays recursively

  • merge(subject, ...sources[]) => subject
  • Default depth: 10
import { merge } from 'lutils'

merge({ aa: { cc: 1 }, }, { aa: { cc: 2 } }, { bb: 3 })
=== { aa: { cc: 2 }, bb: 3 }

Construct & configure your own Merge instance

  • new Merge(config).merge
  • See: config
import { Merge } from 'lutils'

const merge = new Merge({ depth: Infinity }).merge

merge(megaDeep, ultraDeep)

Merge, but with two common behaviours, whitelisting and blacklisting

  • merge.white(subject, ...sources[]) => subject
  • merge.black(subject, ...sources[]) => subject
import { merge } from 'lutils'

merge.white({ aa: { bb: 1, cc: 1 } }, { aa: { xx: 2, cc: 2 } })
=== { aa: { bb: 1, cc: 2 } }

merge.black({ aa: { bb: 1, cc: 1 } }, { aa: { xx: 2, cc: 2 } })
=== { aa: { bb: 1, cc: 1, xx: 2 } }

clone

Clones objects & arrays recursively

  • clone(subject) => clonedSubject
  • Default depth: 10
import { clone } from 'lutils'

const cloned = clone({ my: { little: { foo: 'bar' } } })
  • new Clone(config).clone
  • See: config
import { Clone } from 'lutils'

const clone = new Clone({ depth: Infinity }).clone

const cloned = clone({ my: { little: { foo: 'bar' } } })

typeOf

Gets the type of a value as a lowercase string.
Like the built-in typeof, but works for all primitives.

  • typeOf(value) => string
import { typeOf } from 'lutils'

typeOf(null)
=== 'null'

typeOf(NaN)
=== 'nan'

typeOf([])
=== 'array'

Specific type checkers are also exported and attached to typeOf
These checkers also supply typescript with type information, meaning they can act a type guards.

  • isBoolean(value) => boolean
  • is<type>(value) => boolean
  • See: ITypeOf
import { typeOf, isBoolean, isString } from 'lutils'

typeOf.isNull(null)
=== true

isString(undefined)
=== false

typeOf.isString('')
=== true

isBoolean(false)
=== true

// Type guarding...

function blah (aa: number|string) {
  if (isString(aa)) {
    // string
    aa += '!!!!'
  } else {
    // number
    ++aa 
  }

  return aa
}

Keywords

FAQs

Package last updated on 06 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc