From dc1a6c70f14e385c0eeabc81bc8235448f281101 Mon Sep 17 00:00:00 2001 From: johnste Date: Sat, 12 Mar 2016 10:30:43 +0100 Subject: [PATCH] Indentation issues --- README.md | 4 ++++ lib/getify.js | 44 ++++++++++++++++++++++---------------------- test/getify.spec.js | 8 ++++---- test/test-main.js | 26 +++++++++++++------------- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 34b5fb2..9f7e0df 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,17 @@ Getify is a utility to grab nested values from objects. Like lodash's `_.get`, o ``` import getify from 'getify' + const obj = { deeply: { nested: ['the', 'values', 'are', 'here'] } } + const value = getify(obj).deeply.nested[1](); // === "values" + const missing = getify(obj).cant['find'].anything.here() // === undefined + const defaultValue = getify(obj).nothing.here.as.well('oops!') // === "oops!" ``` diff --git a/lib/getify.js b/lib/getify.js index 6a40736..47a0910 100644 --- a/lib/getify.js +++ b/lib/getify.js @@ -1,15 +1,15 @@ (function (root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define([], factory); - } else if (typeof module === 'object' && module.exports) { - // Node. Does not work with strict CommonJS, but - // only CommonJS-like environments that support module.exports, - // like Node. - module.exports = factory(); - } else { - // Browser globals (root is window) - root.getify = factory(); + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define([], factory); + } else if (typeof module === 'object' && module.exports) { + // Node. Does not work with strict CommonJS, but + // only CommonJS-like environments that support module.exports, + // like Node. + module.exports = factory(); + } else { + // Browser globals (root is window) + root.getify = factory(); } }(this, function () { @@ -29,14 +29,14 @@ function handler() { return { - get: function(target, key){ - if (typeof key == 'symbol' || key == '__proto__') { - return target[key] - } + get: function(target, key){ + if (typeof key == 'symbol' || key == '__proto__') { + return target[key] + } - path.push(key) - return getProxy(getValueFromPath(obj)) - } + path.push(key) + return getProxy(getValueFromPath(obj)) + } } } @@ -48,8 +48,8 @@ return getProxy(() => obj, path) } - // Just return a value to define the module export. - // This example returns an object, but the module - // can return a function as the exported value. - return getify; + // Just return a value to define the module export. + // This example returns an object, but the module + // can return a function as the exported value. + return getify; })); \ No newline at end of file diff --git a/test/getify.spec.js b/test/getify.spec.js index 1e58dcc..a64412e 100644 --- a/test/getify.spec.js +++ b/test/getify.spec.js @@ -26,10 +26,10 @@ define(['lib/getify'], (getify) => { }, f: [undefined, { g: "321" }] } - expect(getify(obj).a.b(), 'obj.a.b').to.be.undefined - expect(getify(obj).b[4](), 'obj.b[4]').to.be.undefined - expect(getify(obj).d(), 'obj.d').to.be.undefined - expect(getify(obj).f[1].x.x(), 'obj.f[1].x.x').to.be.undefined + expect(getify(obj).a.b(), 'obj.a.b').to.be.undefined + expect(getify(obj).b[4](), 'obj.b[4]').to.be.undefined + expect(getify(obj).d(), 'obj.d').to.be.undefined + expect(getify(obj).f[1].x.x(), 'obj.f[1].x.x').to.be.undefined }) diff --git a/test/test-main.js b/test/test-main.js index c2173ad..d9633dc 100644 --- a/test/test-main.js +++ b/test/test-main.js @@ -3,22 +3,22 @@ var TEST_REGEXP = /(spec|test)\.js$/i; // Get a list of all the test files to include Object.keys(window.__karma__.files).forEach(function(file) { - if (TEST_REGEXP.test(file)) { - // Normalize paths to RequireJS module names. - // If you require sub-dependencies of test files to be loaded as-is (requiring file extension) - // then do not normalize the paths - var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, ''); - allTestFiles.push(normalizedTestModule); - } + if (TEST_REGEXP.test(file)) { + // Normalize paths to RequireJS module names. + // If you require sub-dependencies of test files to be loaded as-is (requiring file extension) + // then do not normalize the paths + var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, ''); + allTestFiles.push(normalizedTestModule); + } }); require.config({ - // Karma serves files under /base, which is the basePath from your config file - baseUrl: '/base', + // Karma serves files under /base, which is the basePath from your config file + baseUrl: '/base', - // dynamically load all test files - deps: allTestFiles, + // dynamically load all test files + deps: allTestFiles, - // we have to kickoff jasmine, as it is asynchronous - callback: window.__karma__.start + // we have to kickoff jasmine, as it is asynchronous + callback: window.__karma__.start });