New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@finibit/iterate

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@finibit/iterate

Iterate over objects, strings and collections

unpublished
latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

@finibit/iterate

Iterate over objects, strings and collections using a single function.

Installation

Requires Node.js version >=16.15.0.

Install using NPM:

npm i @finibit/iterate

Usage

Import iterate function using import statement:

import iterate from '@finibit/iterate'

The iterate function accepts a value to iterate over, and a function to call for each element of that value. The value can be an any iterable value, e.g. array, string, or an object.

When iterating over iterables, the function receives three arguments. The first one is the current element. The second one is the index of the element. The third one is the iterable object itself:

// array
iterate([1, 2, 3], (value, index, array) => {})

// string
iterate('abc', (char, index, string) => {})

// set
iterate(new Set('a', 'b', 'c'), (value, index, set) => {})

// integer
iterate(10, (integer) => {})

When iterating over objects, the function also receives three arguments. The first one is the value of the current property. The second one is the key of that property. The third one is the object itself.

iterate({ a: 1, b: 2, c: 3 }, (value, key, object) => {})

Although, the built-in Map type is technically an iterable, it is treated like an object by the iterate function:

iterate(new Map([[1, 'a'], [2, 'b'], [3, 'c']], (value, key, map) => {}))

You can use more specific functions if you know your type.

For iterables use iterateIterable:

import { iterateIterable } from '@finibit/iterate'

iterateIterable([1, 2, 3], (value, index, array) => {})

For objects use iterateObject:

import { iterateObject } from '@finibit/iterate'

iterateObject({ a: 1, b: 2, c: 3 }, (value, key, object) => {})

For the built-in Map use iterateMap:

import { iterateMap } from '@finibit/iterate'

iterateMap(new Map([[1, 'a'], [2, 'b'], [3, 'c']], (value, key, map) => {}))

You can iterate over negative integer values too:

import { iterateInteger } from '@finibit/iterate'

iterateInteger(-10, (integer) => {})

Keywords

for

FAQs

Package last updated on 02 Jan 2023

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