From a3e843c64e1526c1452c13468dd774564be61785 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Fri, 21 Dec 2018 16:22:54 +0100 Subject: [PATCH] feat(isArrayLike): add support for currying Also make tests consistent with the rest of the codebase --- src/isArrayLike.js | 5 +-- test/isArrayLike.js | 75 +++++++++++++++++++-------------------------- 2 files changed, 35 insertions(+), 45 deletions(-) diff --git a/src/isArrayLike.js b/src/isArrayLike.js index 894d53ef50..4e83e79974 100644 --- a/src/isArrayLike.js +++ b/src/isArrayLike.js @@ -1,4 +1,5 @@ import { has } from 'ramda'; +import curry1 from 'ramda/src/internal/_curry1'; import isArray from './isArray'; import isString from './isString'; @@ -27,7 +28,7 @@ import isString from './isString'; * RA.isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true */ /* eslint-enable max-len */ -const isArrayLike = val => { +const isArrayLike = curry1(val => { if (isArray(val)) { return true; } @@ -50,7 +51,7 @@ const isArrayLike = val => { return has(0, val) && has(val.length - 1, val); } return false; -}; +}); export default isArrayLike; diff --git a/test/isArrayLike.js b/test/isArrayLike.js index 79d5dbe68d..71555a36e1 100644 --- a/test/isArrayLike.js +++ b/test/isArrayLike.js @@ -1,14 +1,16 @@ +import * as R from 'ramda'; + import * as RA from '../src/index'; import eq from './shared/eq'; describe('isArrayLike', function() { - it('is true for Arrays', function() { + it('should return true for Arrays', function() { eq(RA.isArrayLike([]), true); eq(RA.isArrayLike([1, 2, 3, 4]), true); eq(RA.isArrayLike([null]), true); }); - it('is true for arguments', function() { + it('should return true for arguments', function() { function testingFn() { return RA.isArrayLike(arguments); } @@ -17,58 +19,45 @@ describe('isArrayLike', function() { eq(testingFn(null), true); }); - it('is false for Strings', function() { + it('should return false for Strings', function() { eq(RA.isArrayLike(''), false); eq(RA.isArrayLike('abcdefg'), false); }); - it('is true for arbitrary objects with numeric length, if extreme indices are defined', function() { - const obj1 = { length: 0 }; - const obj2 = { 0: 'something', length: 0 }; - const obj3 = { 0: void 0, length: 0 }; - const obj4 = { 0: 'zero', 1: 'one', length: 2 }; - const obj5 = { nodeType: 1, length: 2 }; - const obj6 = { 0: 'zero', length: 2 }; - const obj7 = { 1: 'one', length: 2 }; - - eq(RA.isArrayLike(obj1), true); - eq(RA.isArrayLike(obj2), true); - eq(RA.isArrayLike(obj3), true); - eq(RA.isArrayLike(obj4), true); - eq(RA.isArrayLike(obj5), true); - eq(RA.isArrayLike(obj6), false); - eq(RA.isArrayLike(obj7), false); + context('given extreme indices are defined', function() { + specify( + 'should return true for arbitrary objects with numeric length', + function() { + const obj1 = { length: 0 }; + const obj2 = { 0: 'something', length: 0 }; + const obj3 = { 0: void 0, length: 0 }; + const obj4 = { 0: 'zero', 1: 'one', length: 2 }; + const obj5 = { nodeType: 1, length: 2 }; + const obj6 = { 0: 'zero', length: 2 }; + const obj7 = { 1: 'one', length: 2 }; + + eq(RA.isArrayLike(obj1), true); + eq(RA.isArrayLike(obj2), true); + eq(RA.isArrayLike(obj3), true); + eq(RA.isArrayLike(obj4), true); + eq(RA.isArrayLike(obj5), true); + eq(RA.isArrayLike(obj6), false); + eq(RA.isArrayLike(obj7), false); + } + ); }); - it('is false for everything else', function() { + it('should return false for everything else', function() { eq(RA.isArrayLike(undefined), false); eq(RA.isArrayLike(1), false); eq(RA.isArrayLike({}), false); eq(RA.isArrayLike(false), false); eq(RA.isArrayLike(function() {}), false); }); -}); - -/** - The MIT License (MIT) - Copyright (c) 2013-2016 Scott Sauyet and Michael Hurley + it('should support placeholder to specify "gaps"', function() { + const isArrayLike = RA.isArrayLike(R.__); - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - */ + eq(isArrayLike([]), true); + }); +});