3.1.0 • Published 2 years ago

array.defined v3.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
2 years ago

defined

Cheks if properties or variables are defined

$>  npm i -s array.defined

Usage

// import defined or polyfill into your src
import { definedList } from "array.defined";

[1,2, null, undefined].defined() // => [1,2]
defined(null) // => false
defined(undefined) // => false
definedList([1,2]) // => [1,2]
definedList([undefined, null]) // => []

// filter first
[1,2,3].first()  // => [1]
// filter last
[1,2,3].last()  // => [3]

Template for wrapping immutable lists

import { Iterable, List } from "immutable";
import { defined } from "array.defined";

Iterable.prototype.defined = defined(Iterable.prototype.defined)
  ? Iterable.prototype.defined
  : function (this: any) {
      return this.toList().filter((e: any) => defined(e));
    };

Iterable.prototype.allDefined = defined(Iterable.prototype.allDefined)
  ? Iterable.prototype.allDefined
  : function (this: any) {
      return this.toList().every((e: any) => defined(e)) ? this : List();
    };

Publish

npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease]
git push --follow-tags
npm publish
3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

3.0.0-1

2 years ago

3.0.0-0

2 years ago

2.4.2

4 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago