0.1.11 • Published 13 days ago

array-filter-utils v0.1.11

Weekly downloads
-
License
MIT
Repository
-
Last release
13 days ago

array-filter-utils

array-filter-utils is a library offering a bulk of functions to filter arrays with type management.

GitHub Coveralls GitHub tag checks state npm GitHub tag (latest by date)

Usage

npm install array-filter-utils
import { isSet } from "array-filter-utils";

const array = [1, undefined, 3];
// typeof array == Array<number | undefined>
const result = array.filter(isSet);
// typeof result == Array<number>

Examples

array.filter(requiredIsSet)

return true if element is set

const test_array: readonly T[] = [
  { key: "valid" },
  { key: null },
  { key: undefined },
  {},
  { key: 0 },
  { key: false },
] as const;

const result = test_array.filter(requiredIsSet("key"));

expect(result).toStrictEqual([
  { key: "valid" },
  { key: null },
  { key: 0 },
  { key: false },
]);

array.filter(requiredIsNotNullable)

return true if element is set and not null

const test_array: readonly T[] = [
  { key: "valid" },
  { key: null },
  { key: undefined },
  {},
  { key: 0 },
  { key: false },
] as const;

const result = test_array.filter(requiredIsNotNullable("key"));

expect(result).toStrictEqual([{ key: "valid" }, { key: 0 }, { key: false }]);

array.filter(isSet)

remove undefined elements

const testArray = ["valid", null, undefined, 0, false] as const;

const result = testArray.filter(isSet);

expect(result).toStrictEqual(["valid", null, 0, false]);

array.filter(notNullable)

remove null and undefined elements

const testArray = ["valid", null, undefined, 0, false] as const;

const result = testArray.filter(notNullable);

expect(result).toStrictEqual(["valid", 0, false]);
0.1.11

13 days ago

0.1.10

3 months ago

0.1.9

3 months ago

0.1.8

8 months ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.0

3 years ago

0.1.4

3 years ago