Socket
Socket
Sign inDemoInstall

@cbuschka/data-utils

Package Overview
Dependencies
2
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

dist/legacy/paths/__tests__/split_test.js

22

dist/legacy/__tests__/set_test.js

@@ -45,2 +45,24 @@ "use strict";

}.bind(void 0));
it('set adds object as array item', function () {
_newArrowCheck(this, _this);
var data = {
prop: {
sub: []
}
};
(0, _set.set)('prop.sub[0].value', data, 2);
expect(data.prop.sub[0].value).toEqual(2);
}.bind(void 0));
it('set adds value as array item', function () {
_newArrowCheck(this, _this);
var data = {
prop: {
sub: []
}
};
(0, _set.set)('prop.sub[0]', data, 2);
expect(data.prop.sub[0]).toEqual(2);
}.bind(void 0));
//# sourceMappingURL=set_test.js.map

6

dist/legacy/get.js
"use strict";
require("core-js/modules/es6.regexp.split");
Object.defineProperty(exports, "__esModule", {

@@ -8,3 +10,3 @@ value: true

require("core-js/modules/es6.regexp.split");
var _split = require("./paths/split");

@@ -20,3 +22,3 @@ var _this = void 0;

var parts = path.split(/\./);
var parts = (0, _split.split)(path);
var curr = target;

@@ -23,0 +25,0 @@

"use strict";
require("core-js/modules/es6.regexp.split");
Object.defineProperty(exports, "__esModule", {

@@ -8,4 +10,8 @@ value: true

require("core-js/modules/es6.regexp.split");
require("core-js/modules/es6.number.constructor");
require("core-js/modules/es6.number.is-integer");
var _split = require("./paths/split");
var _this = void 0;

@@ -18,3 +24,3 @@

var parts = path.split(/\./);
var parts = (0, _split.split)(path);
var curr = target;

@@ -24,3 +30,3 @@

if (!curr.hasOwnProperty(parts[i])) {
curr[parts[i]] = {};
curr[parts[i]] = Number.isInteger(parts[i + 1]) ? [] : {};
}

@@ -27,0 +33,0 @@

{
"name": "@cbuschka/data-utils",
"version": "1.0.0",
"version": "1.1.0",
"description": "Collection of data-utils.",

@@ -5,0 +5,0 @@ "author": "cbuschka@gmail.com",

@@ -35,1 +35,17 @@ import {set} from '../set.js';

});
it('set adds object as array item', () => {
const data = {prop: {sub: []}};
set('prop.sub[0].value', data, 2)
expect(data.prop.sub[0].value).toEqual(2);
});
it('set adds value as array item', () => {
const data = {prop: {sub: []}};
set('prop.sub[0]', data, 2)
expect(data.prop.sub[0]).toEqual(2);
});

@@ -0,3 +1,5 @@

import {split as splitPath} from './paths/split';
export const get = (path, target, defaultValue = undefined) => {
const parts = path.split(/\./);
const parts = splitPath(path);
let curr = target;

@@ -4,0 +6,0 @@ for (let i = 0; i < parts.length - 1; ++i) {

@@ -0,7 +1,10 @@

import {split as splitPath} from './paths/split';
export const set = (path, target, value) => {
const parts = path.split(/\./);
const parts = splitPath(path);
let curr = target;
for (let i = 0; i < parts.length - 1; ++i) {
if (!curr.hasOwnProperty(parts[i])) {
curr[parts[i]] = {};
curr[parts[i]] = Number.isInteger(parts[i + 1]) ? [] : {};
}

@@ -8,0 +11,0 @@ curr = curr[parts[i]];

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc