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

array-deep-get-set

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-deep-get-set - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

index.d.ts

35

index.js

@@ -1,4 +0,33 @@

import get from 'src/get'
import set from 'src/set'
const lodashGet = require('lodash.get')
const lodashSet = require('lodash.set')
export default { get, set }
const get = (object, path = '', defaultValue) => {
const flatArrayIndex = path.indexOf('[]')
if (flatArrayIndex > 0) {
const pathToArray = path.slice(0, flatArrayIndex)
const pathInArray = path.slice(flatArrayIndex + 3, path.length)
const arrayToFlat = lodashGet(object, pathToArray, []).map((item) =>
lodashGet(item, pathInArray, null)
)
return arrayToFlat
}
return lodashGet(object, path, defaultValue)
}
const set = (objectToSet, path = '', value) => {
const flatArrayIndex = path.indexOf('[]')
if (flatArrayIndex > 0) {
const pathToArray = path.slice(0, flatArrayIndex)
const pathInArray = path.slice(flatArrayIndex + 3, path.length)
const arrayToSet = get(objectToSet, pathToArray, [])
const arraySet = value.map((item, index) => ({
...(arrayToSet[index] ?? []),
[pathInArray]: item,
}))
return lodashSet(objectToSet, pathToArray, arraySet)
}
return lodashSet(objectToSet, path, value)
}
module.exports = {get, set}

10

package.json
{
"name": "array-deep-get-set",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "1.0.1",
"author": "Thibaut Mottet",
"license": "ISC",
"publishConfig": {
"access": "public"
},
"dependencies": {

@@ -12,0 +10,0 @@ "lodash.get": "4.4.2",

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