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

dot-prop-ts

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dot-prop-ts

Get, set, or delete a property from a nested object using a dot path refactored for typescript

latest
Source
npmnpm
Version
1.1.1
Version published
Weekly downloads
928
84.86%
Maintainers
1
Weekly downloads
 
Created
Source

dot-prop-ts

Get, set, or delete a property from a nested object using a dot path

This package is heavily inspired on the dot-prop package developed by Sindre Sorhus and has been refactored to typescript so that it can be installed and used without converting your project to ESM module (see issue).

Install

Using NPM

npm install dot-prop-ts

Using yarn

yarn add dot-prop-ts

getProperty

import {getProperty} from 'dot-prop-ts';

// Getter
getProperty({foo: {bar: 'unicorn'}}, 'foo.bar');
//=> 'unicorn'

getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep');
//=> null

getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value');
//=> 'default value'

getProperty({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot');
//=> 'unicorn'

getProperty({foo: [{bar: 'unicorn'}]}, 'foo.0.bar');
//=> 'unicorn'

setProperty

import {setProperty} from 'dot-prop-ts';

const object = {foo: {bar: 'a'}};
setProperty(object, 'foo.bar', 'b');
//=> {foo: {bar: 'b'}}

const foo = setProperty({}, 'foo.bar', 'c');
//=> {foo: {bar: 'c'}}

setProperty(object, 'foo.baz', 'x');
//=> {foo: {bar: 'b', baz: 'x'}}

setProperty(object, 'foo.biz[0]', 'a');
//=> {foo: {bar: 'b', baz: 'x', biz: ['a']}}

hasProperty

import {hasProperty} from 'dot-prop-ts';

const object = {foo: {bar: 'a'}};
hasProperty(object, 'foo.bar');
//=> true

hasProperty(object, 'foo.goo');
//=> false

deleteProperty

import {deleteProperty} from 'dot-prop-ts';

const object = {foo: {bar: 'a'}};
deleteProperty(object, 'foo.bar');
//=> {foo:{}}

const object = {foo: {bar: 'a'}};
deleteProperty(object, 'foo');
//=> {}

Keywords

object

FAQs

Package last updated on 17 Aug 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