From f98e516343303da1147c8674367f00c1cae58fa3 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Wed, 3 Aug 2016 20:21:23 -0400 Subject: [PATCH] Initial/final commit! --- index.js | 8 ++++++++ package.json | 13 +++++++++++++ test.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 index.js create mode 100644 package.json create mode 100644 test.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..a197790 --- /dev/null +++ b/index.js @@ -0,0 +1,8 @@ +if (typeof module!=='undefined') module.exports = dlv; + +function dlv(obj, key) { + if (key.split) key = key.split('.'); + for (var i=0; i", + "license": "MIT" +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..ff31057 --- /dev/null +++ b/test.js @@ -0,0 +1,33 @@ +var assert = require('assert'); +var dlv = require('.'); + +var obj = { + one: 1, + a: { + two: 2, + b: { + three: 3, + c: { + four: 4 + } + } + } +}; + +function check(path, value) { + assert.equal(dlv(obj, path), value); + console.log(' ✓ dlv(obj, "'+path+'")'); +} + +check('', undefined); +check('one', obj.one); +check('one.two', undefined); +check('a', obj.a); +check('a.two', obj.a.two); +check('a.b', obj.a.b); +check('a.b.three', obj.a.b.three); +check('a.b.c', obj.a.b.c); +check('a.b.c.four', obj.a.b.c.four); + +console.log('✅ Success!'); +process.exit(0);