{"name":"svg-react-loader","fullname":"SVG to React","description":"Webpack SVG to React Component Loader","version":"0.0.0","keywords":["webpack","loader","react","svg","component"],"main":"./index.js","dependencies":{"xml2js":"0.4.x","lodash":"3.x"},"devDependencies":{"mocha":"2.x","should":"6.x","del":"*","gulp":"3.x","gulp-util":"*","gulp-ejs":"*","gulp-concat":"*"},"scripts":{"build":"gulp","clobber":"gulp clobber","test":"mocha -R spec test/test-*.js"},"licenses":[{"type":"MIT","url":"http://github.com/jhamlet/svg-react-loader/raw/master/LICENSE"}],"repository":{"type":"git","url":"http://github.com/jhamlet/svg-react-loader.git"},"bugs":{"url":"http://github.com/jhamlet/svg-react-loader/issues"},"contributors":[{"name":"Jerry Hamlet","email":"jerry@hamletink.com","url":"http://hamletink.com/"}],"homepage":"https://github.com/jhamlet/svg-react-loader","_id":"svg-react-loader@0.0.0","dist":{"shasum":"912e3a8426df7af54e90daf595c03b6ccf5afb03","tarball":"http://registry-npm.ywwl.com/svg-react-loader/download/svg-react-loader-0.0.0.tgz","integrity":"sha512-+4aFaa86SHRzBwVAfjs/us+SFQzJVVgEkX5QhPMsqO5fA2sbONMVI/OctOUws7UhKbqD09GCuteLGpTa5ZwyKA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAd6sPA8Puvu5WLkyOfKnyKpwyY8UzlRjyej9oOOGmhKAiEAxpXP1jgQht7LcaamrhUO95HLi4DLFmX8lclSDDCwOEE="}],"size":1866,"noattachment":false,"key":"/svg-react-loader/-/svg-react-loader-0.0.0.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"jhamlet","email":"jerry@hamletink.com"},"maintainers":[{"name":"jhamlet","email":"jerry@hamletink.com"}],"deprecated":"Versions of svg-react-loader < 0.4.3 are no longer supported. Upgrade to a version >= 0.4.3","directories":{},"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":1439594352413,"_cnpm_publish_time":1439594352413,"dist-tags":{"latest":"0.4.6","next":"0.4.0-beta.2","unstable":"0.4.0-beta.1"}}