diff --git a/README.md b/README.md index 2efb6072..03f026be 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ You are welcome to contribute with more items provided below. * If you are targeting legacy JavaScript engine with those ES5 methods, you can use [es5-shim](https://github.com/es-shims/es5-shim) -* Please note that, the examples used below are just showing you the native alternative of performing certain tasks. For some of the functions, Lodash provides you more options than native built-ins. This list is not a 1:1 comparison. +* Please note that, the examples used below are just showing you the native alternative of performing certain tasks. For some functions, Lodash provides you more options than native built-ins. This list is not a 1:1 comparison. * Please send a PR if you want to add or modify the code. No need to open an issue unless it's something big and you want to discuss. @@ -1028,7 +1028,7 @@ Returns everything but the last entry of the array. Pass n to exclude the last n // Native var array = [5, 4, 3, 2, 1] - console.log(array.slice(0, -2);); + console.log(array.slice(0, -2)); // output: [5, 4, 3] ``` @@ -1273,9 +1273,9 @@ Creates an object composed of keys generated from the results of running each el // Lodash console.log(_.keyBy(['a', 'b', 'c'])) // output: { a: 'a', b: 'b', c: 'c' } - console.log(_.keyBy([{ id: 'a1', title: 'abc' }, { id: 'b2', title: 'def' }], 'id') + console.log(_.keyBy([{ id: 'a1', title: 'abc' }, { id: 'b2', title: 'def' }], 'id')) // output: { a1: { id: 'a1', title: 'abc' }, b2: { id: 'b2', title: 'def' } } - console.log(_.keyBy({ data: { id: 'a1', title: 'abc' }}, 'id') + console.log(_.keyBy({ data: { id: 'a1', title: 'abc' }}, 'id')) // output: { a1: { id: 'a1', title: 'abc' }} // keyBy for array only @@ -1284,9 +1284,9 @@ Creates an object composed of keys generated from the results of running each el // Native console.log(keyBy(['a', 'b', 'c'])) // output: { a: 'a', b: 'b', c: 'c' } - console.log(keyBy([{ id: 'a1', title: 'abc' }, { id: 'b2', title: 'def' }], 'id') + console.log(keyBy([{ id: 'a1', title: 'abc' }, { id: 'b2', title: 'def' }], 'id')) // output: { a1: { id: 'a1', title: 'abc' }, b2: { id: 'b2', title: 'def' } } - console.log(keyBy(Object.values({ data: { id: 'a1', title: 'abc' }}), 'id') + console.log(keyBy(Object.values({ data: { id: 'a1', title: 'abc' }}), 'id')) // output: { a1: { id: 'a1', title: 'abc' }} // keyBy for array and object @@ -1983,29 +1983,29 @@ Checks if value is an empty object or collection. ```js // Lodash - console.log(_.isEmpty(null) + console.log(_.isEmpty(null)) // output: true - console.log(_.isEmpty('') + console.log(_.isEmpty('')) // output: true - console.log(_.isEmpty({}) + console.log(_.isEmpty({})) // output: true - console.log(_.isEmpty([]) + console.log(_.isEmpty([])) // output: true - console.log(_.isEmpty({a: '1'}) + console.log(_.isEmpty({a: '1'})) // output: false // Native const isEmpty = obj => [Object, Array].includes((obj || {}).constructor) && !Object.entries((obj || {})).length; - console.log(isEmpty(null) + console.log(isEmpty(null)) // output: true - console.log(isEmpty('') + console.log(isEmpty('')) // output: true - console.log(isEmpty({}) + console.log(isEmpty({})) // output: true - console.log(isEmpty([]) + console.log(isEmpty([])) // output: true - console.log(isEmpty({a: '1'}) + console.log(isEmpty({a: '1'})) // output: false ``` @@ -2332,7 +2332,7 @@ Checks if `key` is a direct property of `object`. Key may be a path of a value s ### _.get Gets the value at path of object. -*Note: If provided path does not exists inside the object js will generate error.* +*Note: If provided path does not exist inside the object js will generate error.* ```js // Lodash diff --git a/tests/lib/rules/all.js b/tests/lib/rules/all.js index f02761f3..d2a93cbf 100644 --- a/tests/lib/rules/all.js +++ b/tests/lib/rules/all.js @@ -8,7 +8,7 @@ const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018, sourceType: "module" } }); -// Only a couple of smoke tests because otherwise it would get very reduntant +// Only a couple of smoke tests because otherwise it would get very redundant ruleTester.run('_.concat', rules.concat, { valid: [ diff --git a/tests/unit/all.js b/tests/unit/all.js index 00f3d768..f58f7e38 100644 --- a/tests/unit/all.js +++ b/tests/unit/all.js @@ -15,8 +15,8 @@ describe('code snippet example', () => { const lodashArray = [1] const lodashResult = _.concat(lodashArray, 2, [3], [[4]]) - const nativehArray = [1] - const nativeResult = nativehArray.concat(2, [3], [[4]]) + const nativeArray = [1] + const nativeResult = nativeArray.concat(2, [3], [[4]]) assert.deepEqual(lodashResult, nativeResult) }) @@ -255,7 +255,7 @@ describe('code snippet example', () => { "kk.ll": { "mm.n": [3, 4, { "oo.p": 5 }] } }; - it ("should handle falsey values", () => { + it ("should handle falsy values", () => { var val = _.get(obj, 'aa[0].b.c', 1) assert.strictEqual(val, get(obj, 'aa[0].b.c', 1)) assert.notEqual(val, 1) @@ -354,49 +354,49 @@ describe('code snippet example', () => { } return (num >= Math.min(init, final) && num < Math.max(init, final)); } - + it('_.inRange(3, 2, 4)', () => { assert.equal( _.inRange(3, 2, 4), inRange(3, 2, 4) ) }); - + it('_.inRange(4, 8)', () => { assert.equal( _.inRange(4, 8), inRange(4, 8) ) }); - + it('_.inRange(4, 2)', () => { assert.equal( _.inRange(4, 2), inRange(4, 2) ) }); - + it('_.inRange(2, 2)', () => { assert.equal( _.inRange(2, 2), inRange(2, 2) ) }); - + it('_.inRange(1.2, 2)', () => { assert.equal( _.inRange(1.2, 2), inRange(1.2, 2) ) }); - + it('_.inRange(5.2, 4)', () => { assert.equal( _.inRange(5.2, 4), inRange(5.2, 4) ) }); - + it('_.inRange(-3, -2, -6)', () => { assert.equal( _.inRange(-3, -2, -6), @@ -574,11 +574,11 @@ describe('code snippet example', () => { assert.deepStrictEqual(randoms, [100000, 100001]); }); }); - + describe('clamp', () => { const clamp = (number, boundOne, boundTwo) => { if (!boundTwo) { - return Math.max(number, boundOne) === boundOne ? number : boundOne; + return Math.max(number, boundOne) === boundOne ? number : boundOne; } else if (Math.min(number, boundOne) === number) { return boundOne; } else if (Math.max(number, boundTwo) === number) { @@ -683,7 +683,7 @@ describe('code snippet example', () => { describe('isUndefined', () => { const definedVariable = 1; //defined variable (will return false) let undefinedVariable; //undefined variable (will return true) - + it('_.isUndefined(definedVariable)', () => { assert.equal(_.isUndefined(definedVariable), (definedVariable === undefined)) @@ -725,7 +725,7 @@ describe('code snippet example', () => { describe('forEach', () => { it('_.forEach(array)', () => { const testArray = [1,2,3,4]; - + let lodashOutput = [] let nativeOutput = [] @@ -828,13 +828,9 @@ describe('code snippet example', () => { }); }) - describe('isFunction', () => { function isFunction(func) { - if (func && typeof func === "function") { - return true - } - return false + return (func && typeof func === "function") } it('_.isFunction(setTimeout)', () => { @@ -852,6 +848,5 @@ describe('code snippet example', () => { isFunction("abc")) }); - }); });