Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@youngbeen/es-halfmoon

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

@youngbeen/es-halfmoon

`ES-halfmoon` is about to provide some prototype methods for ES not covered yet

latest
npmnpm
Version
0.1.2
Version published
Weekly downloads
19
137.5%
Maintainers
1
Weekly downloads
 
Created
Source

[TOC]

ES-halfmoon

New ES6+ has many amazing features like filter, map etc. But it's not enough. ES-halfmoon is about to provide some prototype methods for ES not covered yet.

All features will only be attached when ES does not provide, ES-halfmoon never overrides native ES methods

Features

  • Array.get() like map
  • Array.forEachRight() loop reversed

Install

Install it via npm

npm i @youngbeen/es-halfmoon

Usage

Array.get()

Array.get(value, [keyName])

Tip: if keyName not set, default get priority is id > key > value

e.g.

const fruits = [
  { id: 'apple', name: 'Apple' },
  { id: 'orange', name: 'Orange' },
  { id: 'banana', name: 'Banana' }
]
// finding item by specific value
fruits.get('orange') // -> { id: 'orange', name: 'Orange' }
// which equivalent
fruits.get('orange', 'id')

const myFruits = [
  { type: 'apple', name: 'Apple' },
  { type: 'orange', name: 'Orange' },
  { type: 'banana', name: 'Banana' }
]
// specify keyName
fruits.get('orange', 'type')

Array.forEachRight()

Array.forEachRight(callback(item, [index]))

This method is useful when you are looping array for removing some item

e.g.

const array = ['h', 'e', 'l', 'l', 'o']
array.forEachRight((item, index) => {
  console.log(item, index)
})
// 'o' 4
// 'l' 3
// 'l' 2
// 'e' 1
// 'h' 0

Keywords

ES

FAQs

Package last updated on 22 Feb 2021

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