Array helpers for okiba.js
npm install @okiba/arrays__
``bash`
npm i --save @okiba/arrays
Or import it directly in the browser
`html`
`javascript`
import arrays from '@okiba/arrays'
#### Untranspiled code 🛑
Okiba Core packages are not transpiled, so _don't forget to transpile them with your favourite bundler_.
For example, using Babel with Webpack, you should prevent imports from okiba to be excluded from transpilation, like follows:
`javascript`
{
test: /\.js$/,
exclude: /node_modules\/(?!(@okiba)\/).*/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
Return the first element if it only contains one
`javascript
const els = arrayOrOne([🍏, 🍌])
console.log(els) // [🍏, 🍌]
const els = arrayOrOne([🍏])
console.log(els) // 🍏
`
#### Arguments
##### + arrayLike: Array-like
The options object.
#### Returns
any The first element or the argument, undefined if empty arraycastArray(castable)
Cast an array-like object or single element to Array
`javascript`
const elements = castArray(document.querySelectorAll('p')) // [p, p]
const fruits = castArray(🍒) // [🍒]
#### Arguments
##### + castable: any
Array to cast
#### Returns
Array The array-like converted to Array, or an Array containing the elementspliceOne(array, index)
Removes an element from an array in-place without causing Garbage Collection
`javascript`
const array = [🍎, 🍐, 🍌]
spliceOne(array, 1)
console.log(array) // Logs: [🍎, 🍌]
#### Arguments
##### + array: Array
Array you want to remove an element from
##### + index: Number`
The index of the element to remove