motion
Version:
motion - moving development forward
70 lines (69 loc) • 7.45 kB
JSON
{
"_args": [
[
"loader-utils@https://registry.npmjs.org/loader-utils/-/loader-utils-0.2.12.tgz",
"/Users/nw/flint/packages/flint"
]
],
"_from": "loader-utils@>=0.2.2 <0.3.0",
"_id": "loader-utils@0.2.12",
"_inCache": true,
"_location": "/loader-utils",
"_phantomChildren": {},
"_requested": {
"name": "loader-utils",
"raw": "loader-utils@https://registry.npmjs.org/loader-utils/-/loader-utils-0.2.12.tgz",
"rawSpec": "https://registry.npmjs.org/loader-utils/-/loader-utils-0.2.12.tgz",
"scope": null,
"spec": "https://registry.npmjs.org/loader-utils/-/loader-utils-0.2.12.tgz",
"type": "remote"
},
"_requiredBy": [
"/css-loader",
"/file-loader",
"/style-loader",
"/url-loader",
"/webpack"
],
"_resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-0.2.12.tgz",
"_shasum": "faa2a501563a3c2c9dda57aa8c39d8be628de7a2",
"_shrinkwrap": null,
"_spec": "loader-utils@https://registry.npmjs.org/loader-utils/-/loader-utils-0.2.12.tgz",
"_where": "/Users/nw/flint/packages/flint",
"author": {
"name": "Tobias Koppers @sokra"
},
"bugs": {
"url": "https://github.com/webpack/loader-utils/issues"
},
"dependencies": {
"big.js": "^3.0.2",
"json5": "^0.4.0"
},
"description": "utils for webpack loaders",
"devDependencies": {
"coveralls": "^2.11.2",
"istanbul": "^0.3.14",
"mocha": "^1.21.4"
},
"files": [
"index.js"
],
"homepage": "https://github.com/webpack/loader-utils#readme",
"license": "MIT",
"name": "loader-utils",
"optionalDependencies": {},
"readme": "# loader-utils\r\n\r\n## Methods\r\n\r\n### `parseQuery`\r\n\r\n``` javascript\r\nvar query = loaderUtils.parseQuery(this.query);\r\nassert(typeof query == \"object\");\r\nif(query.flag)\r\n\t// ...\r\n```\r\n\r\n``` text\r\nnull -> {}\r\n? -> {}\r\n?flag -> { flag: true }\r\n?+flag -> { flag: true }\r\n?-flag -> { flag: false }\r\n?xyz=test -> { xyz: \"test\" }\r\n?xyz[]=a -> { xyz: [\"a\"] }\r\n?flag1&flag2 -> { flag1: true, flag2: true }\r\n?+flag1,-flag2 -> { flag1: true, flag2: false }\r\n?xyz[]=a,xyz[]=b -> { xyz: [\"a\", \"b\"] }\r\n?a%2C%26b=c%2C%26d -> { \"a,&b\": \"c,&d\" }\r\n?{json:5,data:{a:1}} -> { json: 5, data: { a: 1 } }\r\n```\r\n\r\n### `stringifyRequest`\r\n\r\nMakes a request pretty and stringifies it. Absolute paths are replaced with relative ones.\r\n\r\nUse it instead of `JSON.stringify(...)` to build code of a `require(...)` call in a loader.\r\n\r\n``` javascript\r\nloaderUtils.stringifyRequest(this, require.resolve(\"./test\"));\r\n// = \"../node_modules/some-loader/lib/test.js\"\r\n```\r\n\r\n### `urlToRequest`\r\n\r\nConverts some resource URL to a webpack module request.\r\n\r\n```javascript\r\nvar url = \"path/to/module.js\";\r\nvar request = loaderUtils.urlToRequest(url); // \"./path/to/module.js\"\r\n```\r\n\r\n#### Module URLs\r\n\r\nAny URL containing a `~` will be interpreted as a module request. Anything after the `~` will be considered the request path.\r\n\r\n```javascript\r\nvar url = \"~path/to/module.js\";\r\nvar request = loaderUtils.urlToRequest(url); // \"path/to/module.js\"\r\n```\r\n\r\n#### Root-relative URLs\r\n\r\nURLs that are root-relative (start with `/`) can be resolved relative to some arbitrary path by using the `root` parameter:\r\n\r\n```javascript\r\nvar url = \"/path/to/module.js\";\r\nvar root = \"./root\";\r\nvar request = loaderUtils.urlToRequest(url, root); // \"./root/path/to/module.js\"\r\n```\r\n\r\nTo convert a root-relative URL into a module URL, specify a `root` value that starts with `~`:\r\n\r\n```javascript\r\nvar url = \"/path/to/module.js\";\r\nvar root = \"~\";\r\nvar request = loaderUtils.urlToRequest(url, root); // \"path/to/module.js\"\r\n```\r\n\r\n### `interpolateName`\r\n\r\nInterpolates a filename template using multiple placeholders and/or a regular expression.\r\nThe template and regular expression are set as query params called `name` and `regExp` on the current loader's context.\r\n\r\n```javascript\r\nvar interpolatedName = loaderUtils.interpolateName(loaderContext, name, options);\r\n```\r\n\r\nThe following tokens are replaced in the `name` parameter:\r\n\r\n* `[ext]` the extension of the resource\r\n* `[name]` the basename of the resource\r\n* `[path]` the path of the resource relative to the `context` query parameter or option.\r\n* `[hash]` the hash of `options.content` (Buffer) (by default it's the hex digest of the md5 hash)\r\n* `[<hashType>:hash:<digestType>:<length>]` optionally one can configure\r\n * other `hashType`s, i. e. `sha1`, `md5`, `sha256`, `sha512`\r\n * other `digestType`s, i. e. `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`\r\n * and `length` the length in chars\r\n* `[N]` the N-th match obtained from matching the current file name against `options.regExp`\r\n\r\nExamples\r\n\r\n``` javascript\r\n// loaderContext.resourcePath = \"/app/js/javascript.js\"\r\nloaderUtils.interpolateName(loaderContext, \"js/[hash].script.[ext]\", { content: ... });\r\n// => js/0dcbbaa701328a3c262cfd45869e351f.script.js\r\n\r\n// loaderContext.resourcePath = \"/app/page.html\"\r\nloaderUtils.interpolateName(loaderContext, \"html-[hash:6].html\", { content: ... });\r\n// => html-109fa8.html\r\n\r\n// loaderContext.resourcePath = \"/app/flash.txt\"\r\nloaderUtils.interpolateName(loaderContext, \"[hash]\", { content: ... });\r\n// => c31e9820c001c9c4a86bce33ce43b679\r\n\r\n// loaderContext.resourcePath = \"/app/img/image.png\"\r\nloaderUtils.interpolateName(loaderContext, \"[sha512:hash:base64:7]\", { content: ... });\r\n// => gdyb21L.png\r\n// use sha512 hash instead of md5 and with only 7 chars of base64\r\n\r\n// loaderContext.resourcePath = \"/app/img/myself.png\"\r\n// loaderContext.query.name =\r\nloaderUtils.interpolateName(loaderContext, \"picture.png\");\r\n// => picture.png\r\n\r\n// loaderContext.resourcePath = \"/app/dir/file.png\"\r\nloaderUtils.interpolateName(loaderContext, \"[path][name].[ext]?[hash]\", { content: ... });\r\n// => dir/file.png?e43b20c069c4a01867c31e98cbce33c9\r\n\r\n// loaderContext.resourcePath = \"/app/js/page-home.js\"\r\nloaderUtils.interpolateName(loaderContext, \"script-[1].[ext]\", { regExp: \"page-(.*)\\\\.js\", content: ... });\r\n// => script-home.js\r\n```\r\n\r\n### `getHashDigest`\r\n\r\n``` javascript\r\nvar digestString = loaderUtils.getHashDigest(buffer, hashType, digestType, maxLength);\r\n```\r\n\r\n* `buffer` the content that should be hashed\r\n* `hashType` one of `sha1`, `md5`, `sha256`, `sha512` or any other node.js supported hash type\r\n* `digestType` one of `hex`, `base26`, `base32`, `base36`, `base49`, `base52`, `base58`, `base62`, `base64`\r\n* `maxLength` the maximum length in chars\r\n\r\n## License\r\n\r\nMIT (http://www.opensource.org/licenses/mit-license.php)\r\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/webpack/loader-utils.git"
},
"scripts": {
"cover": "istanbul cover -x *.runtime.js node_modules/mocha/bin/_mocha",
"publish-patch": "mocha && npm version patch && git push && git push --tags && npm publish",
"test": "mocha",
"travis": "npm run cover -- --report lcovonly"
},
"version": "0.2.12"
}