Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@magic/deep

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magic/deep

manipulate nested objects and arrays

  • 0.1.11
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
400
increased by16.96%
Maintainers
2
Weekly downloads
 
Created
Source

@magic/deep

Work with deeply nested objects and arrays.

NPM version Linux Build Status Windows Build Status Coverage Status Greenkeeper badge Known Vulnerabilities

install
npm i --save --save-exact @magic/deep
import
// single function
import { equal, flatten, loop, merge } from '@magic/deep'

// object with all functions
import deep from '@magic/deep'

Currently implemented:

deep.equal
// test equality
deep.equal(['shallow', ['deep']], ['shallow', ['deep']])
// true

// alias
deep.equals, deep.eq
deep.different
// test difference
deep.different(['shallow', ['deep']], ['shallow', ['deep']])
// false

// alias
deep.diff
deep.flatten
// flatten a deeply nested array
deep.flatten(['shallow', ['deep']])
// ['shallow', 'deep']
deep.loop
// apply function add
const add = e => e + 1

// for each item
const items = [1, 2, [3]]

// using a deeply nested array
deep.loop(add, items)
// or
deep.loop(items, add)
// returns [2, 3, [4]]
deep.merge
// merge objects and arrays, with infinite recursion if needed.
// this can be slow...

deep.merge({ obj1Key: { val: 1 } }, { obj2Key: { val: 2 } } )

// { obj1Key: { val: 1}, obj2Key: { val: 2 } }

deep.merge({ key: { val: 1, str: 'test' } }, { key: { val: 2, str: 'overwritten' } })

// { key: { val: 2, str: 'overwritten' } }

Changelog

0.1.0

use ecmascript modules instead of commonjs.

0.1.1
  • update readme
  • also export deep.eq alias for deep.equal
0.1.2
  • require node 13.5.0
  • use deep.equal and deep.different from @magic/types
0.1.3

bump required node version to 14.2.0

0.1.4

update dependencies

0.1.5
  • bump required node version to 14.15.4
  • update dependencies
0.1.6
  • merge now checks if o2.hasOwnProperty is a function before using it to check if we should overwrite keys of o1 or not.
0.1.7

update @magic/types to avoid circular dependency

0.1.8
  • update dependencies
  • use @magic/types for all type comparisons
0.1.9

update dependencies

0.1.10

update dependencies

0.1.11

update dependencies

0.1.12 - unreleased

...

FAQs

Package last updated on 01 Apr 2022

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