New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

accessor

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

accessor - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

tests/path-tests.js

31

index.js

@@ -0,1 +1,3 @@

var getAtPath = require('get-at-path');
function Accessor() {

@@ -23,4 +25,5 @@ var cachedAccessors = {

property = prop;
}
else {
} else if (typeof prop === 'object' && typeof prop.path === 'string') {
property = prop.path.split('/');
} else {
property = '' + prop;

@@ -38,16 +41,24 @@ }

function createAccessor(property, defaultValue) {
return function accessProperty(d) {
return accessProperty;
function accessProperty(d) {
if (typeof d === 'object') {
var value = d[property];
var value = getPropFromObject(d, property);
if (value === undefined) {
return defaultValue;
} else {
return value;
}
else {
return d[property];
}
}
else {
} else {
return defaultValue;
}
};
}
function getPropFromObject(d, prop) {
if (typeof prop === 'string') {
return d[prop];
} else if (Array.isArray(prop)) {
return getAtPath(d, prop);
}
}
}

@@ -54,0 +65,0 @@ }

{
"name": "accessor",
"version": "2.0.0",
"version": "2.1.0",
"description": "Provides accessor functions for convenience in D3 programming",

@@ -25,5 +25,7 @@ "main": "index.js",

"devDependencies": {
"tape": "^3.0.3"
"tape": "^4.10.1"
},
"dependencies": {}
"dependencies": {
"get-at-path": "^1.0.1"
}
}

@@ -25,2 +25,8 @@ accessor

If you want to write accessors that traverse a path in an object to get properties, do this:
thingElements.text(accessor({ path: 'data/meta/label'));
That will make it look for an object named `data`, then look for an object named `meta` in that, then look for a property named `label` within that. If you need to traverse arrays you can use array indexes in the path, e.g. `data/list/3/label`.
Installation

@@ -27,0 +33,0 @@ ------------

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc