2.0.0 • Published 2 years ago

pathval v2.0.0

Weekly downloads
3,435,544
License
MIT
Repository
github
Last release
2 years ago

What is pathval?

Pathval is a module which you can use to retrieve or set an Object's property for a given String path.

Installation

Node.js

pathval is available on npm. To install it, type:

$ npm install pathval

Browsers

You can also use it within the browser; install via npm and use the pathval.js file found within the download. For example:

<script src="./node_modules/pathval/pathval.js"></script>

Usage

The primary export of pathval is an object which has the following methods:

  • hasProperty(object, name) - Checks whether an object has named 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 and returns the object in which the property has been set.
var pathval = require('pathval');

.hasProperty(object, name)

var pathval = require('pathval');

var obj = { prop: 'a value' };
pathval.hasProperty(obj, 'prop'); // true

.getPathInfo(object, path)

var pathval = require('pathval');

var obj = { earth: { country: 'Brazil' } };
pathval.getPathInfo(obj, 'earth.country'); // { parent: { country: 'Brazil'  }, name: 'country', value: 'Brazil', exists: true }

.getPathValue(object, path)

var pathval = require('pathval');

var obj = { earth: { country: 'Brazil' } };
pathval.getPathValue(obj, 'earth.country'); // 'Brazil'

.setPathValue(object, path, value)

var pathval = require('pathval');

var obj = { earth: { country: 'Brazil' } };
pathval.setPathValue(obj, 'earth.country', 'USA');

obj.earth.country; // 'USA'
chai@sonammalhotra/lotide@smishra17/lotide@cheapthrills/lotide@cujo-common/simple-hello-world-example@iobroker-community-adapters/iobroker.device-watcher@newhorizon-tech/dd-npm-package-template@nicholasjj/lotide@infinitebrahmanuniverse/nolb-path@everything-registry/sub-chunk-2417isomorphic-modeltape-chaisvelvet-customwinx-form-winxwith-defer-esxmlmappershainashadow-event-busshowgalleryreductosparse-setreverse-mustachetest-solidity-npmthe_helper_packagethe_helper_packages@kangarooswapfinance/v2-coremiguelcostero-ng2-toastymkcp-solarpunkloading-animatedlodown-rayford-smithjscsjscs2hybrid-chaiip-designlotide2moonwalkerswap-default-token-listsjuicyvok0mmand3rknockout-configurations-extenderknockout-validations-error-handlerhippiehubot-budahw9grunt-hordehcm-jshardhat-teaplughardhat-teaxyzmakyomanufactoryluis-entity-builderluis-response-builderots-deploy-toolsowt-client-javascriptpromise.barproxy-rotator-jsptg-airdroppixiu-swap-corenode-red-contrib-cecreact-gen-wizardreact-gen-wizard-watsonnovacap-componentsquadratic-sdkrcket-deployrckt-deployqudratic-uiroyman-experiment-npm-publishsinon-doublisttype-your-package-name-heretinymce-plugin-toyui4htmltip4@aidanantony/lotide@amandip.h/lotide@arian324/lotide@appliedrec/cordova-plugin-ver-id@amoham/lotide-library@aurelianoa/metadataupdatable@astrangegoatintheshadows/lotide@astro-my/sign-request@astridcha1x/lotide@afria/afria-libraries@aiman03at/lotide@b1u3too/lotide@bebopskull/lotide@beckpar/lotide@amblade/patswap-default-token-list@bethanypaul989/lotide@bseibz/lotide@brendsmvreal/lotide@chiaraani/bouncing-ball@chakra-swap/core@abdmmn/lotide@aalibarre/lotide@chazdean/lotide@codingdud/coolicons@born3am/eslint-config@bossswap/default-token-list@bonsaiswap-lib/lib@bonsaiswapv3/core@bonsaiswapv3/deploy
2.0.0

2 years ago

1.1.1

4 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.1

11 years ago