Socket
Socket
Sign inDemoInstall

elem-dataset

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 2.0.0

index.js

76

dist/index.js
'use strict';
// <3 Modernizr
// https://raw.githubusercontent.com/Modernizr/Modernizr/master/feature-detects/dom/dataset.js
function useNative() {
var elem = document.createElement('div');
elem.setAttribute('data-a-b', 'c');
return Boolean(elem.dataset && elem.dataset.aB === 'c');
var elem = document.createElement('div');
elem.setAttribute('data-a-b', 'c');
return Boolean(elem.dataset && elem.dataset.aB === 'c');
}
function nativeDataset(element) {
return element.dataset;
return element.dataset;
}
module.exports = useNative() ? nativeDataset : function (element) {
var map = {};
var attributes = element.attributes;
var map = {};
var attributes = element.attributes;
function getter() {
return this.value;
}
function getter() {
return this.value;
}
function setter(name, value) {
if (typeof value === 'undefined') {
this.removeAttribute(name);
} else {
this.setAttribute(name, value);
}
}
function setter(name, value) {
if (typeof value === 'undefined') {
this.removeAttribute(name);
} else {
this.setAttribute(name, value);
}
}
for (var i = 0, j = attributes.length; i < j; i++) {
var attribute = attributes[i];
for (var i = 0, j = attributes.length; i < j; i++) {
var attribute = attributes[i];
if (attribute) {
var name = attribute.name;
if (attribute) {
var name = attribute.name;
if (name.indexOf('data-') === 0) {
var prop = name.slice(5).replace(/-./g, function (u) {
return u.charAt(1).toUpperCase();
});
if (name.indexOf('data-') === 0) {
var prop = name.slice(5).replace(/-./g, function (u) {
return u.charAt(1).toUpperCase();
});
var value = attribute.value;
Object.defineProperty(map, prop, {
enumerable: true,
get: getter.bind({
value: value || ''
}),
set: setter.bind(element, name)
});
}
}
}
var value = attribute.value;
Object.defineProperty(map, prop, {
enumerable: true,
get: getter.bind({ value: value || '' }),
set: setter.bind(element, name)
});
}
}
}
return map;
return map;
};
{
"name": "elem-dataset",
"version": "1.1.1",
"description": "Simple HTMLElement.dataset ponyfill",
"license": "MIT",
"repository": "awcross/elem-dataset",
"author": {
"name": "Alex Cross",
"url": "alexcross.io"
},
"main": "dist/index.js",
"keywords": [
"html",
"htmlelement",
"element",
"data",
"dataset",
"html5",
"polyfill",
"ponyfill",
"attributes",
"custom",
"property"
],
"scripts": {
"build": "npm test && npm run bundle && npm run minify",
"bundle": "node_modules/.bin/babel src/index.js > dist/index.js",
"minify": "node_modules/.bin/uglifyjs dist/index.js > dist/index.min.js -m",
"test": "xo && ava"
},
"devDependencies": {
"ava": "*",
"babel-cli": "^6.16.0",
"babel-preset-es2015": "^6.14.0",
"jsdom": "^9.6.0",
"uglify-js": "^2.7.3",
"xo": "*"
},
"babel": {
"presets": [
"es2015"
]
},
"xo": {
"esnext": true,
"envs": [
"browser",
"es6"
],
"rules": {
"padded-blocks": 0
}
}
"name": "elem-dataset",
"version": "2.0.0",
"description": "HTML5 HTMLElement.dataset ponyfill",
"license": "MIT",
"repository": "awcross/elem-dataset",
"author": {
"name": "Alex Cross",
"url": "https://alexcross.io"
},
"main": "dist/index.js",
"module": "index.js",
"files": [
"dist",
"index.js"
],
"keywords": [
"html",
"htmlelement",
"element",
"data",
"dataset",
"html5",
"polyfill",
"ponyfill",
"attr",
"attributes",
"custom",
"property"
],
"scripts": {
"clean": "rm -rf dist",
"build": "npm test && npm run bundle",
"bundle": "mkdir dist && babel index.js > dist/index.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"prepare": "npm run clean && npm run bundle",
"test": "xo && nyc ava"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"ava": "^1.2.1",
"coveralls": "^3.0.2",
"jsdom": "^13.2.0",
"nyc": "^13.2.0",
"xo": "^0.24.0"
},
"babel": {
"comments": false,
"presets": [
"@babel/preset-env"
]
},
"xo": {
"envs": [
"browser",
"es6"
],
"rules": {
"padded-blocks": 0
}
}
}

@@ -1,5 +0,6 @@

# elem-dataset
# elem-dataset [![Build Status](https://travis-ci.org/awcross/elem-dataset.svg?branch=master)](https://travis-ci.org/awcross/elem-dataset)
> Simple [ponyfill](https://ponyfill.com) for [`HTMLElement.dataset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset)
> HTML5 [`HTMLElement.dataset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) [ponyfill](https://ponyfill.com)
*Note that "true" and "false" values are [not allowed on boolean attributes](https://w3c.github.io/html/infrastructure.html#sec-boolean-attributes).*

@@ -15,6 +16,6 @@ ## Install

```js
import elemDataset from 'elem-dataset';
import elementDataset from 'elem-dataset';
const element = document.querySelector('.foo');
const attributes = elemDataset(element);
const attributes = elementDataset(element);
```

@@ -24,2 +25,2 @@

MIT © [Alex Cross](http://alexcross.io)
MIT © [Alex Cross](https://alexcross.io)
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc