JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 141684
  • Score
    100M100P100Q168046F
  • License ISC

Get unique values of an array. Really, like deeply unique.

Package Exports

  • array-hyper-unique

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (array-hyper-unique) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

array-hyper-unique

Get unique values of an array. Really, like deeply unique.

API

  1. this module base on arr-unique
  2. but rewrite to typescript and bug fix
  3. also add option control
  4. see _data.ts and test.test.ts

demo

demo.ts

import { array_unique, default as lazy_unique } from 'array-hyper-unique';

_testIt([
        1,
        0,
        true,
        undefined,
        null,
        false,
        ['a', 'b', 'c'],
        ['a', 'b', 'c'],
        ['a', 'c', 'b'],
        { a: { b: 2 } },
        { a: { b: 2 } },
        { a: { b: 3 } },
        { a: { b: undefined } },
        { a: {  } },
        { a: { b: 3, c: undefined } },
    ])
;

_testIt(
    [{a: {b: 2}}, {a: {b: 2}}, {a: {b: 3}}],
);

_testIt(
    [1, 2, 3, 3],
);

_testIt(
    [['a', 'b', 'c'], ['a', 'b', 'c'],],
);

function _testIt(data)
{
    let actual = array_unique(data);

    let actual2;

    if (Array.isArray(data))
    {
        actual2 = lazy_unique(...data);
    }
    else
    {
        actual2 = lazy_unique(data);
    }

    console.log(`========= input =========`);

    console.dir(data);

    console.log(`--------- array_unique ---------`);
    console.dir(actual);

    console.log(`--------- lazy_unique ---------`);
    console.dir(actual2);
}
========= input =========
[ 1,
  0,
  true,
  undefined,
  null,
  false,
  [ 'a', 'b', 'c' ],
  [ 'a', 'b', 'c' ],
  [ 'a', 'c', 'b' ],
  { a: { b: 2 } },
  { a: { b: 2 } },
  { a: { b: 3 } },
  { a: { b: undefined } },
  { a: {} },
  { a: { b: 3, c: undefined } } ]
--------- array_unique ---------
[ 1,
  0,
  true,
  undefined,
  null,
  false,
  [ 'a', 'b', 'c' ],
  [ 'a', 'c', 'b' ],
  { a: { b: 2 } },
  { a: { b: 3 } },
  { a: { b: undefined } },
  { a: {} },
  { a: { b: 3, c: undefined } } ]
--------- lazy_unique ---------
[ 1,
  0,
  true,
  undefined,
  null,
  false,
  [ 'a', 'b', 'c' ],
  [ 'a', 'c', 'b' ],
  { a: { b: 2 } },
  { a: { b: 3 } },
  { a: { b: undefined } },
  { a: {} },
  { a: { b: 3, c: undefined } } ]
========= input =========
[ { a: { b: 2 } }, { a: { b: 2 } }, { a: { b: 3 } } ]
--------- array_unique ---------
[ { a: { b: 2 } }, { a: { b: 3 } } ]
--------- lazy_unique ---------
[ { a: { b: 2 } }, { a: { b: 3 } } ]
========= input =========
[ 1, 2, 3, 3 ]
--------- array_unique ---------
[ 1, 2, 3 ]
--------- lazy_unique ---------
[ 1, 2, 3 ]
========= input =========
[ [ 'a', 'b', 'c' ], [ 'a', 'b', 'c' ] ]
--------- array_unique ---------
[ [ 'a', 'b', 'c' ] ]
--------- lazy_unique ---------
[ [ 'a', 'b', 'c' ] ]

options

array_unique(arr_input, {
    checker(element, array, arr_new, arr_old)
    {
        let bool: boolean;
        
        // do equal check
        
        return bool;
    },
    
    // overwrite source array
    overwrite: true,
})