Shuffle Array (ES)
An ES (JavaScript & TypeScript) module to shuffle the array's indexes.
đ¯ 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
node_modules
Via JSR With đ¯ Supported Target
- Bun
- Cloudflare Workers
- NodeJS
- Install via:
- Bun
bunx jsr add @hugoalh/shuffle-array[@${Tag}]
- NPM
npx jsr add @hugoalh/shuffle-array[@${Tag}]
- PNPM
pnpm dlx jsr add @hugoalh/shuffle-array[@${Tag}]
- Yarn
yarn dlx jsr add @hugoalh/shuffle-array[@${Tag}]
- Bun
- Import at the script:
import ... from "@hugoalh/shuffle-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
propertyexports
for available sub paths.- It is recommended to import the module with tag for immutability.
Via JSR With Specifier
đ¯ Supported Target
- Deno
- Import at the script:
import ... from "jsr:@hugoalh/shuffle-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
propertyexports
for available sub paths.- It is recommended to import the module with tag for immutability.
node_modules
Via NPM With đ¯ Supported Target
- Cloudflare Workers
- NodeJS
- Install via:
- NPM
npm install @hugoalh/shuffle-array[@${Tag}]
- PNPM
pnpm add @hugoalh/shuffle-array[@${Tag}]
- Yarn
yarn add @hugoalh/shuffle-array[@${Tag}]
- NPM
- Import at the script:
import ... from "@hugoalh/shuffle-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
propertyexports
for available sub paths.- It is recommended to import the module with tag for immutability.
Via NPM With Specifier
đ¯ Supported Target
- Bun
- Deno
- Import at the script:
import ... from "npm:@hugoalh/shuffle-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
propertyexports
for available sub paths.- It is recommended to import the module with tag for immutability.
Via Remote Import
đ¯ Supported Target
- Deno
- Import at the script via:
- Deno Land
import ... from "https://deno.land/x/shuffle_array[@${Tag}]/mod.ts";
- GitHub Raw (Require Tag)
import ... from "https://raw.githubusercontent.com/hugoalh-studio/shuffle-array-es/${Tag}/mod.ts";
- Deno Land
âšī¸ 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 shuffleArray<T>(item: T[]): T[];
âšī¸ Note
For the prettier documentation, can visit via:
âī¸ Example
const chain = [3, 7, 25, 26, 42, 62, 71, 76, 92, 93]; shuffleArray(chain); //=> [62, 93, 26, 42, 25, 7, 76, 71, 3, 92] shuffleArray(chain); //=> [42, 3, 26, 62, 93, 7, 76, 25, 92, 71]