Socket
Socket
Sign inDemoInstall

l00p

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    l00p

Getting useful loop information while looping


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
3.23 kB
Created
Weekly downloads
 

Readme

Source

l00p

Getting useful loop information while looping.

This package has been created for help mapping items in, just say, React:

Without l00p:

...
<div>
{some.stuff.collection.map((item, i) => {
    const first = i === 0
    const last = i === some.stuff.collection.length - 1
    return (
        <div className={first ? 'class' : 'anotherClass'}>
            {item.name}
        </div>
    )
})}
</div>
...

With l00p:

import loop from 'l00p'
...
<div>
{loop(some.stuff.collection, (item, { first }) => (
    <div className={first ? 'class' : 'anotherClass'}>
        {item.name}
    </div>
))}
</div>
...

Here the complete list of values provided while looping:

  • index: The current index.
  • first: A boolean true when is ther fist element of collection.
  • last: A boolean true when is ther last element of collection.
  • reverseIndex: The index from the end (collection.lentgth - index).
  • even: A boolean true when the index is even.
  • odd: A boolean true when the index is odd.

FAQs

Last updated on 18 May 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc