🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@okiba/arrays

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@okiba/arrays

Array helpers for okiba.js

1.0.25
latest
Source
npm
Version published
Maintainers
3
Created
Source

Okiba / arrays

Array utils for okiba js

__

Installation

npm i --save @okiba/arrays

Or import it directly in the browser

<script type="module" src="https://unpkg.com/@okiba/arrays/index.js"></script>

Usage

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:

{
  test: /\.js$/,
  exclude: /node_modules\/(?!(@okiba)\/).*/,
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env']
    }
  }
}

arrayOrOne(arrayLike)

Return the first element if it only contains one

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 array

castArray(castable)

Cast an array-like object or single element to Array

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 element

spliceOne(array, index)

Removes an element from an array in-place without causing Garbage Collection

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

FAQs

Package last updated on 26 May 2020

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