-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.json
36 lines (36 loc) · 5.66 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"name": "loader-utils",
"version": "0.2.5",
"author": {
"name": "Tobias Koppers @sokra"
},
"description": "utils for webpack loaders",
"dependencies": {
"json5": "0.1.x",
"big.js": "~2.5.1"
},
"scripts": {
"test": "mocha test index.js"
},
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
}
],
"repository": {
"type": "git",
"url": "git://github.com/webpack/loader-utils.git"
},
"devDependencies": {
"mocha": "^1.21.4"
},
"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### `urlToRequest`\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\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\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\nInterpolates a filename template using multiple placeholders and/or a regular expression.\r\nThe template and regular expresion 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",
"bugs": {
"url": "https://github.com/webpack/loader-utils/issues"
},
"homepage": "https://github.com/webpack/loader-utils",
"_id": "loader-utils@0.2.5",
"_from": "loader-utils@~0.2.2"
}