DefinitelyTyped/types/get-value/get-value-tests.ts
Daniel Rosenwasser c448d9b017 Added 'get-value'.
2018-02-17 10:32:58 -08:00

23 lines
573 B
TypeScript

import get = require("get-value");
const obj = { a: { b: { c: { d: "foo" } } } };
get(obj);
get(obj, "a");
get(obj, "a.b");
get(obj, "a.b.c");
get(obj, "a.b.c.d");
{
const isEnumerable = Object.prototype.propertyIsEnumerable;
const options: get.Options = {
isValid: (key, obj) => isEnumerable.call(obj, key) || typeof obj[key] === "string",
};
const obj = {};
Object.defineProperty(obj, 'foo', { value: 'bar', enumerable: false });
get(obj, 'foo', options);
get({}, 'hasOwnProperty', options);
get({}, 'constructor', options);
}