aboutsummaryrefslogtreecommitdiff
path: root/node_modules/preserve/index.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/preserve/index.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/preserve/index.js')
-rw-r--r--node_modules/preserve/index.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/node_modules/preserve/index.js b/node_modules/preserve/index.js
new file mode 100644
index 00000000..a6c5d481
--- /dev/null
+++ b/node_modules/preserve/index.js
@@ -0,0 +1,54 @@
+/*!
+ * preserve <https://github.com/jonschlinkert/preserve>
+ *
+ * Copyright (c) 2014-2015, Jon Schlinkert.
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+/**
+ * Replace tokens in `str` with a temporary, heuristic placeholder.
+ *
+ * ```js
+ * tokens.before('{a\\,b}');
+ * //=> '{__ID1__}'
+ * ```
+ *
+ * @param {String} `str`
+ * @return {String} String with placeholders.
+ * @api public
+ */
+
+exports.before = function before(str, re) {
+ return str.replace(re, function (match) {
+ var id = randomize();
+ cache[id] = match;
+ return '__ID' + id + '__';
+ });
+};
+
+/**
+ * Replace placeholders in `str` with original tokens.
+ *
+ * ```js
+ * tokens.after('{__ID1__}');
+ * //=> '{a\\,b}'
+ * ```
+ *
+ * @param {String} `str` String with placeholders
+ * @return {String} `str` String with original tokens.
+ * @api public
+ */
+
+exports.after = function after(str) {
+ return str.replace(/__ID(.{5})__/g, function (_, id) {
+ return cache[id];
+ });
+};
+
+function randomize() {
+ return Math.random().toString().slice(2, 7);
+}
+
+var cache = {}; \ No newline at end of file