npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dot-dotty

v0.9.5

Published

Lazy dot-syntax object access via proxies

Downloads

11

Readme

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

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

| Parameter | Type | Description | | :--------------------------------- | :----------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | target | Object | The target object to proxy DotDotty against. | | options | Object | | | options.isImmutable | Boolean? = false | Whether or not the target object should be changeable. | | options.isExpandable | Boolean? = true | Whether or not new values may be placed into the object. These include new array entries and new object entries. | | options.expandOverNull | Boolean? = false | Whether or not null values should be treated as nonexistent for the purposes of expansion. | | options.throwErrors | Boolean? = true | Whether or not to throw errors when invalid access or expansion occurs. If false, invalid access or expansion will return undefined. | | options.throwTraps | Boolean? = true | Whether or not to throw trap errors for set and delete. If false, invalid sets or deletes will be silently ignored. | | options.preventPrototypeKeywords | Boolean? = true | Whether 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.removeLeadingDots | Boolean? = true | Whether or not to remove leading dots from the target. The effectively cleans ".prop.a" => "prop.a". | | options.prefix | String? = '' | A prefix to add to the dot-notation string. | | options.suffix | String? = '' | 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}]}