array-hyper-unique
Advanced tools
Comparing version 1.1.0 to 1.1.1
/** | ||
* Created by user on 2018/5/30/030. | ||
*/ | ||
declare function lazy_unique<T extends any[]>(arr: T): T; | ||
declare function lazy_unique<T, T1, T2>(a1: T1, a2: T2, ...arr: T[]): Array<T | T1 | T2>; | ||
declare function lazy_unique<T>(...arr: Array<T | T[]>): T | (T | T[])[]; | ||
declare module lazy_unique { | ||
export function lazy_unique<T extends any[]>(arr: T): T; | ||
export function lazy_unique<T, T1, T2>(a1: T1, a2: T2, ...arr: T[]): Array<T | T1 | T2>; | ||
export function lazy_unique<T>(...arr: Array<T | T[]>): T | (T | T[])[]; | ||
export function array_unique<T>(arr: T, options?: { | ||
checker?(element: T[keyof T], array: T[keyof T], arr_new?: T, arr_old?: T): boolean; | ||
checker?<R>(element: R[keyof R], array: R[keyof R], arr_new?: R, arr_old?: R): boolean; | ||
overwrite?: boolean; | ||
filter?(v: T[keyof T]): boolean; | ||
filter?<R>(v: R[keyof R]): boolean; | ||
}): T; | ||
export function lazy_unique_overwrite<T>(...arr: Array<T | T[]>): T | (T | T[])[]; | ||
export function array_unique_overwrite<T>(arr: T, options?: IOptions<T>): T; | ||
export type IOptions<T> = { | ||
checker?(element: T[keyof T], array: T[keyof T], arr_new?: T, arr_old?: T): boolean; | ||
checker?<R>(element: R[keyof R], array: R[keyof R], arr_new?: R, arr_old?: R): boolean; | ||
overwrite?: boolean; | ||
filter?(v: T[keyof T]): boolean; | ||
filter?<R>(v: R[keyof R]): boolean; | ||
}; | ||
export function defaultFilter<T>(options?: IOptions<T>): <K extends any[]>(val: K[keyof K], index: number, arr: K) => boolean; | ||
export function defaultChecker<T, R>(element: T, value: R, arr_new?: Array<T | R>, arr_old?: Array<T | R>): boolean; | ||
export function equals(a1: any, a2: any): boolean; | ||
export { lazy_unique as default }; | ||
} | ||
export default lazy_unique; | ||
import { lazy_unique } from './core'; | ||
export = lazy_unique; |
96
index.js
@@ -5,96 +5,4 @@ "use strict"; | ||
*/ | ||
/* | ||
function lazy_unique<T>(...arr: Array<T | T[]>) | ||
{ | ||
if (arr.length > 1) | ||
{ | ||
return array_unique(arr); | ||
} | ||
return array_unique(arr[0]); | ||
} | ||
*/ | ||
var lazy_unique; | ||
(function (lazy_unique_1) { | ||
// @ts-ignore | ||
const equals = require('deep-eql'); | ||
// @ts-ignore | ||
function lazy_unique(...arr) { | ||
if (arr.length > 1) { | ||
return array_unique(arr); | ||
} | ||
return array_unique(arr[0]); | ||
} | ||
lazy_unique_1.lazy_unique = lazy_unique; | ||
function array_unique(arr, options = {}) { | ||
if (!Array.isArray(arr)) { | ||
throw new TypeError(`Expected an Array but got ${typeof arr}.`); | ||
} | ||
const cb = defaultFilter(options); | ||
if (options.overwrite) { | ||
let index = arr.length; | ||
while (index--) { | ||
let val = arr[index]; | ||
if (!cb(val, index, arr)) { | ||
arr.splice(index, 1); | ||
} | ||
} | ||
return arr; | ||
} | ||
// @ts-ignore | ||
return arr.filter(cb); | ||
} | ||
lazy_unique_1.array_unique = array_unique; | ||
function lazy_unique_overwrite(...arr) { | ||
if (arr.length > 1) { | ||
return array_unique_overwrite(arr); | ||
} | ||
return array_unique_overwrite(arr[0]); | ||
} | ||
lazy_unique_1.lazy_unique_overwrite = lazy_unique_overwrite; | ||
function array_unique_overwrite(arr, options = {}) { | ||
let opts = Object.assign({}, options, { | ||
overwrite: true, | ||
}); | ||
return array_unique(arr, opts); | ||
} | ||
lazy_unique_1.array_unique_overwrite = array_unique_overwrite; | ||
function defaultFilter(options = {}) { | ||
const checker = options.checker || defaultChecker; | ||
const filter = options.filter || null; | ||
const cb = (val, index, arr) => { | ||
let i = arr.findIndex(a => checker(a, val, arr, arr)); | ||
return i == index && (!filter || filter(val)); | ||
}; | ||
return cb; | ||
} | ||
lazy_unique_1.defaultFilter = defaultFilter; | ||
function defaultChecker(element, value, arr_new, arr_old) { | ||
return equals(element, value); | ||
} | ||
lazy_unique_1.defaultChecker = defaultChecker; | ||
})(lazy_unique || (lazy_unique = {})); | ||
// @ts-ignore | ||
lazy_unique = lazy_unique.lazy_unique = Object.assign(lazy_unique.lazy_unique, lazy_unique, exports, { | ||
// @ts-ignore | ||
equals: require('deep-eql'), | ||
default: lazy_unique.lazy_unique, | ||
}); | ||
// @ts-ignore | ||
exports.default = lazy_unique; | ||
// @ts-ignore | ||
Object.defineProperty(lazy_unique, "__esModule", { value: true }); | ||
// @ts-ignore | ||
Object.keys(lazy_unique).forEach((k) => { | ||
try { | ||
// @ts-ignore | ||
lazy_unique[k] = Object.freeze(lazy_unique[k]); | ||
} | ||
catch (e) { | ||
} | ||
}); | ||
// @ts-ignore | ||
lazy_unique = Object.freeze(lazy_unique); | ||
module.exports = lazy_unique; | ||
//export = lazy_unique; | ||
const core_1 = require("./core"); | ||
module.exports = core_1.lazy_unique; | ||
//# sourceMappingURL=index.js.map |
@@ -13,2 +13,3 @@ ``` | ||
[FAIL] lodash.uniq | ||
[FAIL] lodash/uniq | ||
@@ -27,2 +28,3 @@ | ||
[FAIL] lodash.uniq | ||
[FAIL] lodash/uniq | ||
@@ -41,2 +43,3 @@ | ||
[SUCCESS] lodash.uniq | ||
[SUCCESS] lodash/uniq | ||
@@ -55,2 +58,3 @@ | ||
[SUCCESS] lodash.uniq | ||
[SUCCESS] lodash/uniq | ||
@@ -69,2 +73,3 @@ | ||
[SUCCESS] lodash.uniq | ||
[SUCCESS] lodash/uniq | ||
@@ -83,2 +88,3 @@ | ||
[FAIL] lodash.uniq | ||
[FAIL] lodash/uniq | ||
@@ -97,2 +103,3 @@ | ||
[FAIL] lodash.uniq | ||
[FAIL] lodash/uniq | ||
@@ -111,2 +118,3 @@ | ||
[SUCCESS] lodash.uniq | ||
[SUCCESS] lodash/uniq | ||
@@ -125,2 +133,3 @@ | ||
[SUCCESS] lodash.uniq | ||
[SUCCESS] lodash/uniq | ||
@@ -139,2 +148,3 @@ | ||
[FAIL] lodash.uniq | ||
[FAIL] lodash/uniq | ||
@@ -153,2 +163,3 @@ | ||
[SUCCESS] lodash.uniq | ||
[SUCCESS] lodash/uniq | ||
@@ -167,2 +178,3 @@ | ||
[FAIL] lodash.uniq | ||
[FAIL] lodash/uniq | ||
@@ -181,2 +193,3 @@ | ||
[FAIL] lodash.uniq | ||
[FAIL] lodash/uniq | ||
@@ -195,2 +208,3 @@ | ||
[SUCCESS] lodash.uniq | ||
[SUCCESS] lodash/uniq | ||
@@ -209,2 +223,3 @@ | ||
[FAIL] lodash.uniq | ||
[FAIL] lodash/uniq | ||
@@ -224,2 +239,3 @@ | ||
'lodash.uniq': { success: 7, fail: 8, error: 0 }, | ||
'lodash/uniq': { success: 7, fail: 8, error: 0 }, | ||
'array-unique': { success: 6, fail: 9, error: 0 }, | ||
@@ -226,0 +242,0 @@ '@arr/unique': { success: 6, fail: 9, error: 0 }, |
{ | ||
"name": "array-hyper-unique", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Get unique values of an array. Really, like deeply unique.", | ||
@@ -43,3 +43,3 @@ "keywords": [ | ||
"license": "ISC", | ||
"author": "", | ||
"author": "bluelovers", | ||
"main": "index.js", | ||
@@ -50,11 +50,13 @@ "directories": { | ||
"scripts": { | ||
"build:lib:chk": "ts-node test/lib.chk", | ||
"coverage": "npx nyc yarn run test", | ||
"lint": "npx eslint **/*.ts", | ||
"test": "jest", | ||
"build:lib:chk": "ts-node test/lib.chk", | ||
"npm:publish": "npm publish", | ||
"npm:publish:lerna": "npx lerna publish --yes --cd-version patch", | ||
"prepublish:lockfile": "npx sync-lockfile .", | ||
"prepublishOnly": "yarn run test && yarn run build:lib:chk", | ||
"postpublish": "git commit -m \"chore(release): publish\" .", | ||
"ncu": "npx yarn-tool ncu -u", | ||
"npm:publish": "npm publish", | ||
"prepublishOnly": "yarn run ncu && yarn run sort-package-json && yarn run test && yarn run build:lib:chk", | ||
"postpublish": "echo postpublish & git commit -m \"publish new version\" .", | ||
"sort-package-json": "npx sort-package-json ./package.json", | ||
"test": "npx -r chai -r mocha -r ts-node mocha --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"", | ||
"sort-package-json": "npx yarn-tool sort", | ||
"tsc:default": "tsc -p tsconfig.json", | ||
@@ -67,5 +69,9 @@ "tsc:esm": "tsc -p tsconfig.esm.json" | ||
"devDependencies": { | ||
"@arr/unique": "^1.0.0", | ||
"@bluelovers/tsconfig": "^1.0.12", | ||
"@types/node": "^12.6.8", | ||
"@arr/unique": "^1.0.1", | ||
"@bluelovers/tsconfig": "^1.0.19", | ||
"@types/array-unique": "^0.3.0", | ||
"@types/jest": "^25.2.3", | ||
"@types/lodash": "^4.14.155", | ||
"@types/lodash.uniq": "^4.5.6", | ||
"@types/node": "^14.0.11", | ||
"arr-unique": "^1.0.2", | ||
@@ -75,8 +81,11 @@ "array-uniq": "^2.1.0", | ||
"array-unique-deep": "^1.0.1", | ||
"debug-color2": "^1.1.6", | ||
"debug-color2": "^1.1.7", | ||
"jest": "^26.0.1", | ||
"just-unique": "^3.2.0", | ||
"lodash": "^4.17.15", | ||
"lodash.uniq": "^4.5.0", | ||
"strip-ansi": "^5.2.0", | ||
"tfk-unique-array": "^2.0.0" | ||
"strip-ansi": "^6.0.0", | ||
"tfk-unique-array": "^2.0.0", | ||
"ts-jest": "^26.1.0" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
26611
15
156
0
19
1