Socket
Socket
Sign inDemoInstall

glfe

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    glfe

A simple but powerful dot-notation prop path util


Version published
Maintainers
1
Created

Readme

Source

glfe

✨ A simple but powerful dot-notation prop path util

Install

with npm or yarn or any other package manager you prefer

yarn add glfe
// npm i glfe

Usage

  • you can include glfe with 'script' tag derectly:
<script src="path/to/glfe"></script>
<script>
    var glfe = window.glfe
    glfe.get(...)
    glfe.find(...)
    glfe.set(...)
</script>
  • when you project use some module bundler like webpack:
import glfe from "glfe"

example

var obj = {
    a: {
        b: {
            c: [{
                d: [ {
                    e: 5
                }]
            }],
            f: 6
        }
    }
}
console.log(glfe.get(obj, "a.b.c[0].d[0].e"))
console.log(glfe.get(obj, "a.b.f"))
console.log(glfe.get(obj, "a[b]"))
console.log(glfe.get(obj, "not.exist.prop"))   // throw error
console.log(glfe.find(obj, "not.exist.prop"))  // undefined
// you can use "!" flag to tell `glfe` to make an array instead of an object
var seter = glfe.set(obj, "a[b][r!][2]", 66)
console.log(seter)
console.log(obj)
console.log(obj===seter) // true

Api

glfe#get(target, propPath)

Get prop value with dot-notation from target object. It would throw error when the prop path is not exist, if you want to avoid it please use find instead of get

glfe#find(target, propPath)

Same as get except it would return undefined when the prop path is not exist, if you want to avoid it please use get instead of find

glfe#set(target, propPath, value)

set prop value with dot-notation paths

propPath: dot-notation paths, such as "a.b", "a[b]", "a.b[0].c", but "a.b.[0].c" is not supported! target should be a plain object, array is not supported!

Lisense

MIT

Keywords

FAQs

Last updated on 24 Feb 2022

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