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

can-key

Package Overview
Dependencies
Maintainers
6
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-key - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

1

can-key.md
@module {Object} can-key
@parent can-js-utilities
@collection can-infrastructure
@package ./package.json

@@ -5,0 +6,0 @@ @description Utilities that read and write nested properties on objects and arrays.

18

dist/amd/can-key.js

@@ -1,16 +0,16 @@

/*can-key@1.1.0#can-key*/
define([
/*can-key@1.2.0#can-key*/
define('can-key', [
'require',
'exports',
'module',
'./delete/delete',
'./get/get',
'./replace-with/replace-with',
'./set/set',
'./transform/transform',
'./walk/walk',
'can-key/delete/delete',
'can-key/get/get',
'can-key/replace-with/replace-with',
'can-key/set/set',
'can-key/transform/transform',
'can-key/walk/walk',
'can-namespace'
], function (require, exports, module) {
'use strict';
var deleteKey = require('./delete/delete'), get = require('./get/get'), replaceWith = require('./replace-with/replace-with'), set = require('./set/set'), transform = require('./transform/transform'), walk = require('./walk/walk'), namespace = require('can-namespace');
var deleteKey = require('can-key/delete/delete'), get = require('can-key/get/get'), replaceWith = require('can-key/replace-with/replace-with'), set = require('can-key/set/set'), transform = require('can-key/transform/transform'), walk = require('can-key/walk/walk'), namespace = require('can-namespace');
module.exports = namespace.key = {

@@ -17,0 +17,0 @@ deleteKey: deleteKey,

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

/*can-key@1.1.0#delete/delete*/
define([
/*can-key@1.2.0#delete/delete*/
define('can-key/delete/delete', [
'require',

@@ -7,7 +7,7 @@ 'exports',

'can-reflect',
'../utils'
'can-key/utils'
], function (require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var utils = require('../utils');
var utils = require('can-key/utils');
module.exports = function deleteAtPath(data, path) {

@@ -14,0 +14,0 @@ var parts = utils.parts(path);

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

/*can-key@1.1.0#get/get*/
define([
/*can-key@1.2.0#get/get*/
define('can-key/get/get', [
'require',

@@ -7,7 +7,7 @@ 'exports',

'can-reflect',
'../utils'
'can-key/utils'
], function (require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var utils = require('../utils');
var utils = require('can-key/utils');
function get(obj, name) {

@@ -14,0 +14,0 @@ var parts = utils.parts(name);

@@ -1,14 +0,14 @@

/*can-key@1.1.0#replace-with/replace-with*/
define([
/*can-key@1.2.0#replace-with/replace-with*/
define('can-key/replace-with/replace-with', [
'require',
'exports',
'module',
'../utils',
'../get/get',
'../delete/delete'
'can-key/utils',
'can-key/get/get',
'can-key/delete/delete'
], function (require, exports, module) {
'use strict';
var utils = require('../utils');
var get = require('../get/get');
var deleteKey = require('../delete/delete');
var utils = require('can-key/utils');
var get = require('can-key/get/get');
var deleteKey = require('can-key/delete/delete');
module.exports = function (str, data, replacer, shouldRemoveMatchedPaths) {

@@ -15,0 +15,0 @@ return str.replace(utils.strReplacer, function (whole, path) {

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

/*can-key@1.1.0#set/set*/
define([
/*can-key@1.2.0#set/set*/
define('can-key/set/set', [
'require',

@@ -8,3 +8,3 @@ 'exports',

'can-symbol',
'../utils'
'can-key/utils'
], function (require, exports, module) {

@@ -14,3 +14,3 @@ 'use strict';

var canSymbol = require('can-symbol');
var utils = require('../utils');
var utils = require('can-key/utils');
var setValueSymbol = canSymbol.for('can.setValue');

@@ -17,0 +17,0 @@ function set(object, path, value) {

@@ -1,13 +0,13 @@

/*can-key@1.1.0#transform/transform*/
define([
/*can-key@1.2.0#transform/transform*/
define('can-key/transform/transform', [
'require',
'exports',
'module',
'../walk/walk',
'../utils',
'can-key/walk/walk',
'can-key/utils',
'can-reflect'
], function (require, exports, module) {
'use strict';
var walk = require('../walk/walk');
var utils = require('../utils');
var walk = require('can-key/walk/walk');
var utils = require('can-key/utils');
var canReflect = require('can-reflect');

@@ -14,0 +14,0 @@ function deleteKeys(parentsAndKeys) {

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

/*can-key@1.1.0#utils*/
define(function (require, exports, module) {
/*can-key@1.2.0#utils*/
define('can-key/utils', function (require, exports, module) {
'use strict';

@@ -4,0 +4,0 @@ var utils = {

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

/*can-key@1.1.0#walk/walk*/
define([
/*can-key@1.2.0#walk/walk*/
define('can-key/walk/walk', [
'require',

@@ -7,7 +7,7 @@ 'exports',

'can-reflect',
'../utils'
'can-key/utils'
], function (require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var utils = require('../utils');
var utils = require('can-key/utils');
module.exports = function walk(obj, name, keyCallback) {

@@ -14,0 +14,0 @@ var parts = utils.parts(name);

@@ -1,11 +0,24 @@

/*can-key@1.1.0#can-key*/
'use strict';
var deleteKey = require('./delete/delete.js'), get = require('./get/get.js'), replaceWith = require('./replace-with/replace-with.js'), set = require('./set/set.js'), transform = require('./transform/transform.js'), walk = require('./walk/walk.js'), namespace = require('can-namespace');
module.exports = namespace.key = {
deleteKey: deleteKey,
get: get,
replaceWith: replaceWith,
set: set,
transform: transform,
walk: walk
};
/*can-key@1.2.0#can-key*/
define('can-key', [
'require',
'exports',
'module',
'can-key/delete/delete',
'can-key/get/get',
'can-key/replace-with/replace-with',
'can-key/set/set',
'can-key/transform/transform',
'can-key/walk/walk',
'can-namespace'
], function (require, exports, module) {
'use strict';
var deleteKey = require('can-key/delete/delete'), get = require('can-key/get/get'), replaceWith = require('can-key/replace-with/replace-with'), set = require('can-key/set/set'), transform = require('can-key/transform/transform'), walk = require('can-key/walk/walk'), namespace = require('can-namespace');
module.exports = namespace.key = {
deleteKey: deleteKey,
get: get,
replaceWith: replaceWith,
set: set,
transform: transform,
walk: walk
};
});

@@ -1,16 +0,24 @@

/*can-key@1.1.0#delete/delete*/
'use strict';
var canReflect = require('can-reflect');
var utils = require('../utils.js');
module.exports = function deleteAtPath(data, path) {
var parts = utils.parts(path);
var current = data;
for (var i = 0; i < parts.length - 1; i++) {
/*can-key@1.2.0#delete/delete*/
define('can-key/delete/delete', [
'require',
'exports',
'module',
'can-reflect',
'can-key/utils'
], function (require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var utils = require('can-key/utils');
module.exports = function deleteAtPath(data, path) {
var parts = utils.parts(path);
var current = data;
for (var i = 0; i < parts.length - 1; i++) {
if (current) {
current = canReflect.getKeyValue(current, parts[i]);
}
}
if (current) {
current = canReflect.getKeyValue(current, parts[i]);
canReflect.deleteKeyValue(current, parts[parts.length - 1]);
}
}
if (current) {
canReflect.deleteKeyValue(current, parts[parts.length - 1]);
}
};
};
});

@@ -1,18 +0,26 @@

/*can-key@1.1.0#get/get*/
'use strict';
var canReflect = require('can-reflect');
var utils = require('../utils.js');
function get(obj, name) {
var parts = utils.parts(name);
var length = parts.length, current, i, container;
if (!length) {
return obj;
/*can-key@1.2.0#get/get*/
define('can-key/get/get', [
'require',
'exports',
'module',
'can-reflect',
'can-key/utils'
], function (require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var utils = require('can-key/utils');
function get(obj, name) {
var parts = utils.parts(name);
var length = parts.length, current, i, container;
if (!length) {
return obj;
}
current = obj;
for (i = 0; i < length && utils.isContainer(current) && current !== null; i++) {
container = current;
current = canReflect.getKeyValue(container, parts[i]);
}
return current;
}
current = obj;
for (i = 0; i < length && utils.isContainer(current) && current !== null; i++) {
container = current;
current = canReflect.getKeyValue(container, parts[i]);
}
return current;
}
module.exports = get;
module.exports = get;
});

@@ -1,14 +0,23 @@

/*can-key@1.1.0#replace-with/replace-with*/
'use strict';
var utils = require('../utils.js');
var get = require('../get/get.js');
var deleteKey = require('../delete/delete.js');
module.exports = function (str, data, replacer, shouldRemoveMatchedPaths) {
return str.replace(utils.strReplacer, function (whole, path) {
var value = get(data, path);
if (shouldRemoveMatchedPaths) {
deleteKey(data, path);
}
return replacer ? replacer(path, value) : value;
});
};
/*can-key@1.2.0#replace-with/replace-with*/
define('can-key/replace-with/replace-with', [
'require',
'exports',
'module',
'can-key/utils',
'can-key/get/get',
'can-key/delete/delete'
], function (require, exports, module) {
'use strict';
var utils = require('can-key/utils');
var get = require('can-key/get/get');
var deleteKey = require('can-key/delete/delete');
module.exports = function (str, data, replacer, shouldRemoveMatchedPaths) {
return str.replace(utils.strReplacer, function (whole, path) {
var value = get(data, path);
if (shouldRemoveMatchedPaths) {
deleteKey(data, path);
}
return replacer ? replacer(path, value) : value;
});
};
});

@@ -1,25 +0,34 @@

/*can-key@1.1.0#set/set*/
'use strict';
var canReflect = require('can-reflect');
var canSymbol = require('can-symbol');
var utils = require('../utils.js');
var setValueSymbol = canSymbol.for('can.setValue');
function set(object, path, value) {
var parts = utils.parts(path);
var current = object;
var length = parts.length;
for (var i = 0; i < length - 1; i++) {
if (utils.isContainer(current)) {
current = canReflect.getKeyValue(current, parts[i]);
/*can-key@1.2.0#set/set*/
define('can-key/set/set', [
'require',
'exports',
'module',
'can-reflect',
'can-symbol',
'can-key/utils'
], function (require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var canSymbol = require('can-symbol');
var utils = require('can-key/utils');
var setValueSymbol = canSymbol.for('can.setValue');
function set(object, path, value) {
var parts = utils.parts(path);
var current = object;
var length = parts.length;
for (var i = 0; i < length - 1; i++) {
if (utils.isContainer(current)) {
current = canReflect.getKeyValue(current, parts[i]);
} else {
break;
}
}
if (current) {
canReflect.setKeyValue(current, parts[i], value);
} else {
break;
throw new TypeError('Cannot set value at key path \'' + path + '\'');
}
return object;
}
if (current) {
canReflect.setKeyValue(current, parts[i], value);
} else {
throw new TypeError('Cannot set value at key path \'' + path + '\'');
}
return object;
}
module.exports = set;
module.exports = set;
});

@@ -1,37 +0,46 @@

/*can-key@1.1.0#transform/transform*/
'use strict';
var walk = require('../walk/walk.js');
var utils = require('../utils.js');
var canReflect = require('can-reflect');
function deleteKeys(parentsAndKeys) {
for (var i = parentsAndKeys.length - 1; i >= 0; i--) {
var parentAndKey = parentsAndKeys[i];
delete parentAndKey.parent[parentAndKey.key];
if (canReflect.size(parentAndKey.parent) !== 0) {
return;
/*can-key@1.2.0#transform/transform*/
define('can-key/transform/transform', [
'require',
'exports',
'module',
'can-key/walk/walk',
'can-key/utils',
'can-reflect'
], function (require, exports, module) {
'use strict';
var walk = require('can-key/walk/walk');
var utils = require('can-key/utils');
var canReflect = require('can-reflect');
function deleteKeys(parentsAndKeys) {
for (var i = parentsAndKeys.length - 1; i >= 0; i--) {
var parentAndKey = parentsAndKeys[i];
delete parentAndKey.parent[parentAndKey.key];
if (canReflect.size(parentAndKey.parent) !== 0) {
return;
}
}
}
}
module.exports = function (obj, transformer) {
var copy = canReflect.serialize(obj);
canReflect.eachKey(transformer, function (writeKey, readKey) {
var readParts = utils.parts(readKey), writeParts = utils.parts(writeKey);
var parentsAndKeys = [];
walk(copy, readParts, function (info) {
parentsAndKeys.push(info);
module.exports = function (obj, transformer) {
var copy = canReflect.serialize(obj);
canReflect.eachKey(transformer, function (writeKey, readKey) {
var readParts = utils.parts(readKey), writeParts = utils.parts(writeKey);
var parentsAndKeys = [];
walk(copy, readParts, function (info) {
parentsAndKeys.push(info);
});
var last = parentsAndKeys[parentsAndKeys.length - 1];
var value = last.value;
if (value !== undefined) {
walk(copy, writeParts, function (info, i) {
if (i < writeParts.length - 1 && !info.value) {
return info.parent[info.key] = {};
} else if (i === writeParts.length - 1) {
info.parent[info.key] = value;
}
});
deleteKeys(parentsAndKeys);
}
});
var last = parentsAndKeys[parentsAndKeys.length - 1];
var value = last.value;
if (value !== undefined) {
walk(copy, writeParts, function (info, i) {
if (i < writeParts.length - 1 && !info.value) {
return info.parent[info.key] = {};
} else if (i === writeParts.length - 1) {
info.parent[info.key] = value;
}
});
deleteKeys(parentsAndKeys);
}
});
return copy;
};
return copy;
};
});

@@ -1,17 +0,19 @@

/*can-key@1.1.0#utils*/
'use strict';
var utils = {
isContainer: function (current) {
var type = typeof current;
return current && (type === 'object' || type === 'function');
},
strReplacer: /\{([^\}]+)\}/g,
parts: function (name) {
if (Array.isArray(name)) {
return name;
} else {
return typeof name !== 'undefined' ? (name + '').replace(/\[/g, '.').replace(/]/g, '').split('.') : [];
/*can-key@1.2.0#utils*/
define('can-key/utils', function (require, exports, module) {
'use strict';
var utils = {
isContainer: function (current) {
var type = typeof current;
return current && (type === 'object' || type === 'function');
},
strReplacer: /\{([^\}]+)\}/g,
parts: function (name) {
if (Array.isArray(name)) {
return name;
} else {
return typeof name !== 'undefined' ? (name + '').replace(/\[/g, '.').replace(/]/g, '').split('.') : [];
}
}
}
};
module.exports = utils;
};
module.exports = utils;
});

@@ -1,25 +0,33 @@

/*can-key@1.1.0#walk/walk*/
'use strict';
var canReflect = require('can-reflect');
var utils = require('../utils.js');
module.exports = function walk(obj, name, keyCallback) {
var parts = utils.parts(name);
var length = parts.length, current, i, container, part;
if (!length) {
return;
}
current = obj;
for (i = 0; i < length; i++) {
container = current;
part = parts[i];
current = utils.isContainer(container) && canReflect.getKeyValue(container, part);
var result = keyCallback({
parent: container,
key: part,
value: current
}, i);
if (result !== undefined) {
current = result;
/*can-key@1.2.0#walk/walk*/
define('can-key/walk/walk', [
'require',
'exports',
'module',
'can-reflect',
'can-key/utils'
], function (require, exports, module) {
'use strict';
var canReflect = require('can-reflect');
var utils = require('can-key/utils');
module.exports = function walk(obj, name, keyCallback) {
var parts = utils.parts(name);
var length = parts.length, current, i, container, part;
if (!length) {
return;
}
}
};
current = obj;
for (i = 0; i < length; i++) {
container = current;
part = parts[i];
current = utils.isContainer(container) && canReflect.getKeyValue(container, part);
var result = keyCallback({
parent: container,
key: part,
value: current
}, i);
if (result !== undefined) {
current = result;
}
}
};
});

@@ -109,4 +109,5 @@ /*[process-shim]*/

args[2] = module;
} else if (!args[0] && deps[0] === "exports") {
// Babel uses the exports and module object.
}
// Babel uses the exports and module object.
else if (!args[0] && deps[0] === "exports") {
module = { exports: {} };

@@ -168,3 +169,3 @@ args[0] = module.exports;

/*can-key@1.1.0#utils*/
/*can-key@1.2.0#utils*/
define('can-key/utils', function (require, exports, module) {

@@ -188,3 +189,3 @@ 'use strict';

});
/*can-key@1.1.0#delete/delete*/
/*can-key@1.2.0#delete/delete*/
define('can-key/delete/delete', [

@@ -213,3 +214,3 @@ 'require',

});
/*can-key@1.1.0#get/get*/
/*can-key@1.2.0#get/get*/
define('can-key/get/get', [

@@ -240,3 +241,3 @@ 'require',

});
/*can-key@1.1.0#replace-with/replace-with*/
/*can-key@1.2.0#replace-with/replace-with*/
define('can-key/replace-with/replace-with', [

@@ -264,3 +265,3 @@ 'require',

});
/*can-key@1.1.0#set/set*/
/*can-key@1.2.0#set/set*/
define('can-key/set/set', [

@@ -299,3 +300,3 @@ 'require',

});
/*can-key@1.1.0#walk/walk*/
/*can-key@1.2.0#walk/walk*/
define('can-key/walk/walk', [

@@ -333,3 +334,3 @@ 'require',

});
/*can-key@1.1.0#transform/transform*/
/*can-key@1.2.0#transform/transform*/
define('can-key/transform/transform', [

@@ -380,3 +381,3 @@ 'require',

});
/*can-key@1.1.0#can-key*/
/*can-key@1.2.0#can-key*/
define('can-key', [

@@ -383,0 +384,0 @@ 'require',

{
"name": "can-key",
"version": "1.2.0",
"version": "1.2.1",
"description": "Read nested key values",

@@ -56,8 +56,8 @@ "homepage": "http://canjs.com",

"jshint": "^2.9.1",
"steal": "^1.6.5",
"steal-qunit": "^1.0.1",
"steal-tools": "^1.11.3",
"testee": "^0.7.0"
"steal": "^2.2.1",
"steal-qunit": "^2.0.0",
"steal-tools": "^2.2.1",
"testee": "^0.9.0"
},
"license": "MIT"
}
# can-key
[![Build Status](https://travis-ci.org/canjs/can-key.svg?branch=master)](https://travis-ci.org/canjs/can-key)
[![Join our Slack](https://img.shields.io/badge/slack-join%20chat-611f69.svg)](https://www.bitovi.com/community/slack?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Join our Discourse](https://img.shields.io/discourse/https/forums.bitovi.com/posts.svg)](https://forums.bitovi.com/?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/canjs/can-key/blob/master/LICENSE)
[![npm version](https://badge.fury.io/js/can-key.svg)](https://www.npmjs.com/package/can-key)
[![Travis build status](https://travis-ci.org/canjs/can-key.svg?branch=master)](https://travis-ci.org/canjs/can-key)
[![Greenkeeper badge](https://badges.greenkeeper.io/canjs/can-key.svg)](https://greenkeeper.io/)
Read nested key values
## Documentation
Read the [can-key API docs on CanJS.com](https://canjs.com/doc/can-key.html).
## Changelog
See the [latest releases on GitHub](https://github.com/canjs/can-key/releases).
## Contributing
The [contribution guide](https://github.com/canjs/can-key/blob/master/CONTRIBUTING.md) has information on getting help, reporting bugs, developing locally, and more.
## License
[MIT](https://github.com/canjs/can-key/blob/master/LICENSE)

@@ -24,3 +24,3 @@ var transform = require("./transform");

{ start: 1, end: 2 });
QUnit.deepEqual(source, {page: {start: 1, end: 2}});
assert.deepEqual(source, {page: {start: 1, end: 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