Skip to main content
Deno 2 is finally here 🎉️
Learn more

Unique Array (ES)

⚖️ MIT

Deno Land: unique_array GitHub: hugoalh-studio/unique-array-es JSR: @hugoalh/unique-array NPM: @hugoalh/unique-array

An ES (JavaScript & TypeScript) module to return unique array elements without any duplicated elements by ignore their reference points.

🎯 Target

  • Bun ^ v1.0.0
  • Cloudflare Workers
  • Deno >= v1.34.0 / >= v1.41.1 (For JSR Only)

    🛡️ Require Permission

    N/A

  • NodeJS >= v16.13.0

🔰 Usage

Via JSR With node_modules

🎯 Supported Target

  • Bun
  • Cloudflare Workers
  • NodeJS
  1. Install via:
    • Bun
      bunx jsr add @hugoalh/unique-array[@${Tag}]
    • NPM
      npx jsr add @hugoalh/unique-array[@${Tag}]
    • PNPM
      pnpm dlx jsr add @hugoalh/unique-array[@${Tag}]
    • Yarn
      yarn dlx jsr add @hugoalh/unique-array[@${Tag}]
  2. Import at the script:
    import ... from "@hugoalh/unique-array";

ℹ️ Note

  • Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.
  • It is recommended to import the module with tag for immutability.

Via JSR With Specifier

🎯 Supported Target

  • Deno
  1. Import at the script:
    import ... from "jsr:@hugoalh/unique-array[@${Tag}]";

ℹ️ Note

  • Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.
  • It is recommended to import the module with tag for immutability.

Via NPM With node_modules

🎯 Supported Target

  • Cloudflare Workers
  • NodeJS
  1. Install via:
    • NPM
      npm install @hugoalh/unique-array[@${Tag}]
    • PNPM
      pnpm add @hugoalh/unique-array[@${Tag}]
    • Yarn
      yarn add @hugoalh/unique-array[@${Tag}]
  2. Import at the script:
    import ... from "@hugoalh/unique-array";

ℹ️ Note

  • Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.
  • It is recommended to import the module with tag for immutability.

Via NPM With Specifier

🎯 Supported Target

  • Bun
  • Deno
  1. Import at the script:
    import ... from "npm:@hugoalh/unique-array[@${Tag}]";

ℹ️ Note

  • Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file jsr.jsonc property exports for available sub paths.
  • It is recommended to import the module with tag for immutability.

Via Remote Import

🎯 Supported Target

  • Deno
  1. Import at the script via:
    • Deno Land
      import ... from "https://deno.land/x/unique_array[@${Tag}]/mod.ts";
    • GitHub Raw (Require Tag)
      import ... from "https://raw.githubusercontent.com/hugoalh-studio/unique-array-es/${Tag}/mod.ts";

ℹ️ Note

  • Although it is recommended to import the entire module with the main path mod.ts, it is also able to import part of the module with sub path if available, but do not import if:

    • it’s file path has an underscore prefix (e.g.: _foo.ts, _util/bar.ts), or
    • it is a benchmark or test file (e.g.: foo.bench.ts, foo.test.ts), or
    • it’s symbol has an underscore prefix (e.g.: export function _baz() {}).

    These elements are not considered part of the public API, thus no stability is guaranteed for them.

  • Although there have 3rd party services which provide enhanced, equal, or similar methods/ways to remote import the module, beware these services maybe inject unrelated elements and thus affect the security.

  • It is recommended to import the module with tag for immutability.

🧩 API

  • function uniqueArray<T>(item: T[]): T[];

ℹ️ Note

For the prettier documentation, can visit via:

✍️ Example

  • uniqueArray([{ foo: "bar" }, { foo: "bar" }, { bar: "gaz" }]);
    //=> [{ foo: "bar" }, { bar: "gaz" }]