Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/igorskyflyer/npm-uarray

🎉 Provides UArray, an Array type that supports negative indices/indexes, just wrap your regular JavaScript array with UArray() and you are all set! 🙌
https://github.com/igorskyflyer/npm-uarray

access array back-end igorskyflyer index javascript mocha negative nodejs npm uarray utility

Last synced: 2 days ago
JSON representation

🎉 Provides UArray, an Array type that supports negative indices/indexes, just wrap your regular JavaScript array with UArray() and you are all set! 🙌

Awesome Lists containing this project

README

        

## 🎉 UArray 🙌




Provides `UArray`, an `Array` type that supports negative indices/indexes, just wrap your _regular_ JavaScript array with `UArray()` or pass the elements directly to `UArray()` and you are all set! 🎉🙌


⚠ Uses the built-in Proxy object, check browser compatibility on the Can I Use website.



📢 This is the npm version of this project, if you are looking for the vanilla JavaScript version, check this.


### Usage


ℹ Works like negative indices in other languages, e.g. **-1** picks that **last** element, **-2,** the **second to last**, etc.


✨ Since `v.1.1.0` the function signature has been changed and now it supports 2 different ways of action. You can now pass a single parameter of type `Array` or multiple parameters of any primitive type.


Install it first by doing,

```shell
npm i "@igor.dvlpr/uarray"
```


and then use it,


```js
const UArray = require('@igor.dvlpr/uarray')
const food = UArray(['🍟', '🌭', '🍿', '🥙', '🥓']) // array passed
const objects = UArray('🎈', '🎩', '⚽', '🥇', '🎯') // no array passed, just direct values

console.log(food[-1]) // prints '🥓'
console.log(food[-3]) // prints '🍿'

console.log(objects[-1]) // prints '🎯'
console.log(objects[-3]) // prints '⚽'
```



🎉 Happy coding! 🙌