1.1.0 • Published 4 years ago

funckey v1.1.0

Weekly downloads
1
License
Unlicense
Repository
github
Last release
4 years ago

VersionBuild Status codecov

license JavaScript Style Guide


funckey

Documentation

Function-valued properties of objects as dot-separated/array paths.


Installation

Run npm install funckey

Inclusion

ESWhatever:

import funckey from 'funckey'

CommonJS:

const funckey = require('funckey').default

Usage

Module exports a unary function accepting an object with named parameters as follows:

ArgumentType/DefaultRequiredDescription
objObjectYesThe object to search for functions
prefixString = ''NoA prefix to add to found paths
arrayModeBoolean= falseNoWhether to return paths as arrays instead of dot-separated strings. See symbNames.
symbNamesBoolean= falseNoWhether to search own property symbols. If true, arrayMode enabled by default.
propNamesBoolean= falseNoWhether to search own property names
allBoolean= falseNoIf true, include own property names and own property symbols
excludesArray= []NoObject references to exclude from traversal (i.e., circular references)
excludeKeysArray= 'prototype'NoKeyed references to exclude from traversal

Find enumerable functions in an object as dot-paths:

const fixture0 = {
  n(){},
  o: {
    a: ()=>{},
    b:3,
    c: {
      d(){},
      e: 4
    }
  }
}

funckey({obj: fixture0})
// ['n', 'o.a', 'o.c.d']

Find functions in a nested object as array path lists:

const fixture1 = {
  n(){},
  o: {
    a: ()=>{},
    b:3,
    c: {
      d(){},
      e: 4
    }
  }
}

funckey({obj: fixture1,  arrayMode: true})
// [['n'], ['o', 'a'], ['o', 'c', 'd'] ]

Find the function paths associated with the native Array object (ignoring prototype subpaths):

funcKey({obj: Array, propNames: true}) // [ 'isArray', 'from', 'of' ]

Find string- and symbol-keyed function pathss using all option:

const fixture2 = {
  a: 3,
  b(){},
  [Symbol.for('c')]: {
    ca: ()=>{},
    [Symbol.for('cb')]: ()=>{},
    cc: 'no'
  },
  d: {
    da () {},
    [Symbol.for('db')]:()=>{},
    dc: 33
  }
}

funckey({obj: fixture2, all:true})
// [
//   [ 'b' ],
//   [ 'd', 'da' ],
//   [ 'd', Symbol(db) ],
//   [ Symbol(c), 'ca' ],
//   [ Symbol(c), Symbol(cb) ]
// ]

Testing

npm test

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago