JSPM

arr-to-obj

0.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23
  • Score
    100M100P100Q55605F

convert arrays to objects (arr to obj)

Package Exports

  • arr-to-obj

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (arr-to-obj) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

array to object (arr to obj)

convert arrays to objects

default

(also can be used as valAsKeyAndVal)

const arrToObj = require('arr-to-obj')
const obj = arrToObj(['eh', 'canada'])
// {eh: eh, canada: canada}

valAsKey

const {valAsKey} = require('arr-to-obj')
const obj = valAsKey(['eh', 'canada'], 'woot')
// {eh: 'woot', canada: 'woot'}

valAsVal

// @example:
// var array = ['eh', 'canada']
// valAsVal(array)
const {valAsVal} = require('arr-to-obj')
const obj = valAsVal(['eh', 'canada'])
// {'1': 'eh', '2': 'canada'}

custom

const arrToObj = require('arr-to-obj')
const arr = ['eh', 'canada']

// does the same as #valAsKey
// {eh: 'woot', canada: 'woot'}
const obj = arrToObj(array, {
  valFn: () => undefined,
  keyFn: ({i, val}) => typeof fn === 'function' ? fn(val, i) : (fn || i),
})

resources