[Pkg-javascript-commits] [node-parse-base64vlq-mappings] 02/26: initial package with adapted parse
Bastien Roucariès
rouca at moszumanska.debian.org
Mon Sep 18 09:24:03 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-parse-base64vlq-mappings.
commit c6fd6366785749687d1c5114ccb0c0a037eb62a7
Author: Thorsten Lorenz <thlorenz at gmx.de>
Date: Wed Mar 13 07:35:09 2013 -0400
initial package with adapted parse
---
.gitignore | 16 +++++++++
LICENSE | 16 +++++++++
MOZILLA_LICENSE | 28 +++++++++++++++
base64-vlq.js | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
base64.js | 35 ++++++++++++++++++
index.js | 85 ++++++++++++++++++++++++++++++++++++++++++++
package.json | 26 ++++++++++++++
7 files changed, 314 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..de78e27
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,16 @@
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
+tmp
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..de78e27
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,16 @@
+lib-cov
+*.seed
+*.log
+*.csv
+*.dat
+*.out
+*.pid
+*.gz
+
+pids
+logs
+results
+
+node_modules
+npm-debug.log
+tmp
diff --git a/MOZILLA_LICENSE b/MOZILLA_LICENSE
new file mode 100644
index 0000000..ed1b7cf
--- /dev/null
+++ b/MOZILLA_LICENSE
@@ -0,0 +1,28 @@
+
+Copyright (c) 2009-2011, Mozilla Foundation and contributors
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the names of the Mozilla Foundation nor the names of project
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/base64-vlq.js b/base64-vlq.js
new file mode 100644
index 0000000..1213ae1
--- /dev/null
+++ b/base64-vlq.js
@@ -0,0 +1,108 @@
+'use strict';
+/*
+ * Copyright 2011 Mozilla Foundation and contributors
+ * Licensed under the New BSD license. See LICENSE or:
+ * http://opensource.org/licenses/BSD-3-Clause
+ */
+
+var base64 = require('./base64');
+
+// A single base 64 digit can contain 6 bits of data. For the base 64 variable
+// length quantities we use in the source map spec, the first bit is the sign,
+// the next four bits are the actual value, and the 6th bit is the
+// continuation bit. The continuation bit tells us whether there are more
+// digits in this value following this digit.
+//
+// Continuation
+// | Sign
+// | |
+// V V
+// 101011
+
+var VLQ_BASE_SHIFT = 5;
+
+// binary: 100000
+var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
+
+// binary: 011111
+var VLQ_BASE_MASK = VLQ_BASE - 1;
+
+// binary: 100000
+var VLQ_CONTINUATION_BIT = VLQ_BASE;
+
+/**
+ * Converts from a two-complement value to a value where the sign bit is
+ * is placed in the least significant bit. For example, as decimals:
+ * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
+ * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
+ */
+function toVLQSigned(aValue) {
+ return aValue < 0
+ ? ((-aValue) << 1) + 1
+ : (aValue << 1) + 0;
+}
+
+/**
+ * Converts to a two-complement value from a value where the sign bit is
+ * is placed in the least significant bit. For example, as decimals:
+ * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
+ * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
+ */
+function fromVLQSigned(aValue) {
+ var isNegative = (aValue & 1) === 1;
+ var shifted = aValue >> 1;
+ return isNegative
+ ? -shifted
+ : shifted;
+}
+
+/**
+ * Returns the base 64 VLQ encoded value.
+ */
+exports.encode = function base64VLQ_encode(aValue) {
+ var encoded = "";
+ var digit;
+
+ var vlq = toVLQSigned(aValue);
+
+ do {
+ digit = vlq & VLQ_BASE_MASK;
+ vlq >>>= VLQ_BASE_SHIFT;
+ if (vlq > 0) {
+ // There are still more digits in this value, so we must make sure the
+ // continuation bit is marked.
+ digit |= VLQ_CONTINUATION_BIT;
+ }
+ encoded += base64.encode(digit);
+ } while (vlq > 0);
+
+ return encoded;
+};
+
+/**
+ * Decodes the next base 64 VLQ value from the given string and returns the
+ * value and the rest of the string.
+ */
+exports.decode = function base64VLQ_decode(aStr) {
+ var i = 0;
+ var strLen = aStr.length;
+ var result = 0;
+ var shift = 0;
+ var continuation, digit;
+
+ do {
+ if (i >= strLen) {
+ throw new Error("Expected more digits in base 64 VLQ value.");
+ }
+ digit = base64.decode(aStr.charAt(i++));
+ continuation = !!(digit & VLQ_CONTINUATION_BIT);
+ digit &= VLQ_BASE_MASK;
+ result = result + (digit << shift);
+ shift += VLQ_BASE_SHIFT;
+ } while (continuation);
+
+ return {
+ value: fromVLQSigned(result),
+ rest: aStr.slice(i)
+ };
+};
diff --git a/base64.js b/base64.js
new file mode 100644
index 0000000..239223a
--- /dev/null
+++ b/base64.js
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2011 Mozilla Foundation and contributors
+ * Licensed under the New BSD license. See LICENSE or:
+ * http://opensource.org/licenses/BSD-3-Clause
+ */
+
+var charToIntMap = {};
+var intToCharMap = {};
+
+'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
+ .split('')
+ .forEach(function (ch, index) {
+ charToIntMap[ch] = index;
+ intToCharMap[index] = ch;
+ });
+
+/**
+ * Encode an integer in the range of 0 to 63 to a single base 64 digit.
+ */
+exports.encode = function base64_encode(aNumber) {
+ if (aNumber in intToCharMap) {
+ return intToCharMap[aNumber];
+ }
+ throw new TypeError("Must be between 0 and 63: " + aNumber);
+};
+
+/**
+ * Decode a single base 64 digit to an integer.
+ */
+exports.decode = function base64_decode(aChar) {
+ if (aChar in charToIntMap) {
+ return charToIntMap[aChar];
+ }
+ throw new TypeError("Not a valid base 64 digit: " + aChar);
+};
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..353aeaa
--- /dev/null
+++ b/index.js
@@ -0,0 +1,85 @@
+'use strict';
+
+/*
+ * Copyright 2011 Mozilla Foundation and contributors
+ * Licensed under the New BSD license. See LICENSE or:
+ * http://opensource.org/licenses/BSD-3-Clause
+ */
+
+var base64VLQ = require('./base64-vlq');
+
+module.exports = function parse(str_) {
+ var generatedLine = 1
+ , previousGeneratedColumn = 0
+ , previousOriginalLine = 0
+ , previousOriginalColumn = 0
+ , previousSource = 0
+ , previousName = 0
+ , mappingSeparator = /^[,;]/
+ , mappings = []
+ , str = str_
+ , mapping
+ , temp;
+
+ while (str.length > 0) {
+ if (str.charAt(0) === ';') {
+ generatedLine++;
+ str = str.slice(1);
+ previousGeneratedColumn = 0;
+ }
+ else if (str.charAt(0) === ',') {
+ str = str.slice(1);
+ }
+ else {
+ mapping = { generated: { }, original: { } };
+ mapping.generated.line = generatedLine;
+
+ // Generated column.
+ temp = base64VLQ.decode(str);
+ mapping.generated.column = previousGeneratedColumn + temp.value;
+ previousGeneratedColumn = mapping.generated.column;
+ str = temp.rest;
+
+ if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
+ // Original source.
+ temp = base64VLQ.decode(str);
+
+ previousSource += temp.value;
+ str = temp.rest;
+ if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
+ throw new Error('Found a source, but no line and column');
+ }
+
+ // Original line.
+ temp = base64VLQ.decode(str);
+ mapping.original.line = previousOriginalLine + temp.value;
+ previousOriginalLine = mapping.original.line;
+ // Lines are stored 0-based
+ mapping.original.line += 1;
+ str = temp.rest;
+ if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
+ throw new Error('Found a source and line, but no column');
+ }
+
+ // Original column.
+ temp = base64VLQ.decode(str);
+ mapping.original.column = previousOriginalColumn + temp.value;
+ previousOriginalColumn = mapping.original.column;
+ str = temp.rest;
+
+ if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
+ // Original name.
+ temp = base64VLQ.decode(str);
+ mapping.name = this._names.at(previousName + temp.value);
+ previousName += temp.value;
+ str = temp.rest;
+ }
+ }
+
+ mappings.push(mapping);
+ }
+ }
+ return mappings;
+};
+
+var maps = ';AAAA;CAAA,IAAA,CAAA;CAAA;CAAA,CAAA,CAAQ,CAAA,CAAR,IAAS;CACG,EAAR,CAAA,GAAO,IAAP,IAAY;CADhB,EAAQ;;CAAR,CAGA,GAAA,OAAA;;CAHA,CAMA,GAAA,SAAA;CANA';
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..793c737
--- /dev/null
+++ b/package.json
@@ -0,0 +1,26 @@
+{
+ "name" : "parse-base64vlq-mappings",
+ "version" : "0.0.0",
+ "description" : "Parses out base64 VLQ encoded mappings.",
+ "main" : "parse-base64vlq-mappings.js",
+ "scripts" : {
+ "test" : "node-trap test/*.js"
+ },
+ "repository" : {
+ "type" : "git",
+ "url" : "git://github.com/thlorenz/parse-base64vlq-mappings.git"
+ },
+ "homepage" : "https://github.com/thlorenz/parse-base64vlq-mappings",
+ "dependencies" : {
+ },
+ "devDependencies" : {
+ },
+ "keywords": [ "base64", "vlq", "parse", "sourcemap", "mappings" ] ,
+ "author" : {
+ "name" : "Thorsten Lorenz",
+ "email" : "thlorenz at gmx.de",
+ "url" : "http://thlorenz.com"
+ },
+ "license" : "MIT",
+ "engine" : { "node" : ">=0.6" }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-parse-base64vlq-mappings.git
More information about the Pkg-javascript-commits
mailing list