Socket
Socket
Sign inDemoInstall

obj-case

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

obj-case - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

7

component.json

@@ -5,6 +5,5 @@ {

"description": "Work with objects of different cased keys",
"version": "0.0.11",
"version": "0.2.0",
"keywords": [],
"dependencies": {
},
"dependencies": {},
"development": {

@@ -21,2 +20,2 @@ "visionmedia/mocha-matrix": "*",

]
}
}
0.2.0 / 2014-12-15
==================
* Fix `find` export
* Allow user to pass `options` parameter, letting you customize the normalizer
0.1.1 / 2014-09-09

@@ -3,0 +9,0 @@ ==================

@@ -9,3 +9,4 @@

module.exports = module.exports.find = multiple(find);
module.exports = multiple(find);
module.exports.find = module.exports;

@@ -17,4 +18,4 @@

module.exports.replace = function (obj, key, val) {
multiple(replace).apply(this, arguments);
module.exports.replace = function (obj, key, val, options) {
multiple(replace).call(this, obj, key, val, options);
return obj;

@@ -28,4 +29,4 @@ };

module.exports.del = function (obj, key) {
multiple(del).apply(this, arguments);
module.exports.del = function (obj, key, options) {
multiple(del).call(this, obj, key, null, options);
return obj;

@@ -40,3 +41,4 @@ };

function multiple (fn) {
return function (obj, path, val) {
return function (obj, path, val, options) {
normalize = options && isFunction(options.normalizer) ? options.normalizer : defaultNormalize;
path = normalize(path);

@@ -134,3 +136,3 @@

* Normalize a `dot.separated.path`.
*
*
* A.HELL(!*&#(!)O_WOR LD.bar => ahelloworldbar

@@ -142,4 +144,15 @@ *

function normalize(path) {
function defaultNormalize(path) {
return path.replace(/[^a-zA-Z0-9\.]+/g, '').toLowerCase();
}
}
/**
* Check if a value is a function.
*
* @param {*} val
* @return {boolean} Returns `true` if `val` is a function, otherwise `false`.
*/
function isFunction(val) {
return typeof val === 'function';
}
{
"name": "obj-case",
"version": "0.1.1",
"version": "0.2.0",
"description": "Work with objects of different cased keys",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -26,3 +26,3 @@

### .del(obj, key)
### .del(obj, key, val, [options])

@@ -38,3 +38,3 @@ Deletes a nested key

### .replace(obj, key)
### .replace(obj, key, val, [options])

@@ -41,0 +41,0 @@ Replaces a nested key

@@ -8,2 +8,10 @@

describe('.find()', function () {
it('should be a function', function () {
objCase.find.should.be.a.Function;
});
it('should be the main export', function () {
objCase.find.should.eql(objCase);
});
it('should find simple keys', function () {

@@ -124,5 +132,18 @@ expect(objCase({ a : 'b' }, 'a')).to.eql('b');

});
});
it('should accept a custom key normalizer', function () {
var obj = { one: { a: { b: 'nested' } }, two: 'two' };
var normalize = function(path) {
return path.replace(/[x]/g, '');
};
var options = { normalizer: normalize };
var expected = {
one: { a: {} },
two: 'two'
};
expect(objCase.del(obj, 'xxonxe.xa.xxbxx', options)).to.eql(expected);
});
});
describe('.replace()', function () {

@@ -143,2 +164,16 @@ it('should replace simple keys', function () {

});
it('should accept a custom key normalizer', function () {
var obj = { one: { a: { b: 'nested' } }, two: 'two' };
var normalize = function(path) {
return path.replace(/[x]/g, '');
};
var options = { normalizer: normalize };
var expected = {
one: { a: { b: 'newvalue' } },
two: 'two'
};
expect(objCase.replace(obj, 'xxonxe.xa.xxbxx', 'newvalue', options)).to.eql(expected);
});
});

@@ -145,0 +180,0 @@

Sorry, the diff of this file is not supported yet

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