New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@arecalde/nnmap

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arecalde/nnmap

Array mapping ignoring null values

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

nnmap (No nulls map)

A function for selectively mapping through arrays

  • Just return null to exclude values from map
  • Quit from map at any time

No dependencies

Usage:

function returnIfEven(n: any): any | null {
  return (n % 2 === 0) ? n : null;
}

function quitIfThree(n: any): boolean {
  if (n === 3) return true;
  return false;
}

function quitOnThirdItem(n: any, index: number): boolean {
  if (index >= 3) return true;
  return false;
}

// skip nulls
const evenValues = nnmap([1, 2, 3, 4, 5, 6], returnIfEven); // [2, 4, 6]

// quit when value is 3
const quitWhenThree = nnmap([1, 2, 3, 4, 5]), (n) => n, quitIfThree); // [1, 2]

// map until the third index (maps indexes 0, 1, 2)
const firstThreeMappedItems = nnmap([1, 2, 3, 4, 5]), (n) => n, quitOnThirdItem); // [1, 2, 3]

API
  • nnmap

Parameters

NametypeDescription
arrany[]The array to be mapped
cbCallbackThe mapping callback function
qcb?QuitCallbackIf this callback returns true, nnmap quits immediately
// example
const mappedArray = nnmap([]), (n) => n, (n, i) => null); 

cb: Callback

Whatever this callback returns is inserted in the resulting array

Parameters

NametypeDescription
currentItemanyThe current array item to map to a new value
(item) => item.foo

qcb?: QuitCallback

When this callback returns true, nnmap quits immediately and returns an array with the values mapped up to this point

NametypeDescription
currentItemany[]The current array item to map to a new value
currentIndexnumberThe current index being mapped
// quit based on the current value
(item) => item.quit === true;

// quit based on the current index
(item, index) => index > 10;

FAQs

Package last updated on 21 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc