array-hyper-unique
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -1,26 +0,33 @@ | ||
export declare function lazy_unique<T extends any[]>(arr: T): T; | ||
export declare function lazy_unique<T, T1, T2>(a1: T1, a2: T2, ...arr: T[]): Array<T | T1 | T2>; | ||
export declare function lazy_unique<T>(...arr: Array<T | T[]>): T | (T | T[])[]; | ||
export declare 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 declare function lazy_unique_overwrite<T>(...arr: Array<T | T[]>): T | (T | T[])[]; | ||
export declare function array_unique_overwrite<T>(arr: T, options?: IOptions<T>): T; | ||
export declare 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 declare function defaultFilter<T>(options?: IOptions<T>): <K extends any[]>(val: K[keyof K], index: number, arr: K) => boolean; | ||
export declare function defaultChecker<T, R>(element: T, value: R, arr_new?: Array<T | R>, arr_old?: Array<T | R>): boolean; | ||
export declare function equals(a1: any, a2: any): boolean; | ||
/** | ||
* 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; | ||
export declare namespace lazy_unique { | ||
} | ||
export = lazy_unique; |
128
index.js
"use strict"; | ||
const equals = require("deep-eql"); | ||
function lazy_unique(...arr) { | ||
if (arr.length > 1) { | ||
/** | ||
* Created by user on 2018/5/30/030. | ||
*/ | ||
/* | ||
function lazy_unique<T>(...arr: Array<T | T[]>) | ||
{ | ||
if (arr.length > 1) | ||
{ | ||
return array_unique(arr); | ||
} | ||
return array_unique(arr[0]); | ||
} | ||
function array_unique(arr, options = {}) { | ||
if (!Array.isArray(arr)) { | ||
throw new TypeError(`Expected an Array but got ${typeof arr}.`); | ||
*/ | ||
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]); | ||
} | ||
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); | ||
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; | ||
} | ||
return arr; | ||
// @ts-ignore | ||
return arr.filter(cb); | ||
} | ||
return arr.filter(cb); | ||
} | ||
function lazy_unique_overwrite(...arr) { | ||
if (arr.length > 1) { | ||
return array_unique_overwrite(arr); | ||
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]); | ||
} | ||
return array_unique_overwrite(arr[0]); | ||
} | ||
function array_unique_overwrite(arr, options = {}) { | ||
let opts = Object.assign({}, options, { | ||
overwrite: true, | ||
}); | ||
return array_unique(arr, opts); | ||
} | ||
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; | ||
} | ||
function defaultChecker(element, value, arr_new, arr_old) { | ||
return equals(element, value); | ||
} | ||
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, | ||
}); | ||
// @ts-ignore | ||
exports.default = lazy_unique; | ||
(function (lazy_unique_1) { | ||
})(lazy_unique = lazy_unique || (lazy_unique = {})); | ||
// @ts-ignore | ||
Object.defineProperty(lazy_unique, "__esModule", { value: true }); | ||
Object.assign(lazy_unique, exports, { | ||
lazy_unique, | ||
array_unique, | ||
lazy_unique_overwrite, | ||
array_unique_overwrite, | ||
defaultChecker, | ||
defaultFilter, | ||
equals, | ||
default: lazy_unique, | ||
}); | ||
Object.freeze(lazy_unique); | ||
// @ts-ignore | ||
lazy_unique = Object.freeze(lazy_unique); | ||
module.exports = lazy_unique; | ||
//export = lazy_unique; |
{ | ||
"name": "array-hyper-unique", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Get unique values of an array. Really, like deeply unique.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
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
10702
121