Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chaijs/pathval
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fd11b26a39c2d948ef6785feac1edf8c01e4a055
Choose a base ref
...
head repository: chaijs/pathval
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: db6c3e39c39859564704b7f37149082689f1b172
Choose a head ref
  • 12 commits
  • 10 files changed
  • 4 contributors

Commits on Oct 12, 2016

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    69b05d9 View commit details
  2. Merge pull request #45 from lucasfcosta/update-docs-for-set

    docs: explicitly mention that setPathValue returns the target object
    keithamus authored Oct 12, 2016
    Copy the full SHA
    70dc0a5 View commit details

Commits on Dec 18, 2016

  1. Center repo name on README

    astorije authored Dec 18, 2016
    Copy the full SHA
    aebb278 View commit details
  2. Merge pull request #54 from astorije/patch-1

    Center repo name on README
    lucasfcosta authored Dec 18, 2016
    Copy the full SHA
    a0147cd View commit details

Commits on Jan 16, 2017

  1. Delete MAINTAINERS

    keithamus authored Jan 16, 2017
    Copy the full SHA
    07eb4a8 View commit details
  2. Merge pull request #55 from chaijs/remove-lgtm

    Delete MAINTAINERS
    lucasfcosta authored Jan 16, 2017
    Copy the full SHA
    a123018 View commit details

Commits on Nov 12, 2020

  1. Copy the full SHA
    57730a9 View commit details
  2. Copy the full SHA
    49031e4 View commit details
  3. Copy the full SHA
    c77b9d2 View commit details

Commits on Jan 26, 2021

  1. Copy the full SHA
    49ce1f4 View commit details
  2. Merge pull request #60 from deleonio/fix/vulnerability-prototype-poll…

    …ution
    
    Fix Vulnerability - Ready
    keithamus authored Jan 26, 2021
    Copy the full SHA
    7859e0e View commit details
  3. chore: v1.1.1

    keithamus committed Jan 26, 2021
    Copy the full SHA
    db6c3e3 View commit details
Showing with 15,760 additions and 58 deletions.
  1. +1 −0 .gitignore
  2. +4 −4 .travis.yml
  3. +0 −5 MAINTAINERS
  4. +4 −2 README.md
  5. +15 −5 index.js
  6. +12 −14 karma.conf.js
  7. +15,671 −0 package-lock.json
  8. +24 −22 package.json
  9. +1 −0 test/.eslintrc
  10. +28 −6 test/index.js
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ components
node_modules
npm-debug.log

.nyc_output/
coverage/

pathval.js
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -10,10 +10,10 @@ cache:
- node_modules

node_js:
- 0.10 # to be removed 2016-10-01
- 0.12 # to be removed 2016-12-31
- 4 # to be removed 2018-04-01
- 6 # to be removed 2019-04-01
# - 0.10 # to be removed 2016-10-01
# - 0.12 # to be removed 2016-12-31
# - 4 # to be removed 2018-04-01
# - 6 # to be removed 2019-04-01
- lts/* # safety net; don't remove
- node # safety net; don't remove

5 changes: 0 additions & 5 deletions MAINTAINERS

This file was deleted.

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<h1 align=center>
<a href="http://chaijs.com" title="Chai Documentation">
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png"/> pathval
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png">
</a>
<br>
pathval
</h1>

<p align=center>
@@ -100,7 +102,7 @@ The primary export of `pathval` is an object which has the following methods:
* `hasProperty(object, name)` - Checks whether an `object` has `name`d property or numeric array index.
* `getPathInfo(object, path)` - Returns an object with info indicating the value of the `parent` of that path, the `name ` of the property we're retrieving and its `value`.
* `getPathValue(object, path)` - Retrieves the value of a property at a given `path` inside an `object`'.
* `setPathValue(object, path, value)` - Sets the `value` of a property at a given `path` inside an `object`'.
* `setPathValue(object, path, value)` - Sets the `value` of a property at a given `path` inside an `object` and returns the object in which the property has been set.

```js
var pathval = require('pathval');
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -76,13 +76,20 @@ function parsePath(path) {
var str = path.replace(/([^\\])\[/g, '$1.[');
var parts = str.match(/(\\\.|[^.]+?)+/g);
return parts.map(function mapMatches(value) {
if (
value === 'constructor' ||
value === '__proto__' ||
value === 'prototype'
) {
return {};
}
var regexp = /^\[(\d+)\]$/;
var mArr = regexp.exec(value);
var parsed = null;
if (mArr) {
parsed = { i: parseFloat(mArr[1]) };
} else {
parsed = { p: value.replace(/\\([.\[\]])/g, '$1') };
parsed = { p: value.replace(/\\([.[\]])/g, '$1') };
}

return parsed;
@@ -107,7 +114,7 @@ function parsePath(path) {
function internalGetPathValue(obj, parsed, pathDepth) {
var temporaryValue = obj;
var res = null;
pathDepth = (typeof pathDepth === 'undefined' ? parsed.length : pathDepth);
pathDepth = typeof pathDepth === 'undefined' ? parsed.length : pathDepth;

for (var i = 0; i < pathDepth; i++) {
var part = parsed[i];
@@ -118,7 +125,7 @@ function internalGetPathValue(obj, parsed, pathDepth) {
temporaryValue = temporaryValue[part.p];
}

if (i === (pathDepth - 1)) {
if (i === pathDepth - 1) {
res = temporaryValue;
}
}
@@ -152,7 +159,7 @@ function internalSetPathValue(obj, val, parsed) {
part = parsed[i];

// If it's the last part of the path, we set the 'propName' value with the property name
if (i === (pathDepth - 1)) {
if (i === pathDepth - 1) {
propName = typeof part.p === 'undefined' ? part.i : part.p;
// Now we set the property with the name held by 'propName' on object with the desired val
tempObj[propName] = val;
@@ -199,7 +206,10 @@ function getPathInfo(obj, path) {
var parsed = parsePath(path);
var last = parsed[parsed.length - 1];
var info = {
parent: parsed.length > 1 ? internalGetPathValue(obj, parsed, parsed.length - 1) : obj,
parent:
parsed.length > 1 ?
internalGetPathValue(obj, parsed, parsed.length - 1) :
obj,
name: last.p || last.i,
value: internalGetPathValue(obj, parsed),
};
26 changes: 12 additions & 14 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint no-process-env: "off" */

'use strict';

var packageJson = require('./package.json');
var defaultTimeout = 120000;
var browserifyIstanbul = require('browserify-istanbul');
module.exports = function configureKarma(config) {
var localBrowsers = [
'PhantomJS',
];
var localBrowsers = [ 'PhantomJS' ];
var sauceLabsBrowsers = {
SauceChromeLatest: {
base: 'SauceLabs',
@@ -41,7 +42,9 @@ module.exports = function configureKarma(config) {
config.set({
basePath: '',
browsers: localBrowsers,
logLevel: process.env.npm_config_debug ? config.LOG_DEBUG : config.LOG_INFO,
logLevel: process.env.npm_config_debug ?
config.LOG_DEBUG :
config.LOG_INFO,
frameworks: [ 'browserify', 'mocha' ],
files: [ 'test/*.js' ],
exclude: [],
@@ -51,9 +54,7 @@ module.exports = function configureKarma(config) {
browserify: {
debug: true,
bare: true,
transform: [
browserifyIstanbul({ ignore: [ '**/node_modules/**', '**/test/**' ] }),
],
transform: [ browserifyIstanbul({ ignore: [ '**/node_modules/**', '**/test/**' ] }) ],
},
reporters: [ 'progress', 'coverage' ],
coverageReporter: {
@@ -82,14 +83,11 @@ module.exports = function configureKarma(config) {
browsers: localBrowsers.concat(Object.keys(sauceLabsBrowsers)),
sauceLabs: {
testName: packageJson.name,
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER || new Date().getTime(),
tunnelIdentifier:
process.env.TRAVIS_JOB_NUMBER || new Date().getTime(),
recordVideo: true,
startConnect: ('TRAVIS' in process.env) === false,
tags: [
'pathval_' + packageJson.version,
process.env.SAUCE_USERNAME + '@' + branch,
build,
],
startConnect: 'TRAVIS' in process.env === false,
tags: [ 'pathval_' + packageJson.version, process.env.SAUCE_USERNAME + '@' + branch, build ],
},
});
}
Loading