Socket
Socket
Sign inDemoInstall

@okiba/arrays

Package Overview
Dependencies
0
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @okiba/arrays

Array helpers for okiba.js


Version published
Maintainers
3
Install size
8.30 kB
Created

Readme

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

Last updated on 26 May 2020

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