{"_id":"posthtml-attrs-parser","_rev":"366575","name":"posthtml-attrs-parser","description":"PostHTML helper that gives a better API to work with tag's attrs","dist-tags":{"latest":"0.1.1"},"maintainers":[{"name":"maltsev","email":"maltsevkirill@gmail.com"},{"name":"scrum","email":"scrum@list.ru"}],"time":{"modified":"2021-07-19T07:29:07.000Z","created":"2015-12-10T15:05:52.986Z","0.1.1":"2016-01-04T22:25:00.605Z","0.1.0":"2015-12-10T15:05:52.986Z"},"users":{},"author":{"name":"Kirill Maltsev","email":"maltsevkirill@gmail.com"},"repository":{"type":"git","url":"git://github.com/maltsev/posthtml-attrs-parser.git"},"versions":{"0.1.1":{"name":"posthtml-attrs-parser","version":"0.1.1","description":"PostHTML helper that gives a better API to work with tag's attrs","main":"index.js","author":{"name":"Kirill Maltsev","email":"maltsevkirill@gmail.com"},"license":"MIT","scripts":{"compile":"rm -f lib/*.js && node_modules/.bin/babel -d lib/ lib/","lint":"eslint *.js lib/*.es6 test/","pretest":"npm run lint && npm run compile","test":"_mocha --compilers js:babel-core/register","prepublish":"npm run compile"},"keywords":["posthtml","posthtml-plugin","html","postproccessor","parser"],"babel":{"presets":["es2015"]},"dependencies":{"object-assign":"^4.0.1"},"devDependencies":{"babel-cli":"^6.3.15","babel-core":"^6.3.15","babel-eslint":"^4.1.6","babel-preset-es2015":"^6.3.13","eslint":"^1.10.3","expect":"^1.13.0","mocha":"^2.3.4","posthtml":"^0.8.0"},"repository":{"type":"git","url":"git://github.com/maltsev/posthtml-attrs-parser.git"},"bugs":{"url":"https://github.com/maltsev/posthtml-attrs-parser/issues"},"homepage":"https://github.com/maltsev/posthtml-attrs-parser","gitHead":"085bfc2ea5d1d004cc8b4f091420f072425fb506","_id":"posthtml-attrs-parser@0.1.1","_shasum":"cc33e00155fb99ba96f67e25e330461f05742ac8","_from":".","_npmVersion":"2.7.6","_nodeVersion":"1.7.1","_npmUser":{"name":"maltsev","email":"maltsevkirill@gmail.com"},"dist":{"shasum":"cc33e00155fb99ba96f67e25e330461f05742ac8","size":3878,"noattachment":false,"key":"/posthtml-attrs-parser/-/posthtml-attrs-parser-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/posthtml-attrs-parser/download/posthtml-attrs-parser-0.1.1.tgz"},"maintainers":[{"name":"maltsev","email":"maltsevkirill@gmail.com"},{"name":"scrum","email":"scrum@list.ru"}],"directories":{},"publish_time":1451946300605,"_cnpm_publish_time":1451946300605,"_hasShrinkwrap":false},"0.1.0":{"name":"posthtml-attrs-parser","version":"0.1.0","description":"PostHTML helper that gives a better API to work with tag's attrs","main":"index.js","author":{"name":"Kirill Maltsev","email":"maltsevkirill@gmail.com"},"license":"MIT","scripts":{"compile":"rm -f lib/*.js && node_modules/.bin/babel -d lib/ lib/","lint":"eslint *.js lib/*.es6 test/","pretest":"npm run lint && npm run compile","test":"_mocha --compilers js:babel-core/register","prepublish":"npm run compile"},"keywords":["posthtml","posthtml-plugin","html","postproccessor","parser"],"babel":{"presets":["es2015"]},"dependencies":{"object-assign":"^4.0.1"},"devDependencies":{"babel-cli":"^6.3.15","babel-core":"^6.3.15","babel-eslint":"^4.1.6","babel-preset-es2015":"^6.3.13","eslint":"^1.10.3","expect":"^1.13.0","mocha":"^2.3.4","posthtml":"^0.8.0"},"repository":{"type":"git","url":"git://github.com/maltsev/posthtml-attrs-parser.git"},"bugs":{"url":"https://github.com/maltsev/posthtml-attrs-parser/issues"},"homepage":"https://github.com/maltsev/posthtml-attrs-parser","gitHead":"bae45dee815f866838ff80b67b35822a46003d37","_id":"posthtml-attrs-parser@0.1.0","_shasum":"27cb7ba3866ef9b33dcfa08d4855eb6873fc290b","_from":".","_npmVersion":"2.7.6","_nodeVersion":"1.7.1","_npmUser":{"name":"maltsev","email":"maltsevkirill@gmail.com"},"dist":{"shasum":"27cb7ba3866ef9b33dcfa08d4855eb6873fc290b","size":3738,"noattachment":false,"key":"/posthtml-attrs-parser/-/posthtml-attrs-parser-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/posthtml-attrs-parser/download/posthtml-attrs-parser-0.1.0.tgz"},"maintainers":[{"name":"maltsev","email":"maltsevkirill@gmail.com"},{"name":"scrum","email":"scrum@list.ru"}],"directories":{},"publish_time":1449759952986,"_cnpm_publish_time":1449759952986,"_hasShrinkwrap":false}},"readme":"# PostHTML Attrs Parser\n[![npm version](https://badge.fury.io/js/posthtml-attrs-parser.svg)](http://badge.fury.io/js/posthtml-attrs-parser)\n[![Build Status](https://travis-ci.org/maltsev/posthtml-attrs-parser.svg?branch=master)](https://travis-ci.org/maltsev/posthtml-attrs-parser)\n\n[PostHTML](https://github.com/posthtml/posthtml) helper that gives a better API to work with tag's attrs.\n\n\n## Usage\n```js\nvar posthtml = require('posthtml'),\n    parseAttrs = require('posthtml-attrs-parser');\n\nposthtml()\n    .use(function (tree) {\n        var div = tree[0],\n            attrs = parseAttrs(div.attrs);\n\n        attrs.style['font-size'] = '15px';\n        attrs.class.push('title-sub');\n\n\t\t// Compose attrs back to PostHTML-compatible format\n        div.attrs = attrs.compose();\n    })\n    .process('<div class=\"title\" style=\"font-size: 14px\">Hello!</div>')\n    .then(function (result) {\n        console.log(result.html);\n    });\n\n// <div class=\"title title-sub\" style=\"font-size: 15px\">Hello!</div>\n```\n\n\n## Attributes\nOnly `style` and `class` attributes are parsed by default (as object and array, respectively).\nFor other attributes the parsing rules should be specified (see \"Custom parsing rule\" below).\n\n\n### Default attributes\n#### `style`\n```js\n// <div style=\"color: red; font-size: 14px; color: blue\"></div>\nvar attrs = parseAttrs(div.attrs);\nconsole.log(attrs.style);\n/*\n{\n    // If there is several properties with the same name,\n    // then the values are packed in array\n    'color': ['red', 'blue'],\n    'font-size': '14px'\n}\n*/\n```\n\n\n#### `class`\n```js\n// <div class=\"title title-sub\"></div>\nvar attrs = parseAttrs(div.attrs);\nconsole.log(attrs.class);\n// ['title', 'title-sub']\n```\n\n\n### Custom parsing rule\nYou can also define the parsing rule for other attributes.\n\n#### Array-like attribute\n```js\n// <div data-ids=\"1  2 4 5   6\"></div>\nvar attrs = parseAttrs(div.attrs, {\n    rules: {\n\t\t'data-ids': {\n\t\t\tdelimiter: /\\s+/,\n            // Optional parameter for stringifying attribute's values\n            // If not set, glue = delimiter\n\t\t\tglue: ' '\n\t\t}\n\t}\n});\nconsole.log(attrs['data-ids']);\n// ['1', '2', '4', '5', '6']\n\nconsole.log(attrs.compose()['data-ids']);\n// 1 2 3 4 5 6\n```\n\n\n#### Object-like attribute\n```js\n// <div data-config=\"TEST=1;ENV=debug;PATH=.\"></div>\nvar attrs = parseAttrs(div.attrs, {\n\trules: {\n\t\t'data-config': {\n            // Delimiter for key-value pairs\n\t\t\tdelimiter: ';',\n            // Delimiter for a key-value\n\t\t\tkeyDelimiter: '=',\n\n            // Optional parameter for stringifying key-value pairs\n            // If not set, keyGlue = keyDelimiter\n\t\t\tglue: '; ',\n            // Optional parameter for stringifying a key-value\n            // If not set, glue = delimiter\n            keyGlue: ' = '\n\t\t}\n\t}\n});\nconsole.log(attrs['data-config']);\n// {TEST: '1', ENV: 'debug', PATH: '.'}\n\nconsole.log(attrs.compose()['data-config']);\n// TEST = 1; ENV = debug; PATH = .\n```\n","_attachments":{},"homepage":"https://github.com/maltsev/posthtml-attrs-parser","bugs":{"url":"https://github.com/maltsev/posthtml-attrs-parser/issues"},"license":"MIT"}