fix
This commit is contained in:
4
book/node_modules/string-template/.npmignore
generated
vendored
Normal file
4
book/node_modules/string-template/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
support
|
||||
test
|
||||
examples
|
||||
*.sock
|
||||
7
book/node_modules/string-template/.travis.yml
generated
vendored
Normal file
7
book/node_modules/string-template/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
before_script:
|
||||
- npm install
|
||||
- npm install istanbul coveralls
|
||||
script: npm run travis-test
|
||||
19
book/node_modules/string-template/LICENCE
generated
vendored
Normal file
19
book/node_modules/string-template/LICENCE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2013 Matt Esch.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
103
book/node_modules/string-template/Readme.md
generated
vendored
Normal file
103
book/node_modules/string-template/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
# string-template
|
||||
|
||||
[![build status][1]][2] [![dependency status][3]][4] [![coverage report][9]][10] [![stability index][15]][16]
|
||||
|
||||
[![npm stats][13]][14]
|
||||
|
||||
[![browser support][5]][6]
|
||||
|
||||
A simple string template function based on named or indexed arguments
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var format = require("string-template")
|
||||
var greeting
|
||||
|
||||
// Format using an object hash with keys matching [0-9a-zA-Z]+
|
||||
|
||||
greeting = format("Hello {name}, you have {count} unread messages", {
|
||||
name: "Robert",
|
||||
count: 12
|
||||
})
|
||||
// greeting -> "Hello Robert, you have 12 unread messages"
|
||||
|
||||
|
||||
// Format using a number indexed array
|
||||
|
||||
greeting = format("Hello {0}, you have {1} unread messages", ["Robert", 12])
|
||||
// greeting -> "Hello Robert, you have 12 unread messages"
|
||||
|
||||
|
||||
// Format using optional arguments
|
||||
|
||||
greeting = format("Hello {0}, you have {1} unread messages",
|
||||
"Robert",
|
||||
12)
|
||||
// greeting -> "Hello Robert, you have 12 unread messages"
|
||||
|
||||
|
||||
// Escape {} pairs by using double {{}}
|
||||
|
||||
var text = format("{{0}}")
|
||||
// text -> "{0}"
|
||||
|
||||
```
|
||||
|
||||
## Compiling templates
|
||||
|
||||
`string-template` exposes two template compiling options for when you need the
|
||||
additional performance. Arguments passed to the compiled template are of the
|
||||
same structure as the main `string-template` function, so either a single
|
||||
object/array or a list of arguments.
|
||||
|
||||
```js
|
||||
var compile = require("string-template/compile")
|
||||
|
||||
var greetingTemplate = compile("Hello {0}, you have {1} unread messages")
|
||||
|
||||
var greeting = greetingTemplate("Robert", 12)
|
||||
// -> "Hello Robert, you have 12 unread messages"
|
||||
```
|
||||
|
||||
Passing a truthy second argument to `compile` will opt into using `new Function`
|
||||
to generate a function. The function returned contains a literal string
|
||||
concatenation statement, interleaving the correct arguments you have passed in.
|
||||
|
||||
```js
|
||||
var compile = require("string-template/compile")
|
||||
|
||||
var greetingTemplate = compile("Hello {0}, you have {1} unread messages", true)
|
||||
// -> greetingTemplate generated using new Function
|
||||
|
||||
var greeting = greetingTemplate(["Robert", 12])
|
||||
// -> "Hello Robert, you have 12 unread messages"
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
`npm install string-template`
|
||||
|
||||
## Contributors
|
||||
|
||||
- Matt-Esch
|
||||
|
||||
## MIT Licenced
|
||||
|
||||
[1]: https://secure.travis-ci.org/Matt-Esch/string-template.png
|
||||
[2]: https://travis-ci.org/Matt-Esch/string-template
|
||||
[3]: https://david-dm.org/Matt-Esch/string-template.png
|
||||
[4]: https://david-dm.org/Matt-Esch/string-template
|
||||
[5]: https://ci.testling.com/Matt-Esch/string-template.png
|
||||
[6]: https://ci.testling.com/Matt-Esch/string-template
|
||||
[9]: https://coveralls.io/repos/Matt-Esch/string-template/badge.png
|
||||
[10]: https://coveralls.io/r/Matt-Esch/string-template
|
||||
[13]: https://nodei.co/npm/string-template.png?downloads=true&stars=true
|
||||
[14]: https://nodei.co/npm/string-template
|
||||
[15]: http://hughsk.github.io/stability-badges/dist/unstable.svg
|
||||
[16]: http://github.com/hughsk/stability-badges
|
||||
|
||||
[7]: https://badge.fury.io/js/string-template.png
|
||||
[8]: https://badge.fury.io/js/string-template
|
||||
[11]: https://gemnasium.com/Matt-Esch/string-template.png
|
||||
[12]: https://gemnasium.com/Matt-Esch/string-template
|
||||
143
book/node_modules/string-template/compile.js
generated
vendored
Normal file
143
book/node_modules/string-template/compile.js
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
var template = require("./index")
|
||||
|
||||
var whitespaceRegex = /["'\\\n\r\u2028\u2029]/g
|
||||
var nargs = /\{[0-9a-zA-Z]+\}/g
|
||||
|
||||
var replaceTemplate =
|
||||
" var args\n" +
|
||||
" var result\n" +
|
||||
" if (arguments.length === 1 && typeof arguments[0] === \"object\") {\n" +
|
||||
" args = arguments[0]\n" +
|
||||
" } else {\n" +
|
||||
" args = arguments" +
|
||||
" }\n\n" +
|
||||
" if (!args || !(\"hasOwnProperty\" in args)) {\n" +
|
||||
" args = {}\n" +
|
||||
" }\n\n" +
|
||||
" return {0}"
|
||||
|
||||
var literalTemplate = "\"{0}\""
|
||||
var argTemplate = "(result = args.hasOwnProperty(\"{0}\") ? " +
|
||||
"args[\"{0}\"] : null, \n " +
|
||||
"(result === null || result === undefined) ? \"\" : result)"
|
||||
|
||||
module.exports = compile
|
||||
|
||||
function compile(string, inline) {
|
||||
var replacements = string.match(nargs)
|
||||
var interleave = string.split(nargs)
|
||||
var replace = []
|
||||
|
||||
for (var i = 0; i < interleave.length; i++) {
|
||||
var current = interleave[i];
|
||||
var replacement = replacements[i];
|
||||
var escapeLeft = current.charAt(current.length - 1)
|
||||
var escapeRight = (interleave[i + 1] || "").charAt(0)
|
||||
|
||||
if (replacement) {
|
||||
replacement = replacement.substring(1, replacement.length - 1)
|
||||
}
|
||||
|
||||
if (escapeLeft === "{" && escapeRight === "}") {
|
||||
replace.push(current + replacement)
|
||||
} else {
|
||||
replace.push(current);
|
||||
if (replacement) {
|
||||
replace.push({ name: replacement })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var prev = [""]
|
||||
|
||||
for (var j = 0; j < replace.length; j++) {
|
||||
var curr = replace[j]
|
||||
|
||||
if (String(curr) === curr) {
|
||||
var top = prev[prev.length - 1]
|
||||
|
||||
if (String(top) === top) {
|
||||
prev[prev.length - 1] = top + curr
|
||||
} else {
|
||||
prev.push(curr)
|
||||
}
|
||||
} else {
|
||||
prev.push(curr)
|
||||
}
|
||||
}
|
||||
|
||||
replace = prev
|
||||
|
||||
if (inline) {
|
||||
for (var k = 0; k < replace.length; k++) {
|
||||
var token = replace[k]
|
||||
|
||||
if (String(token) === token) {
|
||||
replace[k] = template(literalTemplate, escape(token))
|
||||
} else {
|
||||
replace[k] = template(argTemplate, escape(token.name))
|
||||
}
|
||||
}
|
||||
|
||||
var replaceCode = replace.join(" +\n ")
|
||||
var compiledSource = template(replaceTemplate, replaceCode)
|
||||
return new Function(compiledSource)
|
||||
}
|
||||
|
||||
return function template() {
|
||||
var args
|
||||
|
||||
if (arguments.length === 1 && typeof arguments[0] === "object") {
|
||||
args = arguments[0]
|
||||
} else {
|
||||
args = arguments
|
||||
}
|
||||
|
||||
if (!args || !("hasOwnProperty" in args)) {
|
||||
args = {}
|
||||
}
|
||||
|
||||
var result = []
|
||||
|
||||
for (var i = 0; i < replace.length; i++) {
|
||||
if (i % 2 === 0) {
|
||||
result.push(replace[i])
|
||||
} else {
|
||||
var argName = replace[i].name
|
||||
var arg = args.hasOwnProperty(argName) ? args[argName] : null
|
||||
if (arg !== null || arg !== undefined) {
|
||||
result.push(arg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.join("")
|
||||
}
|
||||
}
|
||||
|
||||
function escape(string) {
|
||||
string = '' + string;
|
||||
|
||||
return string.replace(whitespaceRegex, escapedWhitespace);
|
||||
}
|
||||
|
||||
function escapedWhitespace(character) {
|
||||
// Escape all characters not included in SingleStringCharacters and
|
||||
// DoubleStringCharacters on
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
||||
switch (character) {
|
||||
case '"':
|
||||
case "'":
|
||||
case '\\':
|
||||
return '\\' + character
|
||||
// Four possible LineTerminator characters need to be escaped:
|
||||
case '\n':
|
||||
return '\\n'
|
||||
case '\r':
|
||||
return '\\r'
|
||||
case '\u2028':
|
||||
return '\\u2028'
|
||||
case '\u2029':
|
||||
return '\\u2029'
|
||||
}
|
||||
}
|
||||
34
book/node_modules/string-template/index.js
generated
vendored
Normal file
34
book/node_modules/string-template/index.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
var nargs = /\{([0-9a-zA-Z]+)\}/g
|
||||
var slice = Array.prototype.slice
|
||||
|
||||
module.exports = template
|
||||
|
||||
function template(string) {
|
||||
var args
|
||||
|
||||
if (arguments.length === 2 && typeof arguments[1] === "object") {
|
||||
args = arguments[1]
|
||||
} else {
|
||||
args = slice.call(arguments, 1)
|
||||
}
|
||||
|
||||
if (!args || !args.hasOwnProperty) {
|
||||
args = {}
|
||||
}
|
||||
|
||||
return string.replace(nargs, function replaceArg(match, i, index) {
|
||||
var result
|
||||
|
||||
if (string[index - 1] === "{" &&
|
||||
string[index + match.length] === "}") {
|
||||
return i
|
||||
} else {
|
||||
result = args.hasOwnProperty(i) ? args[i] : null
|
||||
if (result === null || result === undefined) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
})
|
||||
}
|
||||
57
book/node_modules/string-template/package.json
generated
vendored
Normal file
57
book/node_modules/string-template/package.json
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "string-template",
|
||||
"version": "0.2.1",
|
||||
"description": "A simple string template function based on named or indexed arguments",
|
||||
"keywords": [
|
||||
"template",
|
||||
"string",
|
||||
"format",
|
||||
"replace",
|
||||
"arguments"
|
||||
],
|
||||
"author": "Matt-Esch <matt@mattesch.info>",
|
||||
"repository": "git://github.com/Matt-Esch/string-template.git",
|
||||
"main": "index",
|
||||
"homepage": "https://github.com/Matt-Esch/string-template",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Matt-Esch"
|
||||
}
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/Matt-Esch/string-template/issues",
|
||||
"email": "matt@mattesch.info"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"tape": "~1.1.1"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://github.com/Matt-Esch/string-template/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"scripts": {
|
||||
"test": "node ./test/index.js",
|
||||
"travis-test": "istanbul cover ./test/index.js && ((cat coverage/lcov.info | coveralls) || exit 0)",
|
||||
"cover": "istanbul cover --report none --print detail ./test/index.js",
|
||||
"view-cover": "istanbul report html && google-chrome ./coverage/index.html"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/index.js",
|
||||
"browsers": [
|
||||
"ie/8..latest",
|
||||
"firefox/16..latest",
|
||||
"firefox/nightly",
|
||||
"chrome/22..latest",
|
||||
"chrome/canary",
|
||||
"opera/12..latest",
|
||||
"opera/next",
|
||||
"safari/5.1..latest",
|
||||
"ipad/6.0..latest",
|
||||
"iphone/6.0..latest",
|
||||
"android-browser/4.2..latest"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user