node_modules

This commit is contained in:
saeid
2019-07-15 13:07:31 +04:30
parent d3735c6d30
commit ce1a3ebf9c
35713 changed files with 3639219 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
'use strict';
var List = require('./list');
module.exports = function clone(node) {
var result = {};
for (var key in node) {
var value = node[key];
if (value) {
if (Array.isArray(value) || value instanceof List) {
value = value.map(clone);
} else if (value.constructor === Object) {
value = clone(value);
}
}
result[key] = value;
}
return result;
};
+17
View File
@@ -0,0 +1,17 @@
module.exports = function createCustomError(name, message) {
// use Object.create(), because some VMs prevent setting line/column otherwise
// (iOS Safari 10 even throws an exception)
var error = Object.create(SyntaxError.prototype);
var errorStack = new Error();
error.name = name;
error.message = message;
Object.defineProperty(error, 'stack', {
get: function() {
return (errorStack.stack || '').replace(/^(.+\n){1,3}/, name + ': ' + message + '\n');
}
});
return error;
};
+529
View File
@@ -0,0 +1,529 @@
'use strict';
//
// item item item item
// /------\ /------\ /------\ /------\
// | data | | data | | data | | data |
// null <--+-prev |<---+-prev |<---+-prev |<---+-prev |
// | next-+--->| next-+--->| next-+--->| next-+--> null
// \------/ \------/ \------/ \------/
// ^ ^
// | list |
// | /------\ |
// \--------------+-head | |
// | tail-+--------------/
// \------/
//
function createItem(data) {
return {
prev: null,
next: null,
data: data
};
}
function allocateCursor(node, prev, next) {
var cursor;
if (cursors !== null) {
cursor = cursors;
cursors = cursors.cursor;
cursor.prev = prev;
cursor.next = next;
cursor.cursor = node.cursor;
} else {
cursor = {
prev: prev,
next: next,
cursor: node.cursor
};
}
node.cursor = cursor;
return cursor;
}
function releaseCursor(node) {
var cursor = node.cursor;
node.cursor = cursor.cursor;
cursor.prev = null;
cursor.next = null;
cursor.cursor = cursors;
cursors = cursor;
}
var cursors = null;
var List = function() {
this.cursor = null;
this.head = null;
this.tail = null;
};
List.createItem = createItem;
List.prototype.createItem = createItem;
List.prototype.updateCursors = function(prevOld, prevNew, nextOld, nextNew) {
var cursor = this.cursor;
while (cursor !== null) {
if (cursor.prev === prevOld) {
cursor.prev = prevNew;
}
if (cursor.next === nextOld) {
cursor.next = nextNew;
}
cursor = cursor.cursor;
}
};
List.prototype.getSize = function() {
var size = 0;
var cursor = this.head;
while (cursor) {
size++;
cursor = cursor.next;
}
return size;
};
List.prototype.fromArray = function(array) {
var cursor = null;
this.head = null;
for (var i = 0; i < array.length; i++) {
var item = createItem(array[i]);
if (cursor !== null) {
cursor.next = item;
} else {
this.head = item;
}
item.prev = cursor;
cursor = item;
}
this.tail = cursor;
return this;
};
List.prototype.toArray = function() {
var cursor = this.head;
var result = [];
while (cursor) {
result.push(cursor.data);
cursor = cursor.next;
}
return result;
};
List.prototype.toJSON = List.prototype.toArray;
List.prototype.isEmpty = function() {
return this.head === null;
};
List.prototype.first = function() {
return this.head && this.head.data;
};
List.prototype.last = function() {
return this.tail && this.tail.data;
};
List.prototype.each = function(fn, context) {
var item;
if (context === undefined) {
context = this;
}
// push cursor
var cursor = allocateCursor(this, null, this.head);
while (cursor.next !== null) {
item = cursor.next;
cursor.next = item.next;
fn.call(context, item.data, item, this);
}
// pop cursor
releaseCursor(this);
};
List.prototype.forEach = List.prototype.each;
List.prototype.eachRight = function(fn, context) {
var item;
if (context === undefined) {
context = this;
}
// push cursor
var cursor = allocateCursor(this, this.tail, null);
while (cursor.prev !== null) {
item = cursor.prev;
cursor.prev = item.prev;
fn.call(context, item.data, item, this);
}
// pop cursor
releaseCursor(this);
};
List.prototype.forEachRight = List.prototype.eachRight;
List.prototype.nextUntil = function(start, fn, context) {
if (start === null) {
return;
}
var item;
if (context === undefined) {
context = this;
}
// push cursor
var cursor = allocateCursor(this, null, start);
while (cursor.next !== null) {
item = cursor.next;
cursor.next = item.next;
if (fn.call(context, item.data, item, this)) {
break;
}
}
// pop cursor
releaseCursor(this);
};
List.prototype.prevUntil = function(start, fn, context) {
if (start === null) {
return;
}
var item;
if (context === undefined) {
context = this;
}
// push cursor
var cursor = allocateCursor(this, start, null);
while (cursor.prev !== null) {
item = cursor.prev;
cursor.prev = item.prev;
if (fn.call(context, item.data, item, this)) {
break;
}
}
// pop cursor
releaseCursor(this);
};
List.prototype.some = function(fn, context) {
var cursor = this.head;
if (context === undefined) {
context = this;
}
while (cursor !== null) {
if (fn.call(context, cursor.data, cursor, this)) {
return true;
}
cursor = cursor.next;
}
return false;
};
List.prototype.map = function(fn, context) {
var result = new List();
var cursor = this.head;
if (context === undefined) {
context = this;
}
while (cursor !== null) {
result.appendData(fn.call(context, cursor.data, cursor, this));
cursor = cursor.next;
}
return result;
};
List.prototype.filter = function(fn, context) {
var result = new List();
var cursor = this.head;
if (context === undefined) {
context = this;
}
while (cursor !== null) {
if (fn.call(context, cursor.data, cursor, this)) {
result.appendData(cursor.data);
}
cursor = cursor.next;
}
return result;
};
List.prototype.clear = function() {
this.head = null;
this.tail = null;
};
List.prototype.copy = function() {
var result = new List();
var cursor = this.head;
while (cursor !== null) {
result.insert(createItem(cursor.data));
cursor = cursor.next;
}
return result;
};
List.prototype.prepend = function(item) {
// head
// ^
// item
this.updateCursors(null, item, this.head, item);
// insert to the beginning of the list
if (this.head !== null) {
// new item <- first item
this.head.prev = item;
// new item -> first item
item.next = this.head;
} else {
// if list has no head, then it also has no tail
// in this case tail points to the new item
this.tail = item;
}
// head always points to new item
this.head = item;
return this;
};
List.prototype.prependData = function(data) {
return this.prepend(createItem(data));
};
List.prototype.append = function(item) {
return this.insert(item);
};
List.prototype.appendData = function(data) {
return this.insert(createItem(data));
};
List.prototype.insert = function(item, before) {
if (before !== undefined && before !== null) {
// prev before
// ^
// item
this.updateCursors(before.prev, item, before, item);
if (before.prev === null) {
// insert to the beginning of list
if (this.head !== before) {
throw new Error('before doesn\'t belong to list');
}
// since head points to before therefore list doesn't empty
// no need to check tail
this.head = item;
before.prev = item;
item.next = before;
this.updateCursors(null, item);
} else {
// insert between two items
before.prev.next = item;
item.prev = before.prev;
before.prev = item;
item.next = before;
}
} else {
// tail
// ^
// item
this.updateCursors(this.tail, item, null, item);
// insert to the ending of the list
if (this.tail !== null) {
// last item -> new item
this.tail.next = item;
// last item <- new item
item.prev = this.tail;
} else {
// if list has no tail, then it also has no head
// in this case head points to new item
this.head = item;
}
// tail always points to new item
this.tail = item;
}
return this;
};
List.prototype.insertData = function(data, before) {
return this.insert(createItem(data), before);
};
List.prototype.remove = function(item) {
// item
// ^
// prev next
this.updateCursors(item, item.prev, item, item.next);
if (item.prev !== null) {
item.prev.next = item.next;
} else {
if (this.head !== item) {
throw new Error('item doesn\'t belong to list');
}
this.head = item.next;
}
if (item.next !== null) {
item.next.prev = item.prev;
} else {
if (this.tail !== item) {
throw new Error('item doesn\'t belong to list');
}
this.tail = item.prev;
}
item.prev = null;
item.next = null;
return item;
};
List.prototype.push = function(data) {
this.insert(createItem(data));
};
List.prototype.pop = function() {
if (this.tail !== null) {
return this.remove(this.tail);
}
};
List.prototype.unshift = function(data) {
this.prepend(createItem(data));
};
List.prototype.shift = function() {
if (this.head !== null) {
return this.remove(this.head);
}
};
List.prototype.prependList = function(list) {
return this.insertList(list, this.head);
};
List.prototype.appendList = function(list) {
return this.insertList(list);
};
List.prototype.insertList = function(list, before) {
// ignore empty lists
if (list.head === null) {
return this;
}
if (before !== undefined && before !== null) {
this.updateCursors(before.prev, list.tail, before, list.head);
// insert in the middle of dist list
if (before.prev !== null) {
// before.prev <-> list.head
before.prev.next = list.head;
list.head.prev = before.prev;
} else {
this.head = list.head;
}
before.prev = list.tail;
list.tail.next = before;
} else {
this.updateCursors(this.tail, list.tail, null, list.head);
// insert to end of the list
if (this.tail !== null) {
// if destination list has a tail, then it also has a head,
// but head doesn't change
// dest tail -> source head
this.tail.next = list.head;
// dest tail <- source head
list.head.prev = this.tail;
} else {
// if list has no a tail, then it also has no a head
// in this case points head to new item
this.head = list.head;
}
// tail always start point to new item
this.tail = list.tail;
}
list.head = null;
list.tail = null;
return this;
};
List.prototype.replace = function(oldItem, newItemOrList) {
if ('head' in newItemOrList) {
this.insertList(newItemOrList, oldItem);
} else {
this.insert(newItemOrList, oldItem);
}
this.remove(oldItem);
};
module.exports = List;
+105
View File
@@ -0,0 +1,105 @@
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty;
var keywords = Object.create(null);
var properties = Object.create(null);
var HYPHENMINUS = 45; // '-'.charCodeAt()
function isCustomProperty(str, offset) {
offset = offset || 0;
return str.length - offset >= 2 &&
str.charCodeAt(offset) === HYPHENMINUS &&
str.charCodeAt(offset + 1) === HYPHENMINUS;
}
function getVendorPrefix(str, offset) {
offset = offset || 0;
// verdor prefix should be at least 3 chars length
if (str.length - offset >= 3) {
// vendor prefix starts with hyper minus following non-hyper minus
if (str.charCodeAt(offset) === HYPHENMINUS &&
str.charCodeAt(offset + 1) !== HYPHENMINUS) {
// vendor prefix should contain a hyper minus at the ending
var secondDashIndex = str.indexOf('-', offset + 2);
if (secondDashIndex !== -1) {
return str.substring(offset, secondDashIndex + 1);
}
}
}
return '';
}
function getKeywordDescriptor(keyword) {
if (hasOwnProperty.call(keywords, keyword)) {
return keywords[keyword];
}
var name = keyword.toLowerCase();
if (hasOwnProperty.call(keywords, name)) {
return keywords[keyword] = keywords[name];
}
var custom = isCustomProperty(name, 0);
var vendor = !custom ? getVendorPrefix(name, 0) : '';
return keywords[keyword] = Object.freeze({
basename: name.substr(vendor.length),
name: name,
vendor: vendor,
prefix: vendor,
custom: custom
});
}
function getPropertyDescriptor(property) {
if (hasOwnProperty.call(properties, property)) {
return properties[property];
}
var name = property;
var hack = property[0];
if (hack === '/') {
hack = property[1] === '/' ? '//' : '/';
} else if (hack !== '_' &&
hack !== '*' &&
hack !== '$' &&
hack !== '#' &&
hack !== '+') {
hack = '';
}
var custom = isCustomProperty(name, hack.length);
// re-use result when possible (the same as for lower case)
if (!custom) {
name = name.toLowerCase();
if (hasOwnProperty.call(properties, name)) {
return properties[property] = properties[name];
}
}
var vendor = !custom ? getVendorPrefix(name, hack.length) : '';
var prefix = name.substr(0, hack.length + vendor.length);
return properties[property] = Object.freeze({
basename: name.substr(prefix.length),
name: name.substr(hack.length),
hack: hack,
vendor: vendor,
prefix: prefix,
custom: custom
});
}
module.exports = {
keyword: getKeywordDescriptor,
property: getPropertyDescriptor,
isCustomProperty: isCustomProperty,
vendorPrefix: getVendorPrefix
};
+121
View File
@@ -0,0 +1,121 @@
var REVERSE_SOLIDUS = 0x5c; // \
var QUOTATION_MARK = 0x22; // "
var APOSTROPHE = 0x27; // '
var TAB = 0x09; // tab
var WHITESPACE = 0x20; // space
var AMPERSAND = 0x26;
var LESSTHANSIGN = 0x3C;
var GREATERTHANSIGN = 0x3E;
function isHex(code) {
return (code >= 48 && code <= 57) || // 0 .. 9
(code >= 65 && code <= 70) || // A .. F
(code >= 97 && code <= 102); // a .. f
}
function decodeString(str) {
var decoded = '';
var len = str.length;
var firstChar = str.charCodeAt(0);
var start = firstChar === QUOTATION_MARK || firstChar === APOSTROPHE ? 1 : 0;
var end = start === 1 && len > 1 && str.charCodeAt(len - 1) === firstChar ? len - 2 : len - 1;
for (var i = start; i <= end; i++) {
var code = str.charCodeAt(i);
if (code === REVERSE_SOLIDUS) {
// special case at the ending
if (i === end) {
// if the next input code point is EOF, do nothing
// otherwise include last quote as escaped
if (i !== len - 1) {
decoded = str.substr(i + 1);
}
break;
}
code = str.charCodeAt(++i);
// ignore escaped newline
if (code !== 0x0A && code !== 0x0C && code !== 0x0D) { // TODO: should treat a "CR/LF" pair (U+000D/U+000A) as a single white space character
// https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
for (var j = 0; j < 6 && i + j <= end;) {
code = str.charCodeAt(i + j);
if (isHex(code)) {
j++;
} else {
break;
}
}
if (j > 0) {
code = str.charCodeAt(i + j);
// include space into sequence
// TODO: add newline support
if (code === WHITESPACE || code === TAB) {
j++;
}
code = parseInt(str.substr(i, j), 16);
if (
(code === 0) || // If this number is zero,
(code >= 0xD800 && code <= 0xDFFF) || // or is for a surrogate,
(code > 0x10FFFF) // or is greater than the maximum allowed code point
) {
// ... return U+FFFD REPLACEMENT CHARACTER
code = 0xFFFD;
}
// FIXME: code above 0xFFFF will be converted incorrectly,
// better to use String.fromCharPoint() but it lack of support by engines
decoded += String.fromCharCode(code);
i += j - 1;
} else {
decoded += str.charAt(i);
}
}
} else {
decoded += str.charAt(i);
}
}
return decoded;
}
function encodeString(str, apostrophe) {
var quote = apostrophe ? '\'' : '"';
var quoteCode = apostrophe ? APOSTROPHE : QUOTATION_MARK;
var encoded = quote;
var wsBeforeHexIsNeeded = false;
for (var i = 0; i < str.length; i++) {
var code = str.charCodeAt(i);
if (code <= 0x1F || code === AMPERSAND || code === LESSTHANSIGN || code === GREATERTHANSIGN) {
encoded += '\\' + code.toString(16);
wsBeforeHexIsNeeded = true;
} else if (code === REVERSE_SOLIDUS || code === quoteCode) {
encoded += '\\' + str.charAt(i);
wsBeforeHexIsNeeded = false;
} else {
if (wsBeforeHexIsNeeded && isHex(code)) {
encoded += ' ';
}
encoded += str.charAt(i);
wsBeforeHexIsNeeded = false;
}
}
encoded += quote;
return encoded;
}
module.exports = {
decode: decodeString,
encode: encodeString
};