Skip to content

bbriatte/array-compact-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 ]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published