UNPKG

typedash

Version:

modern, type-safe collection of utility functions

1 lines 1.11 kB
{"version":3,"file":"without-B1K1UmyO.cjs","names":["createTypeGuard"],"sources":["../src/functions/without/without.ts"],"sourcesContent":["import { createTypeGuard } from '../createTypeGuard';\n\n/**\n * Returns a new array containing all elements of the input array except the specified items to exclude.\n * @param array The input array to exclude items from.\n * @param itemsToExclude An iterable of items to exclude from the input array.\n * @returns A new array containing all elements of the input array except the specified items to exclude.\n * @example\n * ```ts\n * without([1, 2, 3], [2, 3]) // [1]\n * without(['a', 'b', 'c'], ['b', 'c']) // ['a']\n * without([1, 2, 3], []) // [1, 2, 3]\n */\nexport function without<T, const S extends T>(\n array: readonly T[],\n itemsToExclude: Iterable<S>\n): Exclude<T, S>[] {\n const isItemToExclude = createTypeGuard(itemsToExclude);\n return array.filter((item): item is Exclude<T, S> => !isItemToExclude(item));\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,QACd,OACA,gBACiB;CACjB,MAAM,kBAAkBA,wCAAgB,eAAe;AACvD,QAAO,MAAM,QAAQ,SAAgC,CAAC,gBAAgB,KAAK,CAAC"}