dottie
Advanced tools
Comparing version 0.0.8-0 to 0.0.9-0
(function(undefined) { | ||
var root = this; | ||
// Weird IE shit, objects do not have hasOwn, but the prototype does... | ||
var hasOwnProp = Object.prototype.hasOwnProperty; | ||
// Object cloning function, uses jQuery/Underscore/Object.create depending on what's available | ||
var clone = function (object) { | ||
if (typeof Object.hasOwnProperty !== 'undefined') { | ||
var target = {}; | ||
for (var i in object) { | ||
if (object.hasOwnProperty(i)) { | ||
target[i] = object[i]; | ||
} | ||
} | ||
return target; | ||
} | ||
if (typeof jQuery !== 'undefined') { | ||
return jQuery.extend({}, object); | ||
} | ||
if (typeof _ !== 'undefined') { | ||
return _.extend({}, object); | ||
} | ||
}; | ||
var clone = function (object) { | ||
if (typeof Object.hasOwnProperty !== 'undefined') { | ||
var target = {}; | ||
for (var i in object) { | ||
if (hasOwnProp.call(object, i)) { | ||
target[i] = object[i]; | ||
} | ||
} | ||
return target; | ||
} | ||
if (typeof jQuery !== 'undefined') { | ||
return jQuery.extend({}, object); | ||
} | ||
if (typeof _ !== 'undefined') { | ||
return _.extend({}, object); | ||
} | ||
}; | ||
// Weird IE shit, objects do not have hasOwn, but the prototype does... | ||
var hasOwnProp = Object.prototype.hasOwnProperty; | ||
var Dot = function() { | ||
var Dottie = function() { | ||
var args = Array.prototype.slice.call(arguments); | ||
if (args.length == 2) { | ||
return Dot.find.apply(this, args); | ||
return Dottie.find.apply(this, args); | ||
} | ||
return Dot.transform.apply(this, args); | ||
return Dottie.transform.apply(this, args); | ||
}; | ||
// Legacy syntax, changed syntax to have get/set be similar in arg order | ||
Dot.find = function(path, object) { | ||
return Dot.get(object, path); | ||
Dottie.find = function(path, object) { | ||
return Dottie.get(object, path); | ||
}; | ||
// Traverse object according to path, return value if found - Return undefined if destination is unreachable | ||
Dot.get = function(object, path) { | ||
Dottie.get = function(object, path) { | ||
var pieces = path.split('.'), current = object, piece; | ||
@@ -63,3 +63,3 @@ | ||
// Set nested value | ||
Dot.set = function(object, path, value) { | ||
Dottie.set = function(object, path, value) { | ||
var pieces = path.split('.'), current = object, piece, length = pieces.length; | ||
@@ -86,5 +86,5 @@ | ||
// Set default nested value | ||
Dot['default'] = function(object, path, value) { | ||
if (Dot.get(object, path) === undefined) { | ||
Dot.set(object, path, value); | ||
Dottie['default'] = function(object, path, value) { | ||
if (Dottie.get(object, path) === undefined) { | ||
Dottie.set(object, path, value); | ||
} | ||
@@ -94,3 +94,3 @@ }; | ||
// Transform unnested object with .-seperated keys into a nested object. | ||
Dot.transform = function(object) { | ||
Dottie.transform = function(object) { | ||
var pieces, piecesLength, current, transformed = clone(object), piece; | ||
@@ -123,11 +123,36 @@ for (var key in transformed) { | ||
Dottie.flatten = function(object, seperator) { | ||
if (typeof seperator === "undefined") seperator = '.'; | ||
var flattened = {}, | ||
current, | ||
nested; | ||
for (var key in object) { | ||
if (hasOwnProp.call(object, key)) { | ||
current = object[key]; | ||
if (current === Object(current)) { | ||
nested = Dottie.flatten(current, seperator); | ||
for (var _key in nested) { | ||
flattened[key+seperator+_key] = nested[_key]; | ||
} | ||
} else { | ||
flattened[key] = current; | ||
} | ||
} | ||
} | ||
return flattened; | ||
} | ||
if (typeof module !== 'undefined' && module.exports) { | ||
exports = module.exports = Dot; | ||
exports = module.exports = Dottie; | ||
} else { | ||
root['Dot'] = Dot; | ||
root['Dottie'] = Dottie; | ||
root['Dot'] = Dottie; //BC | ||
if (typeof define === "function") { | ||
define([], function () { return Dot; }); | ||
define([], function () { return Dottie; }); | ||
} | ||
} | ||
})(); |
{ | ||
"name": "dottie", | ||
"version": "0.0.8-0", | ||
"version": "0.0.9-0", | ||
"devDependencies": { | ||
"buster": "*" | ||
"expect.js": "~0.2.0", | ||
"mocha": "~1.14.0" | ||
}, | ||
"description": "Object traversing/manipulation util", | ||
"author": "Mick Hansen <mh@innofluence.com>", | ||
"author": "Mick Hansen <maker@mhansen.io>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/innofluence/dottie.js.git" | ||
"url": "git://github.com/greenwoodio/dottie.js.git" | ||
}, | ||
"main": "dottie.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/buster-test" | ||
"test": "./node_modules/mocha/bin/mocha -t 5000 -s 100 --reporter spec test/" | ||
} | ||
} |
@@ -1,6 +0,4 @@ | ||
var buster = require('buster'), | ||
var expect = require("expect.js"), | ||
dottie = require('../dottie'); | ||
buster.spec.expose(); | ||
describe("dottie.find", function () { | ||
@@ -15,8 +13,8 @@ var data = { | ||
it("should get first-level values", function () { | ||
expect(dottie.find('zoo', data)).toEqual('lander'); | ||
expect(dottie.find('zoo', data)).to.equal('lander'); | ||
}); | ||
it("should get nested-level values", function () { | ||
expect(dottie.find('foo.bar', data)).toEqual('baz'); | ||
expect(dottie.find('foo.bar', data)).to.equal('baz'); | ||
}); | ||
}); |
@@ -1,6 +0,4 @@ | ||
var buster = require('buster'), | ||
var expect = require("expect.js"), | ||
dottie = require('../dottie'); | ||
buster.spec.expose(); | ||
describe("dottie.get", function () { | ||
@@ -18,16 +16,16 @@ var data = { | ||
it("should get first-level values", function () { | ||
expect(dottie.get(data, 'zoo')).toEqual('lander'); | ||
expect(dottie.get(data, 'zoo')).to.equal('lander'); | ||
}); | ||
it("should get nested-level values", function () { | ||
expect(dottie.get(data, 'foo.bar')).toEqual('baz'); | ||
expect(dottie.get(data, 'foo.bar')).to.equal('baz'); | ||
}); | ||
it("should return undefined if not found", function () { | ||
expect(dottie.get(data, 'foo.zoo.lander')).toEqual(undefined); | ||
expect(dottie.get(data, 'foo.zoo.lander')).to.equal(undefined); | ||
}); | ||
it("should return false values properly", function () { | ||
expect(dottie.get(data, 'false.value')).toEqual(false); | ||
expect(dottie.get(data, 'false.value')).to.equal(false); | ||
}); | ||
}); |
@@ -1,6 +0,4 @@ | ||
var buster = require('buster'), | ||
var expect = require("expect.js"), | ||
dottie = require('../dottie'); | ||
buster.spec.expose(); | ||
describe("dottie.set", function () { | ||
@@ -15,3 +13,3 @@ var data = { | ||
dottie.set(data, 'foo.bar', 'baz'); | ||
expect(data.foo.bar).toEqual('baz'); | ||
expect(data.foo.bar).to.equal('baz'); | ||
}); | ||
@@ -21,4 +19,4 @@ | ||
dottie.set(data, 'level1.level2', 'foo'); | ||
expect(data.level1.level2).toEqual('foo'); | ||
expect(typeof data.level1).toEqual('object'); | ||
expect(data.level1.level2).to.equal('foo'); | ||
expect(typeof data.level1).to.equal('object'); | ||
}); | ||
@@ -32,3 +30,3 @@ | ||
dottie.set(data, 'values.level1', 'foo'); | ||
expect(data.values.level1).toEqual('foo'); | ||
expect(data.values.level1).to.equal('foo'); | ||
}); | ||
@@ -39,4 +37,4 @@ | ||
dottie.set(data, 'foo.bar.baz', 'someValue'); | ||
}).toThrow(); | ||
}).to.throwError(); | ||
}); | ||
}); |
@@ -1,6 +0,4 @@ | ||
var buster = require('buster'), | ||
var expect = require("expect.js"), | ||
dottie = require('../dottie'); | ||
buster.spec.expose(); | ||
describe("dottie.transform", function () { | ||
@@ -17,10 +15,10 @@ it("should create a properly nested object from a basic dottie notated set of keys", function () { | ||
expect(transformed.user).toBeDefined(); | ||
expect(transformed.user.location).toBeDefined(); | ||
expect(transformed.user).not.to.be(undefined); | ||
expect(transformed.user.location).not.to.be(undefined); | ||
expect(transformed.user).toBeObject(); | ||
expect(transformed.user.location).toBeObject(); | ||
expect(transformed.user).to.be.an('object'); | ||
expect(transformed.user.location).to.be.an('object'); | ||
expect(transformed.user.email).toEqual('jd@foobar.com'); | ||
expect(transformed.user.location.city).toEqual('Zanzibar City'); | ||
expect(transformed.user.email).to.equal('jd@foobar.com'); | ||
expect(transformed.user.location.city).to.equal('Zanzibar City'); | ||
}); | ||
@@ -41,13 +39,13 @@ | ||
expect(transformed.user).toBeDefined(); | ||
expect(transformed.user.location).toBeDefined(); | ||
expect(transformed.project).toBeDefined(); | ||
expect(transformed.user).not.to.be(undefined); | ||
expect(transformed.user.location).not.to.be(undefined); | ||
expect(transformed.project).not.to.be(undefined); | ||
expect(transformed.user).toBeObject(); | ||
expect(transformed.user.location).toBeObject(); | ||
expect(transformed.project).toBeObject(); | ||
expect(transformed.user).to.be.an('object'); | ||
expect(transformed.user.location).to.be.an('object'); | ||
expect(transformed.project).to.be.an('object'); | ||
expect(transformed.user.email).toEqual('jd@foobar.com'); | ||
expect(transformed.user.location.city).toEqual('Zanzibar City'); | ||
expect(transformed.project.title).toEqual('dottie'); | ||
expect(transformed.user.email).to.equal('jd@foobar.com'); | ||
expect(transformed.user.location.city).to.equal('Zanzibar City'); | ||
expect(transformed.project.title).to.equal('dottie'); | ||
}); | ||
@@ -64,12 +62,12 @@ | ||
expect(transformed.client).toBeDefined(); | ||
expect(transformed.hasOwnProperty('client')).toBeTruthy(); // Ensure that the property is actually on the object itself, not on the prototype. | ||
expect(transformed.customer).toBeDefined(); | ||
expect(transformed.client).not.to.be(undefined); | ||
expect(transformed.hasOwnProperty('client')).to.be.ok(); // Ensure that the property is actually on the object itself, not on the prototype. | ||
expect(transformed.customer).not.to.be(undefined); | ||
expect(transformed.customer).toBeObject(); | ||
expect(transformed.customer).to.be.an('object'); | ||
expect(transformed.client).toEqual('Lolcat'); | ||
expect(transformed.customer.name).toEqual('John Doe'); | ||
expect(transformed.customer.age).toEqual(15); | ||
expect(transformed.client).to.equal('Lolcat'); | ||
expect(transformed.customer.name).to.equal('John Doe'); | ||
expect(transformed.customer.age).to.equal(15); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
10847
287
0
2