Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dot-dotty

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dot-dotty

Lazy dot-syntax object access via proxies

  • 0.9.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

DotDotty

(of a person, action, or idea) somewhat mad or eccentric.

DotDotty provides a very simple wrapper around a provided object that allows for lazy dot-syntax access via the [] accessor.

Usage

const DotDotty = require('dot-dotty')

let myData = {a: true, b: false}
let dot = DotDotty(myData)

dot['a'] // true
dot['c'] = 'maybe' // 'maybe'
dot['d.0.first'] = 'expansion!' // 'expansion
// dot now is {a: true: b: false, c: 'maybe', d: [{first: 'expansion!'}]}

A given object can be made immutable or denied expansion by providing an additional options object.

If isExpandable is true(default), new arrays, objects, and keys are created when set access is attempted. Arrays will be created if the value at a given key is not an object or array already and the target key can evaluate to a number. If the target key cannot evaluate as a number, the value at the given key is created as an object. Arrays will attempt to remain as arrays unless a non-number is used as the key, in which case the array will be non-destructively converted to an object.

API

Table of contents

  • function DotDotty

function DotDotty

DotDotty return a Proxy against the given target object that can access properties via dot-syntax.

ParameterTypeDescription
targetObjectThe target object to proxy DotDotty against.
optionsObject
options.isImmutableBoolean? = falseWhether or not the target object should be changeable.
options.isExpandableBoolean? = trueWhether or not new values may be placed into the object. These include new array entries and new object entries.
options.expandOverNullBoolean? = falseWhether or not null values should be treated as nonexistent for the purposes of expansion.
options.throwErrorsBoolean? = trueWhether or not to throw errors when invalid access or expansion occurs. If false, invalid access or expansion will return undefined.
options.throwTrapsBoolean? = trueWhether or not to throw trap errors for set and delete. If false, invalid sets or deletes will be silently ignored.
options.preventPrototypeKeywordsBoolean? = trueWhether or not prototype keywords should be allowed within keys. If true, "proto", "constructor", and "prototype" will be silently truncated. If throwErrors is true, an error will be thrown.
options.removeLeadingDotsBoolean? = trueWhether or not to remove leading dots from the target. The effectively cleans ".prop.a" => "prop.a".
options.prefixString? = ''A prefix to add to the dot-notation string.
options.suffixString? = ''A suffix to add to the dot-notation string.

Returns: Proxy — A proxy to the target object that can use dot-notation to access or create properties.

Examples

const DotDotty = require('dot-dotty')

let myData = {a: 1, b: 2}

let dot = DotDotty(myData)

dot["a"] // returns 1

dot["c.cA"] = true // returns true

// dot now contains {a: 1, b:2, c: {cA: true}}

dot["d.0.a"] = "test" // returns "test"

// dot now contains {a: 1, b:2, c: {cA: true}, d: [{a: test}]}

Keywords

FAQs

Package last updated on 26 Jul 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc