Skip to content

Commit

Permalink
Require Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 7, 2020
1 parent cbd7074 commit 5840717
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '14'
- '12'
- '10'
- '8'
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
declare const dotProp: {
/**
Get the value of the property at the given path.
@param object - Object to get the `path` value.
@param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key.
@param defaultValue - Default value.
Expand Down Expand Up @@ -32,6 +34,8 @@ declare const dotProp: {
): T;

/**
Set the property at the given path to the given value.
@param object - Object to set the `path` value.
@param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key.
@param value - Value to set at `path`.
Expand Down Expand Up @@ -62,6 +66,8 @@ declare const dotProp: {
): T;

/**
Check whether the property at the given path exists.
@param object - Object to test the `path` value.
@param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key.
Expand All @@ -76,6 +82,8 @@ declare const dotProp: {
has(object: {[key: string]: any} | undefined, path: string): boolean;

/**
Delete the property at the given path.
@param object - Object to delete the `path` value.
@param path - Path of the property in the object, using `.` to separate each nested key. Use `\\.` if you have a `.` in the key.
@returns A boolean of whether the property existed before being deleted.
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';
const isObj = require('is-obj');

const disallowedKeys = [
const disallowedKeys = new Set([
'__proto__',
'prototype',
'constructor'
];
]);

const isValidPath = pathSegments => !pathSegments.some(segment => disallowedKeys.includes(segment));
const isValidPath = pathSegments => !pathSegments.some(segment => disallowedKeys.has(segment));

function getPathSegments(path) {
const pathArray = path.split('.');
Expand Down
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {expectType} from 'tsd';
import {expectType, expectAssignable} from 'tsd';
import dotProp = require('.');

expectType<unknown>(dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar'));
expectType<string | undefined>(dotProp.get<string>({foo: {bar: 'unicorn'}}, 'foo.bar'));
expectType<unknown>(dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep'));
expectType<string>(
expectAssignable<string>(
dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value')
);
expectType<unknown>(
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"description": "Get, set, or delete a property from a nested object using a dot path",
"license": "MIT",
"repository": "sindresorhus/dot-prop",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd",
Expand Down Expand Up @@ -39,7 +40,12 @@
"devDependencies": {
"ava": "^2.1.0",
"benchmark": "^2.1.4",
"tsd": "^0.7.2",
"xo": "^0.25.3"
"tsd": "^0.13.1",
"xo": "^0.33.1"
},
"xo": {
"rules": {
"@typescript-eslint/method-signature-style": "off"
}
}
}
18 changes: 13 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# dot-prop [![Build Status](https://travis-ci.org/sindresorhus/dot-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/dot-prop)
# dot-prop [![Build Status](https://travis-ci.com/sindresorhus/dot-prop.svg?branch=master)](https://travis-ci.com/github/sindresorhus/dot-prop)

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

## Install

```
$ npm install dot-prop
```


## Usage

```js
Expand Down Expand Up @@ -58,19 +56,30 @@ console.log(object);
//=> {foo: {bar: {y: 'x'}}}
```


## API

### get(object, path, defaultValue?)

Get the value of the property at the given path.

Returns the value if any.

### set(object, path, value)

Set the property at the given path to the given value.

Returns the object.

### has(object, path)

Check whether the property at the given path exists.

Returns a boolean.

### delete(object, path)

Delete the property at the given path.

Returns a boolean of whether the property existed before being deleted.

#### object
Expand Down Expand Up @@ -103,7 +112,6 @@ Type: `unknown`

Default value.


---

<div align="center">
Expand Down

0 comments on commit 5840717

Please sign in to comment.