array-compact-map
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

array-compact-map

npm version npm downloads

array-compact-map JS/TS library that expose a transformation function (eq. to Array.map) The returns array containing non-undefined results of calling the given transformation with each element of this array.

Use this method to receive an array of non-undefined values when your transformation produces an optional value.

Installation

npm i array-compact-map

Usage

import "array-compact-map"; // you must import the framework on your startup file

const strings: string[] = ["10", "500", "hello", "1000", "world"];
const res: number[] = strings.compactMap((str) => {
    const n = Number.parseInt(str);
    if(!isNaN(n)) {
        return n;
    }
});
console.log(res); // [ 10, 500, 1000 ]

Readme

Keywords

Package Sidebar

Install

npm i array-compact-map

Weekly Downloads

0

Version

1.0.0

License

BSD-3-Clause

Unpacked Size

5.48 kB

Total Files

8

Last publish

Collaborators

  • bbriatte