{"name":"svg-react-loader","version":"0.4.0-beta.1","description":"A Webpack Loader to turn SVGs into React Components","main":"./lib/loader.js","directories":{"test":"test"},"scripts":{"test":"./bin/test.sh unit","karma":"./bin/test.sh karma"},"repository":{"type":"git","url":"git+https://github.com/jhamlet/svg-react-loader.git"},"keywords":["webpack","loader","react","svg","component"],"author":{"name":"Jerry Hamlet","email":"jerry@hamletink.com"},"license":"MIT","bugs":{"url":"https://github.com/jhamlet/svg-react-loader/issues"},"homepage":"https://github.com/jhamlet/svg-react-loader#readme","dependencies":{"css":"2.2.1","ramda":"0.21.0","rx":"4.1.0","traverse":"0.6.6","xml2js":"0.4.17"},"devDependencies":{"babel-core":"6.11.4","babel-loader":"6.2.4","babel-preset-es2015":"6.9.0","babel-preset-react":"6.11.1","enzyme":"2.4.1","karma":"1.1.2","karma-chrome-launcher":"1.0.1","karma-cli":"1.0.1","karma-mocha":"1.1.1","karma-mocha-reporter":"2.0.5","karma-sourcemap-loader":"0.3.7","karma-webpack":"1.7.0","loader-utils":"0.2.15","mocha":"2.5.3","react":"15.2.1","react-addons-test-utils":"15.2.1","react-dom":"15.2.1","should":"9.0.2","webpack":"1.13.1","webpack-dev-server":"1.14.1"},"contributors":[{"name":"Jerry Hamlet","email":"jerry@hamletink.com","url":"http://hamletink.com/"}],"gitHead":"0778b9f04e7c1f9ebb676e14b0cba6d6ba35dde5","_id":"svg-react-loader@0.4.0-beta.1","_shasum":"41fb7f8e8451f5dbe4c81375d296340ed2e30862","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"jhamlet","email":"jerry@hamletink.com"},"dist":{"shasum":"41fb7f8e8451f5dbe4c81375d296340ed2e30862","tarball":"http://registry-npm.ywwl.com/svg-react-loader/download/svg-react-loader-0.4.0-beta.1.tgz","integrity":"sha512-+kliSZYMPeDVOKoeqCAi6902Nuh6HlPnP9gCrlnO66HXBAfp8oVdQaL7GLc0dMWiZwyPXoOGJCyXQhFoGe09KA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICPEi1NvZQKheHGe5yPUa/NGQic2iu9OoyPCMFTjclufAiEAyIp2W8KYCk8C/dZ1wNIUjOytsHASHOXdJnB4YubyG/o="}],"size":8398,"noattachment":false,"key":"/svg-react-loader/-/svg-react-loader-0.4.0-beta.1.tgz"},"maintainers":[{"name":"jhamlet","email":"jerry@hamletink.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/svg-react-loader-0.4.0-beta.1.tgz_1469900693214_0.6636499587912112"},"readme":"SVG to React Loader\n===================\n\n> A Webpack Loader to turn SVGs into React Components\n\nSummary\n-------\n\nA webpack loader allowing for inline usage of a SVG as a React component, or for\ncomposing individual SVGs into larger ones.\n\nThe latest version has been refactored to allow for receiving an SVG/XML string\nor an JSON [object-tree](#object-tree-api) representing an SVG. This allows for\nother loaders before `svg-react` to alter/update/remove nodes before reaching\n`svg-react`.\n\nIn addition, the new [filters](#filters) API allows for additional ways to\nmodify the generated SVG Component. This allows `svg-react` to also be used as a\npre-loader (with `filters` and `raw=true` params) for modifying SVGs before they\nare acted on by the loader version of `svg-react`.\n\n### Notes\n\n> As of version 0.4.0, `svg-react-loader` no longer requires `babel` to\n> transpile the generated code. Everything is returned as an ES5-7 compatible\n> module, and the component is just a\n> [function](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions).\n> With that, it only works with React@>=0.14\n\n\nInstallation\n------------\n\n~~~\n% npm install --save-dev svg-react-loader\n~~~\n\n\nUsage\n-----\n\nES6+ (Assuming a `babel-loader` is used on `/\\.jsx?$/` files):\n\n~~~js\nimport React, { Component } from 'react';\nimport Icon from 'svg-react-loader?name=Icon!../svg/my-icon.svg';\n\nexport default class MyIcon extends Component {\n    render () {\n        return <Icon className='normal' />;\n    }\n};\n~~~\n\nES5\n\n~~~js\nvar React = require('react');\nvar Icon = require('svg-react-loader?name=Icon!../svg/my-icon.svg');\n\nmodule.exports = React.createClass({\n    render () {\n        return React.createElement(Icon, { className: 'normal' });\n    }\n});\n~~~\n\n\nDocumentation\n-------------\n\n### Query Params\n\nQuery params can be used on the loader path, or on the resource's path. Those on\nthe resource will override those given for the loader.\n\n* `name`: `displayName` to use for the compiled component. Defaults to using the\n  resource's file name, capitalized and camelCased. ex. `\"?name=MyIcon\"`\n\n* `tag`: Override the root-level tag name.\n\n* `props`: Attributes to apply to the root-level tag. If a certain attribute is\n  already assigned to the tag, the value here will override that.\n\n* `attrs`: Alias for `props`\n\n* `filters`: If given on the query string, it is a list of module names, or\n  filepaths, to load as [filter functions](#filters). If given in the webpack\n  config as a `svgReactLoader.filters`, or as `query.filters` for the loader\n  configuration object, it is an array of functions.\n\n* `classIdPrefix`: A string to prefix all class or id selectors in found style\n  blocks, or within `className` properties, with. If indicated without a string,\n  the file's basename will be used as a prefix.\n\n* `raw`: If set to `true` will output the parsed object tree repesenting the SVG\n  as a JSON string. Otherwise, returns a string of JavaScript that represents\n  the component's module.\n\n* `propsMap`: If given on the query string, it is an array of colon separated\n  `propname:translatedname` pairs. If given in the webpack configuration as\n  `svgReactLoader.propsMap`, or in an object query for the loader configuration,\n  is a simple object of `propname: 'translatedname'`\n\n* `xmlnsTest`: A regular expression used to remove non-supported xmlns\n  attributes. Default is `/^xmlns(Xlink)?$/`\n\n* `titleCaseDelim`: A regular expression used to generate component's name. It\n  would be ignore if `name` was set.\n  Default is `/[._-]/`\n\n### Examples\n#### Webpack 1\n\n~~~js\n// webpack configuration\nmodule: {\n    loaders: [\n        {\n            test: /\\.svg$/,\n            exclude: /node_modules/,\n            loader: 'svg-react-loader',\n            query: {\n                classIdPrefix: '[name]-[hash:8]__',\n                filters: [\n                    function (value) {\n                        // ...\n                        this.update(newvalue);\n                    }\n                ],\n                propsMap: {\n                    fillRule: 'fill-rule',\n                    foo: 'bar'\n                },\n                xmlnsTest: /^xmlns.*$/\n            }\n        }\n    ]\n}\n\n// Resource paths\nimport MyIcon from 'svg-react-loader?name=MyIcon!../svg/icon.svg';\nimport MyIcon from 'svg-react-loader?tag=symbol!../svg/icon.svg';\nimport MyIcon from 'svg-react-loader?tag=symbol&props[]=id:my-icon?../svg/icon.svg';\nimport MyIcon from 'svg-react-loader?filters[]=./my-filter.js!../svg/icon.svg';\n~~~\n\n#### Webpack 2-3\n\n~~~js\n// webpack configuration\nmodule: {\n    loaders: [\n        {\n            test: /\\.svg$/,\n            exclude: /node_modules/,\n            use: {\n                loader: 'svg-react-loader',\n                options: {\n                    tag: 'symbol',\n                    attrs: {\n                        title: 'example',\n                    },\n                    name: 'MyIcon',\n                },\n            },\n        }\n    ]\n}\n\n// Resource paths\nimport MyIcon from '../svg/icon.svg';\n~~~\n\n### Object Tree API\n\nInternally, `svg-react-loader` converts the given SVG/XML into an object tree\nthat looks something like:\n\n~~~js\n{\n    \"tagname\": \"svg\",\n    \"props\": {\n        \"xmlns\": \"http://www.w3.org/2000/svg\",\n        \"xmlns:xlink\": \"http://www.w3.org/1999/xlink\",\n        \"viewBox\": \"0 0 16 16\",\n        \"enable-background\": \"new 0 0 16 16\",\n        \"xml:space\": \"preserve\"\n    },\n    \"children\": [\n        {\n            \"tagname\": \"rect\",\n            \"props\": {\n                \"x\": \"0\",\n                \"y\": \"0\",\n                \"width\": \"16\",\n                \"height\": \"16\",\n                \"fill\": \"#fff\"\n            }\n        },\n        {\n            \"tagname\": \"text\",\n            \"children\": [\"Foobar\"]\n        }\n    ]\n}\n~~~\n\nIt then uses a variety of [filters](#filters) to modify the tree to conform to\nhow `React` expects to see props, styles, etc...\n\nIf `svg-react-loader` receives a JSON string instead of string of SVG/XML, it\nexpects to receive it in the above format (i.e.: objects with properties\n'tagname', 'props', and 'children'). Children is always an array (unless empty),\nand children can be objects with the mentioned props, or a plain string (for\ntext nodes).\n\n### Filters\n\nA filter is just a function that accepts one value, and it has the same `this`\ncontext as the [traverse](https://www.npmjs.com/package/traverse) API.\n\n`svg-react-loader` is really just a series of filters applied to a parsed\nSVG/XML, or JSON, string and then regenerated as a string to form a React\nfunctional component.\n\nReview [lib/sanitize/filters](lib/sanitize/filters) for some examples.\n\nReport an Issue\n---------------\n\n* [Bugs](http://github.com/jhamlet/svg-react-loader/issues)\n* Contact the author: <jerry@hamletink.com>\n\n\nLicense\n-------\n\n[MIT](./LICENSE)\n","publish_time":1469900693477,"_cnpm_publish_time":1469900693477,"dist-tags":{"latest":"0.4.6","next":"0.4.0-beta.2","unstable":"0.4.0-beta.1"}}