New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

funckey

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

funckey

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

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

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

Keywords

funckey

FAQs

Package last updated on 19 Apr 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