Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion 12 src/jsonpath.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const {hasOwnProperty: hasOwnProp} = Object.prototype;

/**
* @typedef {null|boolean|number|string|PlainObject|GenericArray} JSONObject
Expand All @@ -12,6 +11,17 @@ const {hasOwnProperty: hasOwnProp} = Object.prototype;
* @typedef {any} AnyResult
*/

/**
* Check if the provided property name exists on the object.
* @param {string} name Name of the property to check
* @returns {boolean} Whether the object has the property or not
*/
function hasOwnProp (name) {
return typeof this === 'object'
? name in this
: Object.prototype.hasOwnProperty.call(this, name);
}

/**
* Copies array and then pushes item into it.
* @param {GenericArray} arr Array to copy and into which to push
Expand Down
43 changes: 43 additions & 0 deletions 43 test/test.class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {checkBuiltInVMAndNodeVM} from '../test-helpers/checkVM.js';

checkBuiltInVMAndNodeVM(function (vmType, setBuiltInState) {
describe(`JSONPath - Properties (${vmType})`, function () {
before(setBuiltInState);

/**
*
*/
class Test1 {
/**
* Test2.
*/
constructor () {
this.test2 = "test2";
}

/**
* Test3.
* @returns {string}
*/
// eslint-disable-next-line class-methods-use-this
get test3 () {
return "test3";
}
}
const json = new Test1();

it("Checking simple property", () => {
assert.equal(
jsonpath({json, path: "$.test2", wrap: false}),
"test2"
);
});

it("Checking getter property", () => {
assert.equal(
jsonpath({json, path: "$.test3", wrap: false}),
"test3"
);
});
});
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.