File: //opt/code/node_modules/autoprefixer/node_modules/postcss-value-parser/package.json
{
"name": "postcss-value-parser",
"version": "3.3.0",
"description": "Transforms css values and at-rule params into the tree",
"main": "lib/index.js",
"files": [
"lib"
],
"devDependencies": {
"eslint": "^2.1.0",
"eslint-config-postcss": "^2.0.0",
"tap-spec": "^4.1.0",
"tape": "^4.2.0"
},
"scripts": {
"test": "tape test/*.js | tap-spec",
"posttest": "eslint ."
},
"eslintConfig": {
"extends": "postcss/es5",
"rules": {
"max-len": 0,
"no-bitwise": 0,
"complexity": 0,
"no-use-before-define": 0,
"consistent-return": 0
}
},
"author": {
"name": "Bogdan Chadkin",
"email": "trysound@yandex.ru"
},
"license": "MIT",
"homepage": "https://github.com/TrySound/postcss-value-parser",
"repository": {
"type": "git",
"url": "https://github.com/TrySound/postcss-value-parser.git"
},
"keywords": [
"postcss",
"value",
"parser"
],
"bugs": {
"url": "https://github.com/TrySound/postcss-value-parser/issues"
},
"readme": "# postcss-value-parser\r\n\r\n[](https://travis-ci.org/TrySound/postcss-value-parser)\r\n\r\nTransforms CSS declaration values and at-rule parameters into a tree of nodes, and provides a simple traversal API.\r\n\r\n## Usage\r\n\r\n```js\r\nvar valueParser = require('postcss-value-parser');\r\nvar cssBackgroundValue = 'url(foo.png) no-repeat 40px 73%';\r\nvar parsedValue = valueParser(cssBackgroundValue);\r\n// parsedValue exposes an API described below,\r\n// e.g. parsedValue.walk(..), parsedValue.toString(), etc.\r\n```\r\n\r\nFor example, parsing the value `rgba(233, 45, 66, .5)` will return the following:\r\n\r\n```js\r\n{\r\n nodes: [\r\n {\r\n type: 'function',\r\n value: 'rgba',\r\n before: '',\r\n after: '',\r\n nodes: [\r\n { type: 'word', value: '233' },\r\n { type: 'div', value: ',', before: '', after: ' ' },\r\n { type: 'word', value: '45' },\r\n { type: 'div', value: ',', before: '', after: ' ' },\r\n { type: 'word', value: '66' },\r\n { type: 'div', value: ',', before: ' ', after: '' },\r\n { type: 'word', value: '.5' }\r\n ]\r\n }\r\n ]\r\n}\r\n```\r\n\r\nIf you wanted to convert each `rgba()` value in `sourceCSS` to a hex value, you could do so like this:\r\n\r\n```js\r\nvar valueParser = require('postcss-value-parser');\r\n\r\nvar parsed = valueParser(sourceCSS);\r\n\r\n// walk() will visit all the of the nodes in the tree,\r\n// invoking the callback for each.\r\nparsed.walk(function (node) {\r\n\r\n // Since we only want to transform rgba() values,\r\n // we can ignore anything else.\r\n if (node.type !== 'function' && node.value !== 'rgba') return;\r\n\r\n // We can make an array of the rgba() arguments to feed to a\r\n // convertToHex() function\r\n var color = node.nodes.filter(function (node) {\r\n return node.type === 'word';\r\n }).map(function (node) {\r\n return Number(node.value);\r\n }); // [233, 45, 66, .5]\r\n\r\n // Now we will transform the existing rgba() function node\r\n // into a word node with the hex value\r\n node.type = 'word';\r\n node.value = convertToHex(color);\r\n})\r\n\r\nparsed.toString(); // #E92D42\r\n```\r\n\r\n## Nodes\r\n\r\nEach node is an object with these common properties:\r\n\r\n- **type**: The type of node (`word`, `string`, `div`, `space`, `comment`, or `function`).\r\n Each type is documented below.\r\n- **value**: Each node has a `value` property; but what exactly `value` means\r\n is specific to the node type. Details are documented for each type below.\r\n- **sourceIndex**: The starting index of the node within the original source\r\n string. For example, given the source string `10px 20px`, the `word` node\r\n whose value is `20px` will have a `sourceIndex` of `5`.\r\n\r\n### word\r\n\r\nThe catch-all node type that includes keywords (e.g. `no-repeat`),\r\nquantities (e.g. `20px`, `75%`, `1.5`), and hex colors (e.g. `#e6e6e6`).\r\n\r\nNode-specific properties:\r\n\r\n- **value**: The \"word\" itself.\r\n\r\n### string\r\n\r\nA quoted string value, e.g. `\"something\"` in `content: \"something\";`.\r\n\r\nNode-specific properties:\r\n\r\n- **value**: The text content of the string.\r\n- **quote**: The quotation mark surrounding the string, either `\"` or `'`.\r\n- **unclosed**: `true` if the string was not closed properly. e.g. `\"unclosed string `.\r\n\r\n### div\r\n\r\nA divider, for example\r\n\r\n- `,` in `animation-duration: 1s, 2s, 3s`\r\n- `/` in `border-radius: 10px / 23px`\r\n- `:` in `(min-width: 700px)`\r\n\r\nNode-specific properties:\r\n\r\n- **value**: The divider character. Either `,`, `/`, or `:` (see examples above).\r\n- **before**: Whitespace before the divider.\r\n- **after**: Whitespace after the divider.\r\n\r\n### space\r\n\r\nWhitespace used as a separator, e.g. ` ` occurring twice in `border: 1px solid black;`.\r\n\r\nNode-specific properties:\r\n\r\n- **value**: The whitespace itself.\r\n\r\n### comment\r\n\r\nA CSS comment starts with `/*` and ends with `*/`\r\n\r\nNode-specific properties:\r\n\r\n- **value**: The comment value without `/*` and `*/`\r\n- **unclosed**: `true` if the comment was not closed properly. e.g. `/* comment without an end `.\r\n\r\n### function\r\n\r\nA CSS function, e.g. `rgb(0,0,0)` or `url(foo.bar)`.\r\n\r\nFunction nodes have nodes nested within them: the function arguments.\r\n\r\nAdditional properties:\r\n\r\n- **value**: The name of the function, e.g. `rgb` in `rgb(0,0,0)`.\r\n- **before**: Whitespace after the opening parenthesis and before the first argument,\r\n e.g. ` ` in `rgb( 0,0,0)`.\r\n- **after**: Whitespace before the closing parenthesis and after the last argument,\r\n e.g. ` ` in `rgb(0,0,0 )`.\r\n- **nodes**: More nodes representing the arguments to the function.\r\n- **unclosed**: `true` if the parentheses was not closed properly. e.g. `( unclosed-function `.\r\n\r\nMedia features surrounded by parentheses are considered functions with an\r\nempty value. For example, `(min-width: 700px)` parses to these nodes:\r\n\r\n```js\r\n[\r\n {\r\n type: 'function', value: '', before: '', after: '',\r\n nodes: [\r\n { type: 'word', value: 'min-width' },\r\n { type: 'div', value: ':', before: '', after: ' ' },\r\n { type: 'word', value: '700px' }\r\n ]\r\n }\r\n]\r\n```\r\n\r\n`url()` functions can be parsed a little bit differently depending on\r\nwhether the first character in the argument is a quotation mark.\r\n\r\n`url( /gfx/img/bg.jpg )` parses to:\r\n\r\n```js\r\n{ type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [\r\n { type: 'word', sourceIndex: 5, value: '/gfx/img/bg.jpg' }\r\n] }\r\n```\r\n\r\n`url( \"/gfx/img/bg.jpg\" )`, on the other hand, parses to:\r\n\r\n```js\r\n{ type: 'function', sourceIndex: 0, value: 'url', before: ' ', after: ' ', nodes: [\r\n type: 'string', sourceIndex: 5, quote: '\"', value: '/gfx/img/bg.jpg' },\r\n] }\r\n```\r\n\r\n## API\r\n\r\n```\r\nvar valueParser = require('postcss-value-parser');\r\n```\r\n\r\n### valueParser.unit(quantity)\r\n\r\nParses `quantity`, distinguishing the number from the unit. Returns an object like the following:\r\n\r\n```js\r\n// Given 2rem\r\n{\r\n number: '2',\r\n unit: 'rem'\r\n}\r\n```\r\n\r\nIf the `quantity` argument cannot be parsed as a number, returns `false`.\r\n\r\n*This function does not parse complete values*: you cannot pass it `1px solid black` and expect `px` as\r\nthe unit. Instead, you should pass it single quantities only. Parse `1px solid black`, then pass it\r\nthe stringified `1px` node (a `word` node) to parse the number and unit.\r\n\r\n### valueParser.stringify(nodes[, custom])\r\n\r\nStringifies a node or array of nodes.\r\n\r\nThe `custom` function is called for each `node`; return a string to override the default behaviour.\r\n\r\n### valueParser.walk(nodes, callback[, bubble])\r\n\r\nWalks each provided node, recursively walking all descendent nodes within functions.\r\n\r\nReturning `false` in the `callback` will prevent traversal of descendent nodes (within functions).\r\nYou can use this feature to for shallow iteration, walking over only the *immediate* children.\r\n*Note: This only applies if `bubble` is `false` (which is the default).*\r\n\r\nBy default, the tree is walked from the outermost node inwards.\r\nTo reverse the direction, pass `true` for the `bubble` argument.\r\n\r\nThe `callback` is invoked with three arguments: `callback(node, index, nodes)`.\r\n\r\n- `node`: The current node.\r\n- `index`: The index of the current node.\r\n- `nodes`: The complete nodes array passed to `walk()`.\r\n\r\nReturns the `valueParser` instance.\r\n\r\n### var parsed = valueParser(value)\r\n\r\nReturns the parsed node tree.\r\n\r\n### parsed.nodes\r\n\r\nThe array of nodes.\r\n\r\n### parsed.toString()\r\n\r\nStringifies the node tree.\r\n\r\n### parsed.walk(callback[, bubble])\r\n\r\nWalks each node inside `parsed.nodes`. See the documentation for `valueParser.walk()` above.\r\n\r\n# License\r\n\r\nMIT © [Bogdan Chadkin](mailto:trysound@yandex.ru)\r\n",
"readmeFilename": "README.md",
"_id": "postcss-value-parser@3.3.0",
"dist": {
"shasum": "93fc2baf6cd39271379c6db9e8fe4327d9617585"
},
"_from": "postcss-value-parser@^3.2.3",
"_resolved": "http://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-3.3.0.tgz"
}