From 1ce4d7793358b7c7d7019e4365864a6b2dd8673d Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 9 Jan 2020 22:21:48 +0800 Subject: [PATCH] fix: only run `sortArray` on `string[]` (#136) --- index.js | 6 ++++-- package-lock.json | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index df6ceee4..933ac635 100644 --- a/index.js +++ b/index.js @@ -7,8 +7,10 @@ const hasOwnProperty = (object, property) => Object.prototype.hasOwnProperty.call(object, property) const pipe = fns => x => fns.reduce((result, fn) => fn(result), x) const onArray = fn => x => (Array.isArray(x) ? fn(x) : x) -const uniq = onArray(xs => xs.filter((x, i) => i === xs.indexOf(x))) -const sortArray = onArray(array => [...array].sort()) +const onStringArray = fn => x => + Array.isArray(x) && x.every(item => typeof item === 'string') ? fn(x) : x +const uniq = onStringArray(xs => xs.filter((x, i) => i === xs.indexOf(x))) +const sortArray = onStringArray(array => [...array].sort()) const uniqAndSortArray = pipe([uniq, sortArray]) const isPlainObject = x => x && Object.prototype.toString.call(x) === '[object Object]' diff --git a/package-lock.json b/package-lock.json index b4655e79..315d7cb0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4584,7 +4584,7 @@ }, "is-obj": { "version": "1.0.1", - "resolved": "http://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz", "integrity": "sha1-PkcprB9f3gJc19g6iW2rn09n2w8=", "dev": true }, @@ -9231,7 +9231,7 @@ "dependencies": { "minimist": { "version": "0.0.10", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", "dev": true }