From 6445bfbf6bd5bf7ca06cb7b84aa0da08f31fb95b Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 1 Oct 2019 10:32:52 +0200 Subject: [PATCH 1/7] add JSON --- JSON/json2.js | 530 +++++++++++++++++++++++++++++ bin/concat.js | 2 +- index.js | 922 +++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 1258 insertions(+), 196 deletions(-) create mode 100644 JSON/json2.js diff --git a/JSON/json2.js b/JSON/json2.js new file mode 100644 index 0000000..f6fada6 --- /dev/null +++ b/JSON/json2.js @@ -0,0 +1,530 @@ +// json2.js +// 2017-06-12 +// Public Domain. +// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + +// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO +// NOT CONTROL. + +// This file creates a global JSON object containing two methods: stringify +// and parse. This file provides the ES5 JSON capability to ES3 systems. +// If a project might run on IE8 or earlier, then this file should be included. +// This file does nothing on ES5 systems. + +// JSON.stringify(value, replacer, space) +// value any JavaScript value, usually an object or array. +// replacer an optional parameter that determines how object +// values are stringified for objects. It can be a +// function or an array of strings. +// space an optional parameter that specifies the indentation +// of nested structures. If it is omitted, the text will +// be packed without extra whitespace. If it is a number, +// it will specify the number of spaces to indent at each +// level. If it is a string (such as "\t" or " "), +// it contains the characters used to indent at each level. +// This method produces a JSON text from a JavaScript value. +// When an object value is found, if the object contains a toJSON +// method, its toJSON method will be called and the result will be +// stringified. A toJSON method does not serialize: it returns the +// value represented by the name/value pair that should be serialized, +// or undefined if nothing should be serialized. The toJSON method +// will be passed the key associated with the value, and this will be +// bound to the value. + +// For example, this would serialize Dates as ISO strings. + +// Date.prototype.toJSON = function (key) { +// function f(n) { +// // Format integers to have at least two digits. +// return (n < 10) +// ? "0" + n +// : n; +// } +// return this.getUTCFullYear() + "-" + +// f(this.getUTCMonth() + 1) + "-" + +// f(this.getUTCDate()) + "T" + +// f(this.getUTCHours()) + ":" + +// f(this.getUTCMinutes()) + ":" + +// f(this.getUTCSeconds()) + "Z"; +// }; + +// You can provide an optional replacer method. It will be passed the +// key and value of each member, with this bound to the containing +// object. The value that is returned from your method will be +// serialized. If your method returns undefined, then the member will +// be excluded from the serialization. + +// If the replacer parameter is an array of strings, then it will be +// used to select the members to be serialized. It filters the results +// such that only members with keys listed in the replacer array are +// stringified. + +// Values that do not have JSON representations, such as undefined or +// functions, will not be serialized. Such values in objects will be +// dropped; in arrays they will be replaced with null. You can use +// a replacer function to replace those with JSON values. + +// JSON.stringify(undefined) returns undefined. + +// The optional space parameter produces a stringification of the +// value that is filled with line breaks and indentation to make it +// easier to read. + +// If the space parameter is a non-empty string, then that string will +// be used for indentation. If the space parameter is a number, then +// the indentation will be that many spaces. + +// Example: + +// text = JSON.stringify(["e", {pluribus: "unum"}]); +// // text is '["e",{"pluribus":"unum"}]' + +// text = JSON.stringify(["e", {pluribus: "unum"}], null, "\t"); +// // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' + +// text = JSON.stringify([new Date()], function (key, value) { +// return this[key] instanceof Date +// ? "Date(" + this[key] + ")" +// : value; +// }); +// // text is '["Date(---current time---)"]' + +// JSON.parse(text, reviver) +// This method parses a JSON text to produce an object or array. +// It can throw a SyntaxError exception. + +// The optional reviver parameter is a function that can filter and +// transform the results. It receives each of the keys and values, +// and its return value is used instead of the original value. +// If it returns what it received, then the structure is not modified. +// If it returns undefined then the member is deleted. + +// Example: + +// // Parse the text. Values that look like ISO date strings will +// // be converted to Date objects. + +// myData = JSON.parse(text, function (key, value) { +// var a; +// if (typeof value === "string") { +// a = +// /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); +// if (a) { +// return new Date(Date.UTC( +// +a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6] +// )); +// } +// return value; +// } +// }); + +// myData = JSON.parse( +// "[\"Date(09/09/2001)\"]", +// function (key, value) { +// var d; +// if ( +// typeof value === "string" +// && value.slice(0, 5) === "Date(" +// && value.slice(-1) === ")" +// ) { +// d = new Date(value.slice(5, -1)); +// if (d) { +// return d; +// } +// } +// return value; +// } +// ); + +// This is a reference implementation. You are free to copy, modify, or +// redistribute. + +/*jslint + eval, for, this +*/ + +/*property + JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, + lastIndex, length, parse, prototype, push, replace, slice, stringify, + test, toJSON, toString, valueOf +*/ + + +// Create a JSON object only if one does not already exist. We create the +// methods in a closure to avoid creating global variables. + +if (typeof JSON !== "object") { + JSON = {}; +} + +(function () { + "use strict"; + + var rx_one = /^[\],:{}\s]*$/; + var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g; + var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g; + var rx_four = /(?:^|:|,)(?:\s*\[)+/g; + var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; + var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; + + function f(n) { + // Format integers to have at least two digits. + return (n < 10) + ? "0" + n + : n; + } + + function this_value() { + return this.valueOf(); + } + + if (typeof Date.prototype.toJSON !== "function") { + + Date.prototype.toJSON = function () { + + return isFinite(this.valueOf()) + ? ( + this.getUTCFullYear() + + "-" + + f(this.getUTCMonth() + 1) + + "-" + + f(this.getUTCDate()) + + "T" + + f(this.getUTCHours()) + + ":" + + f(this.getUTCMinutes()) + + ":" + + f(this.getUTCSeconds()) + + "Z" + ) + : null; + }; + + Boolean.prototype.toJSON = this_value; + Number.prototype.toJSON = this_value; + String.prototype.toJSON = this_value; + } + + var gap; + var indent; + var meta; + var rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + rx_escapable.lastIndex = 0; + return rx_escapable.test(string) + ? "\"" + string.replace(rx_escapable, function (a) { + var c = meta[a]; + return typeof c === "string" + ? c + : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4); + }) + "\"" + : "\"" + string + "\""; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + var i; // The loop counter. + var k; // The member key. + var v; // The member value. + var length; + var mind = gap; + var partial; + var value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if ( + value + && typeof value === "object" + && typeof value.toJSON === "function" + ) { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === "function") { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case "string": + return quote(value); + + case "number": + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return (isFinite(value)) + ? String(value) + : "null"; + + case "boolean": + case "null": + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce "null". The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is "object", we might be dealing with an object or an array or +// null. + + case "object": + +// Due to a specification blunder in ECMAScript, typeof null is "object", +// so watch out for that case. + + if (!value) { + return "null"; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// Is the value an array? + + if (Object.prototype.toString.apply(value) === "[object Array]") { + +// The value is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || "null"; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 + ? "[]" + : gap + ? ( + "[\n" + + gap + + partial.join(",\n" + gap) + + "\n" + + mind + + "]" + ) + : "[" + partial.join(",") + "]"; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === "object") { + length = rep.length; + for (i = 0; i < length; i += 1) { + if (typeof rep[i] === "string") { + k = rep[i]; + v = str(k, value); + if (v) { + partial.push(quote(k) + ( + (gap) + ? ": " + : ":" + ) + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + ( + (gap) + ? ": " + : ":" + ) + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 + ? "{}" + : gap + ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}" + : "{" + partial.join(",") + "}"; + gap = mind; + return v; + } + } + +// If the JSON object does not yet have a stringify method, give it one. + + if (typeof JSON.stringify !== "function") { + meta = { // table of character substitutions + "\b": "\\b", + "\t": "\\t", + "\n": "\\n", + "\f": "\\f", + "\r": "\\r", + "\"": "\\\"", + "\\": "\\\\" + }; + JSON.stringify = function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + var i; + gap = ""; + indent = ""; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === "number") { + for (i = 0; i < space; i += 1) { + indent += " "; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === "string") { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== "function" && ( + typeof replacer !== "object" + || typeof replacer.length !== "number" + )) { + throw new Error("JSON.stringify"); + } + +// Make a fake root object containing our value under the key of "". +// Return the result of stringifying the value. + + return str("", {"": value}); + }; + } + + +// If the JSON object does not yet have a parse method, give it one. + + if (typeof JSON.parse !== "function") { + JSON.parse = function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + var k; + var v; + var value = holder[key]; + if (value && typeof value === "object") { + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + text = String(text); + rx_dangerous.lastIndex = 0; + if (rx_dangerous.test(text)) { + text = text.replace(rx_dangerous, function (a) { + return ( + "\\u" + + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) + ); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with "()" and "new" +// because they can cause invocation, and "=" because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with "@" (a non-JSON character). Second, we +// replace all simple value tokens with "]" characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or "]" or +// "," or ":" or "{" or "}". If that is so, then the text is safe for eval. + + if ( + rx_one.test( + text + .replace(rx_two, "@") + .replace(rx_three, "]") + .replace(rx_four, "") + ) + ) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The "{" operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval("(" + text + ")"); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return (typeof reviver === "function") + ? walk({"": j}, "") + : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError("JSON.parse"); + }; + } +}()); diff --git a/bin/concat.js b/bin/concat.js index 7601417..8e40ba8 100644 --- a/bin/concat.js +++ b/bin/concat.js @@ -1,4 +1,4 @@ -const folders = ['./Array/', './Function/', './Object/', './String/', './Date/']; +const folders = ['./Array/', './Function/', './JSON/', './Object/', './String/', './Date/']; // const testFolder = './Array/'; const fs = require('fs'); const path = require('path'); diff --git a/index.js b/index.js index f7d6ed0..709bfea 100644 --- a/index.js +++ b/index.js @@ -1,75 +1,33 @@ -//trim.js -/* -https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/Trim -*/ -if (!String.prototype.trim) { - // Вырезаем BOM и неразрывный пробел - String.prototype.trim = function() { - return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); - }; -} -//every.js +//bind.js /* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every -*/ -if (!Array.prototype.every) { - Array.prototype.every = function(callback, thisArg) { - var T, k; +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.every called on null or undefined'); +WARNING! Bound functions used as constructors NOT supported by this polyfill! +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Bound_functions_used_as_constructors +*/ +if (!Function.prototype.bind) { + Function.prototype.bind = function(oThis) { + if (this.__class__ !== 'Function') { + throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); } - // 1. Let O be the result of calling ToObject passing the this - // value as the argument. - var O = Object(this); - - // 2. Let lenValue be the result of calling the Get internal method - // of O with the argument "length". - // 3. Let len be ToUint32(lenValue). - var len = O.length >>> 0; + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof fNOP + ? this + : oThis, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; - // 4. If IsCallable(callback) is false, throw a TypeError exception. - if (callback.__class__ !== 'Function') { - throw new TypeError(callback + ' is not a function'); + if (this.prototype) { + // Function.prototype doesn't have a prototype property + fNOP.prototype = this.prototype; } + fBound.prototype = new fNOP(); - // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. - T = (arguments.length > 1) ? thisArg : void 0; - - // 6. Let k be 0. - k = 0; - - // 7. Repeat, while k < len - while (k < len) { - - var kValue; - - // a. Let Pk be ToString(k). - // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the HasProperty internal - // method of O with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - if (k in O) { - - // i. Let kValue be the result of calling the Get internal method - // of O with argument Pk. - kValue = O[k]; - - // ii. Let testResult be the result of calling the Call internal method - // of callback with T as the this value and argument list - // containing kValue, k, and O. - var testResult = callback.call(T, kValue, k, O); - - // iii. If ToBoolean(testResult) is false, return false. - if (!testResult) { - return false; - } - } - k++; - } - return true; + return fBound; }; } //filter.js @@ -239,17 +197,68 @@ if (!Array.prototype.indexOf) { return -1; }; } -//isArray.js +//every.js /* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every */ -if (!Array.isArray) { - Array.isArray = function(arg) { +if (!Array.prototype.every) { + Array.prototype.every = function(callback, thisArg) { + var T, k; - if (arg === void 0 || arg === null) { - return false; + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.every called on null or undefined'); } - return (arg.__class__ === 'Array'); + + // 1. Let O be the result of calling ToObject passing the this + // value as the argument. + var O = Object(this); + + // 2. Let lenValue be the result of calling the Get internal method + // of O with the argument "length". + // 3. Let len be ToUint32(lenValue). + var len = O.length >>> 0; + + // 4. If IsCallable(callback) is false, throw a TypeError exception. + if (callback.__class__ !== 'Function') { + throw new TypeError(callback + ' is not a function'); + } + + // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + T = (arguments.length > 1) ? thisArg : void 0; + + // 6. Let k be 0. + k = 0; + + // 7. Repeat, while k < len + while (k < len) { + + var kValue; + + // a. Let Pk be ToString(k). + // This is implicit for LHS operands of the in operator + // b. Let kPresent be the result of calling the HasProperty internal + // method of O with argument Pk. + // This step can be combined with c + // c. If kPresent is true, then + if (k in O) { + + // i. Let kValue be the result of calling the Get internal method + // of O with argument Pk. + kValue = O[k]; + + // ii. Let testResult be the result of calling the Call internal method + // of callback with T as the this value and argument list + // containing kValue, k, and O. + var testResult = callback.call(T, kValue, k, O); + + // iii. If ToBoolean(testResult) is false, return false. + if (!testResult) { + return false; + } + } + k++; + } + return true; }; } //lastIndexOf.js @@ -375,6 +384,49 @@ if (!Array.prototype.map) { return A; }; } +//isArray.js +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray +*/ +if (!Array.isArray) { + Array.isArray = function(arg) { + + if (arg === void 0 || arg === null) { + return false; + } + return (arg.__class__ === 'Array'); + }; +} +//some.js +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some +*/ +// Production steps of ECMA-262, Edition 5, 15.4.4.17 +// Reference: http://es5.github.io/#x15.4.4.17 +if (!Array.prototype.some) { + Array.prototype.some = function(callback, thisArg) { + + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.some called on null or undefined'); + } + + if (callback.__class__ !== 'Function') { + throw new TypeError(callback + ' is not a function'); + } + + var t = Object(this); + var len = t.length >>> 0; + + var T = arguments.length > 1 ? thisArg : void 0; + for (var i = 0; i < len; i++) { + if (i in t && callback.call(T, t[i], i, t)) { + return true; + } + } + + return false; + }; +} //reduce.js /* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce @@ -458,36 +510,6 @@ if (!Array.prototype.reduceRight) { return value; }; } -//some.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some -*/ -// Production steps of ECMA-262, Edition 5, 15.4.4.17 -// Reference: http://es5.github.io/#x15.4.4.17 -if (!Array.prototype.some) { - Array.prototype.some = function(callback, thisArg) { - - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.some called on null or undefined'); - } - - if (callback.__class__ !== 'Function') { - throw new TypeError(callback + ' is not a function'); - } - - var t = Object(this); - var len = t.length >>> 0; - - var T = arguments.length > 1 ? thisArg : void 0; - for (var i = 0; i < len; i++) { - if (i in t && callback.call(T, t[i], i, t)) { - return true; - } - } - - return false; - }; -} //create.js if (!Object.create) { // Production steps of ECMA-262, Edition 5, 15.2.3.5 @@ -542,6 +564,42 @@ if (!Object.create) { }; })(); } +//defineProperty.js +if (!Object.defineProperty) { + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + if (Object(object) !== object) { + throw new TypeError('Object.defineProperty can only be called on Objects.'); + } + + if (Object(descriptor) !== descriptor) { + throw new TypeError('Property description can only be an Object.'); + } + + if ('get' in descriptor || 'set' in descriptor) { + throw new TypeError('getters & setters can not be defined on this javascript engine'); + } + // If it's a data property. + if ('value' in descriptor) { + // fail silently if 'writable', 'enumerable', or 'configurable' + // are requested but not supported + // can't implement these features; allow true but not false + /* if ( + ('writable' in descriptor && !descriptor.writable) || + ('enumerable' in descriptor && !descriptor.enumerable) || + ('configurable' in descriptor && !descriptor.configurable) + ) + { + throw new RangeError('This implementation of Object.defineProperty does not support configurable, enumerable, or writable properties SET to FALSE.'); + }*/ + + + object[property] = descriptor.value; + } + return object; + } +} //defineProperties.js /* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties#Polyfill @@ -608,40 +666,30 @@ if (!Object.defineProperties) { return object; } } -//defineProperty.js -if (!Object.defineProperty) { - - Object.defineProperty = function defineProperty(object, property, descriptor) { +//getOwnPropertyDescriptor.js +if (!Object.getOwnPropertyDescriptor) { + Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) { if (Object(object) !== object) { - throw new TypeError('Object.defineProperty can only be called on Objects.'); + throw new TypeError('Object.getOwnPropertyDescriptor can only be called on Objects.'); } - if (Object(descriptor) !== descriptor) { - throw new TypeError('Property description can only be an Object.'); + var descriptor; + if (!Object.prototype.hasOwnProperty.call(object, property)) { + return descriptor; } - if ('get' in descriptor || 'set' in descriptor) { - throw new TypeError('getters & setters can not be defined on this javascript engine'); - } - // If it's a data property. - if ('value' in descriptor) { - // fail silently if 'writable', 'enumerable', or 'configurable' - // are requested but not supported - // can't implement these features; allow true but not false - /* if ( - ('writable' in descriptor && !descriptor.writable) || - ('enumerable' in descriptor && !descriptor.enumerable) || - ('configurable' in descriptor && !descriptor.configurable) - ) - { - throw new RangeError('This implementation of Object.defineProperty does not support configurable, enumerable, or writable properties SET to FALSE.'); - }*/ + descriptor = { + enumerable: Object.prototype.propertyIsEnumerable.call(object, property), + configurable: true + }; + descriptor.value = object[property]; - object[property] = descriptor.value; - } - return object; + var psPropertyType = object.reflect.find(property).type; + descriptor.writable = !(psPropertyType === "readonly"); + + return descriptor; } } //freeze.js @@ -688,31 +736,16 @@ if (!Object.getOwnPropertyNames) { return names; }; } -//getOwnPropertyDescriptor.js -if (!Object.getOwnPropertyDescriptor) { - - Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) { +//isExtensible.js +// ES5 15.2.3.13 +// http://es5.github.com/#x15.2.3.13 +if (!Object.isExtensible) { + Object.isExtensible = function isExtensible(object) { if (Object(object) !== object) { - throw new TypeError('Object.getOwnPropertyDescriptor can only be called on Objects.'); - } - - var descriptor; - if (!Object.prototype.hasOwnProperty.call(object, property)) { - return descriptor; + throw new TypeError('Object.isExtensible can only be called on Objects.'); } - - descriptor = { - enumerable: Object.prototype.propertyIsEnumerable.call(object, property), - configurable: true - }; - - descriptor.value = object[property]; - - var psPropertyType = object.reflect.find(property).type; - descriptor.writable = !(psPropertyType === "readonly"); - - return descriptor; - } + return true; + }; } //getPrototypeOf.js if (!Object.getPrototypeOf) { @@ -723,15 +756,18 @@ if (!Object.getPrototypeOf) { return object.__proto__; } } -//isExtensible.js -// ES5 15.2.3.13 -// http://es5.github.com/#x15.2.3.13 -if (!Object.isExtensible) { - Object.isExtensible = function isExtensible(object) { +//isSealed.js +/* +https://github.com/es-shims/es5-shim/blob/master/es5-sham.js +*/ +// ES5 15.2.3.11 +// http://es5.github.com/#x15.2.3.11 +if (!Object.isSealed) { + Object.isSealed = function isSealed(object) { if (Object(object) !== object) { - throw new TypeError('Object.isExtensible can only be called on Objects.'); + throw new TypeError('Object.isSealed can only be called on Objects.'); } - return true; + return false; }; } //isFrozen.js @@ -748,20 +784,6 @@ if (!Object.isFrozen) { return false; }; } -//isSealed.js -/* -https://github.com/es-shims/es5-shim/blob/master/es5-sham.js -*/ -// ES5 15.2.3.11 -// http://es5.github.com/#x15.2.3.11 -if (!Object.isSealed) { - Object.isSealed = function isSealed(object) { - if (Object(object) !== object) { - throw new TypeError('Object.isSealed can only be called on Objects.'); - } - return false; - }; -} //keys.js if (!Object.keys) { Object.keys = function(object) { @@ -813,37 +835,547 @@ if (!Object.seal) { return object; }; } -//bind.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill +//json2.js +// json2.js +// 2017-06-12 +// Public Domain. +// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + +// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO +// NOT CONTROL. + +// This file creates a global JSON object containing two methods: stringify +// and parse. This file provides the ES5 JSON capability to ES3 systems. +// If a project might run on IE8 or earlier, then this file should be included. +// This file does nothing on ES5 systems. + +// JSON.stringify(value, replacer, space) +// value any JavaScript value, usually an object or array. +// replacer an optional parameter that determines how object +// values are stringified for objects. It can be a +// function or an array of strings. +// space an optional parameter that specifies the indentation +// of nested structures. If it is omitted, the text will +// be packed without extra whitespace. If it is a number, +// it will specify the number of spaces to indent at each +// level. If it is a string (such as "\t" or " "), +// it contains the characters used to indent at each level. +// This method produces a JSON text from a JavaScript value. +// When an object value is found, if the object contains a toJSON +// method, its toJSON method will be called and the result will be +// stringified. A toJSON method does not serialize: it returns the +// value represented by the name/value pair that should be serialized, +// or undefined if nothing should be serialized. The toJSON method +// will be passed the key associated with the value, and this will be +// bound to the value. + +// For example, this would serialize Dates as ISO strings. + +// Date.prototype.toJSON = function (key) { +// function f(n) { +// // Format integers to have at least two digits. +// return (n < 10) +// ? "0" + n +// : n; +// } +// return this.getUTCFullYear() + "-" + +// f(this.getUTCMonth() + 1) + "-" + +// f(this.getUTCDate()) + "T" + +// f(this.getUTCHours()) + ":" + +// f(this.getUTCMinutes()) + ":" + +// f(this.getUTCSeconds()) + "Z"; +// }; + +// You can provide an optional replacer method. It will be passed the +// key and value of each member, with this bound to the containing +// object. The value that is returned from your method will be +// serialized. If your method returns undefined, then the member will +// be excluded from the serialization. + +// If the replacer parameter is an array of strings, then it will be +// used to select the members to be serialized. It filters the results +// such that only members with keys listed in the replacer array are +// stringified. + +// Values that do not have JSON representations, such as undefined or +// functions, will not be serialized. Such values in objects will be +// dropped; in arrays they will be replaced with null. You can use +// a replacer function to replace those with JSON values. + +// JSON.stringify(undefined) returns undefined. + +// The optional space parameter produces a stringification of the +// value that is filled with line breaks and indentation to make it +// easier to read. + +// If the space parameter is a non-empty string, then that string will +// be used for indentation. If the space parameter is a number, then +// the indentation will be that many spaces. + +// Example: + +// text = JSON.stringify(["e", {pluribus: "unum"}]); +// // text is '["e",{"pluribus":"unum"}]' + +// text = JSON.stringify(["e", {pluribus: "unum"}], null, "\t"); +// // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' + +// text = JSON.stringify([new Date()], function (key, value) { +// return this[key] instanceof Date +// ? "Date(" + this[key] + ")" +// : value; +// }); +// // text is '["Date(---current time---)"]' + +// JSON.parse(text, reviver) +// This method parses a JSON text to produce an object or array. +// It can throw a SyntaxError exception. + +// The optional reviver parameter is a function that can filter and +// transform the results. It receives each of the keys and values, +// and its return value is used instead of the original value. +// If it returns what it received, then the structure is not modified. +// If it returns undefined then the member is deleted. + +// Example: + +// // Parse the text. Values that look like ISO date strings will +// // be converted to Date objects. + +// myData = JSON.parse(text, function (key, value) { +// var a; +// if (typeof value === "string") { +// a = +// /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); +// if (a) { +// return new Date(Date.UTC( +// +a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6] +// )); +// } +// return value; +// } +// }); + +// myData = JSON.parse( +// "[\"Date(09/09/2001)\"]", +// function (key, value) { +// var d; +// if ( +// typeof value === "string" +// && value.slice(0, 5) === "Date(" +// && value.slice(-1) === ")" +// ) { +// d = new Date(value.slice(5, -1)); +// if (d) { +// return d; +// } +// } +// return value; +// } +// ); + +// This is a reference implementation. You are free to copy, modify, or +// redistribute. + +/*jslint + eval, for, this +*/ -WARNING! Bound functions used as constructors NOT supported by this polyfill! -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Bound_functions_used_as_constructors +/*property + JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, + lastIndex, length, parse, prototype, push, replace, slice, stringify, + test, toJSON, toString, valueOf */ -if (!Function.prototype.bind) { - Function.prototype.bind = function(oThis) { - if (this.__class__ !== 'Function') { - throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); + + +// Create a JSON object only if one does not already exist. We create the +// methods in a closure to avoid creating global variables. + +if (typeof JSON !== "object") { + JSON = {}; +} + +(function () { + "use strict"; + + var rx_one = /^[\],:{}\s]*$/; + var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g; + var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g; + var rx_four = /(?:^|:|,)(?:\s*\[)+/g; + var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; + var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; + + function f(n) { + // Format integers to have at least two digits. + return (n < 10) + ? "0" + n + : n; } - var aArgs = Array.prototype.slice.call(arguments, 1), - fToBind = this, - fNOP = function() {}, - fBound = function() { - return fToBind.apply(this instanceof fNOP - ? this - : oThis, - aArgs.concat(Array.prototype.slice.call(arguments))); + function this_value() { + return this.valueOf(); + } + + if (typeof Date.prototype.toJSON !== "function") { + + Date.prototype.toJSON = function () { + + return isFinite(this.valueOf()) + ? ( + this.getUTCFullYear() + + "-" + + f(this.getUTCMonth() + 1) + + "-" + + f(this.getUTCDate()) + + "T" + + f(this.getUTCHours()) + + ":" + + f(this.getUTCMinutes()) + + ":" + + f(this.getUTCSeconds()) + + "Z" + ) + : null; }; - if (this.prototype) { - // Function.prototype doesn't have a prototype property - fNOP.prototype = this.prototype; + Boolean.prototype.toJSON = this_value; + Number.prototype.toJSON = this_value; + String.prototype.toJSON = this_value; } - fBound.prototype = new fNOP(); - return fBound; - }; + var gap; + var indent; + var meta; + var rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + rx_escapable.lastIndex = 0; + return rx_escapable.test(string) + ? "\"" + string.replace(rx_escapable, function (a) { + var c = meta[a]; + return typeof c === "string" + ? c + : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4); + }) + "\"" + : "\"" + string + "\""; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + var i; // The loop counter. + var k; // The member key. + var v; // The member value. + var length; + var mind = gap; + var partial; + var value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if ( + value + && typeof value === "object" + && typeof value.toJSON === "function" + ) { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === "function") { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case "string": + return quote(value); + + case "number": + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return (isFinite(value)) + ? String(value) + : "null"; + + case "boolean": + case "null": + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce "null". The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is "object", we might be dealing with an object or an array or +// null. + + case "object": + +// Due to a specification blunder in ECMAScript, typeof null is "object", +// so watch out for that case. + + if (!value) { + return "null"; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// Is the value an array? + + if (Object.prototype.toString.apply(value) === "[object Array]") { + +// The value is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || "null"; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 + ? "[]" + : gap + ? ( + "[\n" + + gap + + partial.join(",\n" + gap) + + "\n" + + mind + + "]" + ) + : "[" + partial.join(",") + "]"; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === "object") { + length = rep.length; + for (i = 0; i < length; i += 1) { + if (typeof rep[i] === "string") { + k = rep[i]; + v = str(k, value); + if (v) { + partial.push(quote(k) + ( + (gap) + ? ": " + : ":" + ) + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + ( + (gap) + ? ": " + : ":" + ) + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 + ? "{}" + : gap + ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}" + : "{" + partial.join(",") + "}"; + gap = mind; + return v; + } + } + +// If the JSON object does not yet have a stringify method, give it one. + + if (typeof JSON.stringify !== "function") { + meta = { // table of character substitutions + "\b": "\\b", + "\t": "\\t", + "\n": "\\n", + "\f": "\\f", + "\r": "\\r", + "\"": "\\\"", + "\\": "\\\\" + }; + JSON.stringify = function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + var i; + gap = ""; + indent = ""; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === "number") { + for (i = 0; i < space; i += 1) { + indent += " "; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === "string") { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== "function" && ( + typeof replacer !== "object" + || typeof replacer.length !== "number" + )) { + throw new Error("JSON.stringify"); + } + +// Make a fake root object containing our value under the key of "". +// Return the result of stringifying the value. + + return str("", {"": value}); + }; + } + + +// If the JSON object does not yet have a parse method, give it one. + + if (typeof JSON.parse !== "function") { + JSON.parse = function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + var k; + var v; + var value = holder[key]; + if (value && typeof value === "object") { + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + text = String(text); + rx_dangerous.lastIndex = 0; + if (rx_dangerous.test(text)) { + text = text.replace(rx_dangerous, function (a) { + return ( + "\\u" + + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) + ); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with "()" and "new" +// because they can cause invocation, and "=" because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with "@" (a non-JSON character). Second, we +// replace all simple value tokens with "]" characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or "]" or +// "," or ":" or "{" or "}". If that is so, then the text is safe for eval. + + if ( + rx_one.test( + text + .replace(rx_two, "@") + .replace(rx_three, "]") + .replace(rx_four, "") + ) + ) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The "{" operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval("(" + text + ")"); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return (typeof reviver === "function") + ? walk({"": j}, "") + : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError("JSON.parse"); + }; + } +}()); + +//trim.js +/* +https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/Trim +*/ +if (!String.prototype.trim) { + // Вырезаем BOM и неразрывный пробел + String.prototype.trim = function() { + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + }; } //toISOString.js /* From c414892056e1399b1ef43fd8feef2a4a5d0b83ff Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 7 Oct 2019 11:51:01 +0200 Subject: [PATCH 2/7] add types file --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 189910c..44e926e 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.2.0", "description": "a collection of useful es5-shims for Extendscript", "main": "index.js", + "types": "index.d.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "bundle": "node bin/concat.js" From 032d3e90f886b626ef3fcfa09dcabddd4b5363cf Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 7 Oct 2019 13:07:15 +0200 Subject: [PATCH 3/7] add TypeScript-Definition files update concat script --- Array.d.ts | 122 ++++++++++++++++++++++++++++++++++++++++++++++++ Date.d.ts | 20 ++++++++ Function.d.ts | 27 +++++++++++ JSON.d.ts | 45 ++++++++++++++++++ Object.d.ts | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++ String.d.ts | 19 ++++++++ bin/concat.js | 62 +++++++++++++++++------- 7 files changed, 405 insertions(+), 17 deletions(-) create mode 100644 Array.d.ts create mode 100644 Date.d.ts create mode 100644 Function.d.ts create mode 100644 JSON.d.ts create mode 100644 Object.d.ts create mode 100644 String.d.ts diff --git a/Array.d.ts b/Array.d.ts new file mode 100644 index 0000000..acdcd1f --- /dev/null +++ b/Array.d.ts @@ -0,0 +1,122 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +interface ArrayConstructor { + isArray(arg: any): arg is any[]; +} + +interface Array { + /** + * Determines whether all the members of an array satisfy the specified test. + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in the array until the callbackfn returns a value + * which is coercible to the Boolean value false, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + every(callbackfn: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean; + + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; + + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + filter(callbackfn: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[]; + + /** + * Performs the specified action for each element in an array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; + + /** + * Returns the index of the first occurrence of a value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. + */ + indexOf(searchElement: T, fromIndex?: number): number; + + /** + * Returns the index of the last occurrence of a specified value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array. + */ + lastIndexOf(searchElement: T, fromIndex?: number): number; + + /** + * Calls a defined callback function on each element of an array, and returns an array that contains the results. + * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; + + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + */ + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; + + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; + + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; + + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + */ + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; + + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; + + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; + + /** + * Determines whether the specified callback function returns true for any element of an array. + * @param callbackfn A function that accepts up to three arguments. The some method calls + * the callbackfn function for each element in the array until the callbackfn returns a value + * which is coercible to the Boolean value true, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + some(callbackfn: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean; +} diff --git a/Date.d.ts b/Date.d.ts new file mode 100644 index 0000000..4df2ea1 --- /dev/null +++ b/Date.d.ts @@ -0,0 +1,20 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +/** Enables basic storage and retrieval of dates and times. */ +interface Date { + /** Returns a date as a string value in ISO format. */ + toISOString(): string; +} \ No newline at end of file diff --git a/Function.d.ts b/Function.d.ts new file mode 100644 index 0000000..e325294 --- /dev/null +++ b/Function.d.ts @@ -0,0 +1,27 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +/** + * Creates a new function. + */ +interface Function { + /** + * For a given function, creates a bound function that has the same body as the original function. + * The this object of the bound function is associated with the specified object, and has the specified initial parameters. + * @param thisArg An object to which the this keyword can refer inside the new function. + * @param argArray A list of arguments to be passed to the new function. + */ + bind(this: Function, thisArg: any, ...argArray: any[]): any; +} \ No newline at end of file diff --git a/JSON.d.ts b/JSON.d.ts new file mode 100644 index 0000000..78842b9 --- /dev/null +++ b/JSON.d.ts @@ -0,0 +1,45 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +interface JSON { + /** + * Converts a JavaScript Object Notation (JSON) string into an object. + * @param text A valid JSON string. + * @param reviver A function that transforms the results. This function is called for each member of the object. + * If a member contains nested objects, the nested objects are transformed before the parent object is. + */ + parse(text: string, reviver?: (this: any, key: string, value: any) => any): any; + + /** + * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. + * @param value A JavaScript value, usually an object or array, to be converted. + * @param replacer A function that transforms the results. + * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. + */ + stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; + + /** + * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. + * @param value A JavaScript value, usually an object or array, to be converted. + * @param replacer An array of strings and numbers that acts as a approved list for selecting the object properties that will be stringified. + * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. + */ + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; +} + +/** + * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. + */ +declare var JSON: JSON; diff --git a/Object.d.ts b/Object.d.ts new file mode 100644 index 0000000..0af6f08 --- /dev/null +++ b/Object.d.ts @@ -0,0 +1,127 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + + +interface PropertyDescriptor { + configurable?: boolean; + enumerable?: boolean; + value?: any; + writable?: boolean; + + get?(): any; + + set?(v: any): void; +} + +interface PropertyDescriptorMap { + [s: string]: PropertyDescriptor; +} + +interface ObjectConstructor { + /** + * Creates an object that has the specified prototype or that has null prototype. + * @param o Object to use as a prototype. May be null. + */ + create(o: object | null): any; + + /** + * Adds a property to an object, or modifies attributes of an existing property. + * @param o Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object. + * @param p The property name. + * @param attributes Descriptor for the property. It can be for a data property or an accessor property. + */ + defineProperty(o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType): any; + + /** + * Adds one or more properties to an object, and/or modifies attributes of existing properties. + * @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object. + * @param properties JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property. + */ + defineProperties(o: any, properties: PropertyDescriptorMap & ThisType): any; + + /** + * Prevents the modification of existing property attributes and values, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + freeze(o: T[]): readonly T[]; + + /** + * Prevents the modification of existing property attributes and values, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + freeze(o: T): T; + + /** + * Prevents the modification of existing property attributes and values, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + freeze(o: T): Readonly; + + /** + * Gets the own property descriptor of the specified object. + * An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype. + * @param o Object that contains the property. + * @param p Name of the property. + */ + getOwnPropertyDescriptor(o: any, p: PropertyKey): PropertyDescriptor | undefined; + + /** + * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly + * on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions. + * @param o Object that contains the own properties. + */ + getOwnPropertyNames(o: any): string[]; + + /** + * Returns a value that indicates whether new properties can be added to an object. + * @param o Object to test. + */ + isExtensible(o: any): boolean; + + /** + * Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object. + * @param o Object to test. + */ + isFrozen(o: any): boolean; + + /** + * Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object. + * @param o Object to test. + */ + isSealed(o: any): boolean; + + /** + * Returns the names of the enumerable string properties and methods of an object. + * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. + */ + keys(o: object): string[]; + + /** + * Prevents the addition of new properties to an object. + * @param o Object to make non-extensible. + */ + preventExtensions(o: T): T; + + /** + * Prevents the modification of attributes of existing properties, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + seal(o: T): T; +} + +/** + * Provides functionality common to all JavaScript objects. + */ +declare var Object: ObjectConstructor; diff --git a/String.d.ts b/String.d.ts new file mode 100644 index 0000000..04155eb --- /dev/null +++ b/String.d.ts @@ -0,0 +1,19 @@ +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +interface String { + /** Removes the leading and trailing white space and line terminator characters from a string. */ + trim(): string; +} diff --git a/bin/concat.js b/bin/concat.js index 8e40ba8..4a4725c 100644 --- a/bin/concat.js +++ b/bin/concat.js @@ -1,27 +1,55 @@ const folders = ['./Array/', './Function/', './JSON/', './Object/', './String/', './Date/']; -// const testFolder = './Array/'; const fs = require('fs'); const path = require('path'); const cat = require('cat'); const bundlePath = path.resolve(process.cwd(), './index.js'); +const bundleTypeScriptDefinitionPath = path.resolve(process.cwd(), './index.d.ts'); +let hasLicense = false; + +// clear the files (if not exists, it will be created) +fs.writeFileSync(bundlePath, ''); +fs.writeFileSync(bundleTypeScriptDefinitionPath, ''); -// clear the file -fs.writeFileSync(path.resolve(process.cwd(), bundlePath), ''); // loop folders folders.forEach(folder => { - fs.readdir(folder, (err, files) => { - files = files.filter(file => !(/(^|\/)\.[^\/\.]/g).test(file)) - files.forEach(file => { - // console.log(file); - let filePath = path.resolve(process.cwd(), `${folder}${file}`); - // console.log(filePath); - cat(filePath, (error, data)=>{ - if(error !== null) { - console.log(error); - process.exit(); - } - fs.appendFileSync(bundlePath, `//${file}\n${data}\n`); - }); + + fs.readdir(folder, (err, files) => { + files = files.filter(file => !(/(^|\/)\.[^\/\.]/g).test(file)); + files.forEach(file => { + let filePath = path.resolve(process.cwd(), `${folder}${file}`); + cat(filePath, (error, data) => { + if (error !== null) { + console.log(error); + process.exit(); + } + fs.appendFileSync(bundlePath, `//${file}\n${data}\n`); + }); + }); + }); - }); + + // build TypeScript-Definition path + const tsdFilename = `${path.basename(folder)}.d.ts`; + const tsdPath = path.resolve(process.cwd(), tsdFilename); + + // if TypeScript-Definition exists + if (fs.existsSync(tsdPath)) { + cat(tsdPath, (error, data) => { + if (error !== null) { + console.log(error); + process.exit(); + } + + + if (!hasLicense) { + // add one times Apache license + hasLicense = true; + } else { + // remove Apache License + data = data.split('\n').slice(14).join('\n'); + } + + fs.appendFileSync(bundleTypeScriptDefinitionPath, `// ${tsdFilename}\n${data}\n`); + }); + } }); From 7326a4528e00041619e17969701b466b0081fcff Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 7 Oct 2019 13:19:45 +0200 Subject: [PATCH 4/7] fix missing declaration --- Array.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Array.d.ts b/Array.d.ts index acdcd1f..603f884 100644 --- a/Array.d.ts +++ b/Array.d.ts @@ -120,3 +120,5 @@ interface Array { */ some(callbackfn: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean; } + +declare var Array: ArrayConstructor; \ No newline at end of file From 7b0db577a328bf38bc1e49adf02d67c311cb64ab Mon Sep 17 00:00:00 2001 From: Manuel Date: Mon, 7 Oct 2019 13:21:04 +0200 Subject: [PATCH 5/7] add TypeScript-Definition bundle --- index.d.ts | 301 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 301 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..3b8a6fa --- /dev/null +++ b/index.d.ts @@ -0,0 +1,301 @@ +// Array.d.ts +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at http://www.apache.org/licenses/LICENSE-2.0 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ + +interface ArrayConstructor { + isArray(arg: any): arg is any[]; +} + +interface Array { + /** + * Determines whether all the members of an array satisfy the specified test. + * @param callbackfn A function that accepts up to three arguments. The every method calls + * the callbackfn function for each element in the array until the callbackfn returns a value + * which is coercible to the Boolean value false, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + every(callbackfn: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean; + + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + filter(callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; + + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + filter(callbackfn: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T[]; + + /** + * Performs the specified action for each element in an array. + * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void; + + /** + * Returns the index of the first occurrence of a value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. + */ + indexOf(searchElement: T, fromIndex?: number): number; + + /** + * Returns the index of the last occurrence of a specified value in an array. + * @param searchElement The value to locate in the array. + * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array. + */ + lastIndexOf(searchElement: T, fromIndex?: number): number; + + /** + * Calls a defined callback function on each element of an array, and returns an array that contains the results. + * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. + */ + map(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[]; + + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + */ + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; + + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; + + /** + * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; + + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + */ + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T; + + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T; + + /** + * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. + * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. + * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. + */ + reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U; + + /** + * Determines whether the specified callback function returns true for any element of an array. + * @param callbackfn A function that accepts up to three arguments. The some method calls + * the callbackfn function for each element in the array until the callbackfn returns a value + * which is coercible to the Boolean value true, or until the end of the array. + * @param thisArg An object to which the this keyword can refer in the callbackfn function. + * If thisArg is omitted, undefined is used as the this value. + */ + some(callbackfn: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean; +} + +declare var Array: ArrayConstructor; +// Function.d.ts + +/** + * Creates a new function. + */ +interface Function { + /** + * For a given function, creates a bound function that has the same body as the original function. + * The this object of the bound function is associated with the specified object, and has the specified initial parameters. + * @param thisArg An object to which the this keyword can refer inside the new function. + * @param argArray A list of arguments to be passed to the new function. + */ + bind(this: Function, thisArg: any, ...argArray: any[]): any; +} +// JSON.d.ts + +interface JSON { + /** + * Converts a JavaScript Object Notation (JSON) string into an object. + * @param text A valid JSON string. + * @param reviver A function that transforms the results. This function is called for each member of the object. + * If a member contains nested objects, the nested objects are transformed before the parent object is. + */ + parse(text: string, reviver?: (this: any, key: string, value: any) => any): any; + + /** + * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. + * @param value A JavaScript value, usually an object or array, to be converted. + * @param replacer A function that transforms the results. + * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. + */ + stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string; + + /** + * Converts a JavaScript value to a JavaScript Object Notation (JSON) string. + * @param value A JavaScript value, usually an object or array, to be converted. + * @param replacer An array of strings and numbers that acts as a approved list for selecting the object properties that will be stringified. + * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. + */ + stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string; +} + +/** + * An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format. + */ +declare var JSON: JSON; + +// Object.d.ts + + +interface PropertyDescriptor { + configurable?: boolean; + enumerable?: boolean; + value?: any; + writable?: boolean; + + get?(): any; + + set?(v: any): void; +} + +interface PropertyDescriptorMap { + [s: string]: PropertyDescriptor; +} + +interface ObjectConstructor { + /** + * Creates an object that has the specified prototype or that has null prototype. + * @param o Object to use as a prototype. May be null. + */ + create(o: object | null): any; + + /** + * Adds a property to an object, or modifies attributes of an existing property. + * @param o Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object. + * @param p The property name. + * @param attributes Descriptor for the property. It can be for a data property or an accessor property. + */ + defineProperty(o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType): any; + + /** + * Adds one or more properties to an object, and/or modifies attributes of existing properties. + * @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object. + * @param properties JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property. + */ + defineProperties(o: any, properties: PropertyDescriptorMap & ThisType): any; + + /** + * Prevents the modification of existing property attributes and values, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + freeze(o: T[]): readonly T[]; + + /** + * Prevents the modification of existing property attributes and values, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + freeze(o: T): T; + + /** + * Prevents the modification of existing property attributes and values, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + freeze(o: T): Readonly; + + /** + * Gets the own property descriptor of the specified object. + * An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype. + * @param o Object that contains the property. + * @param p Name of the property. + */ + getOwnPropertyDescriptor(o: any, p: PropertyKey): PropertyDescriptor | undefined; + + /** + * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly + * on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions. + * @param o Object that contains the own properties. + */ + getOwnPropertyNames(o: any): string[]; + + /** + * Returns a value that indicates whether new properties can be added to an object. + * @param o Object to test. + */ + isExtensible(o: any): boolean; + + /** + * Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object. + * @param o Object to test. + */ + isFrozen(o: any): boolean; + + /** + * Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object. + * @param o Object to test. + */ + isSealed(o: any): boolean; + + /** + * Returns the names of the enumerable string properties and methods of an object. + * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. + */ + keys(o: object): string[]; + + /** + * Prevents the addition of new properties to an object. + * @param o Object to make non-extensible. + */ + preventExtensions(o: T): T; + + /** + * Prevents the modification of attributes of existing properties, and prevents the addition of new properties. + * @param o Object on which to lock the attributes. + */ + seal(o: T): T; +} + +/** + * Provides functionality common to all JavaScript objects. + */ +declare var Object: ObjectConstructor; + +// String.d.ts + +interface String { + /** Removes the leading and trailing white space and line terminator characters from a string. */ + trim(): string; +} + +// Date.d.ts + +/** Enables basic storage and retrieval of dates and times. */ +interface Date { + /** Returns a date as a string value in ISO format. */ + toISOString(): string; +} From bdaca6c21c1c2b952afa93310feab295b4bfc82c Mon Sep 17 00:00:00 2001 From: lumenn-home Date: Thu, 24 Oct 2019 22:15:36 +0200 Subject: [PATCH 6/7] Corrected tab indent, updated version --- bin/concat.js | 81 +++++++++++++++++++++++++-------------------------- package.json | 5 ++-- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/bin/concat.js b/bin/concat.js index 4a4725c..952f81b 100644 --- a/bin/concat.js +++ b/bin/concat.js @@ -11,45 +11,44 @@ fs.writeFileSync(bundlePath, ''); fs.writeFileSync(bundleTypeScriptDefinitionPath, ''); // loop folders -folders.forEach(folder => { - - fs.readdir(folder, (err, files) => { - files = files.filter(file => !(/(^|\/)\.[^\/\.]/g).test(file)); - files.forEach(file => { - let filePath = path.resolve(process.cwd(), `${folder}${file}`); - cat(filePath, (error, data) => { - if (error !== null) { - console.log(error); - process.exit(); - } - fs.appendFileSync(bundlePath, `//${file}\n${data}\n`); - }); - }); - +folders.forEach((folder) => { + fs.readdir(folder, (err, files) => { + files = files.filter((file) => !(/(^|\/)\.[^\/\.]/g).test(file)); + + files.forEach((file) => { + let filePath = path.resolve(process.cwd(), `${folder}${file}`); + cat(filePath, (error, data) => { + if (error !== null) { + console.log(error); + process.exit(); + } + + fs.appendFileSync(bundlePath, `//${file}\n${data}\n`); + }); }); - - // build TypeScript-Definition path - const tsdFilename = `${path.basename(folder)}.d.ts`; - const tsdPath = path.resolve(process.cwd(), tsdFilename); - - // if TypeScript-Definition exists - if (fs.existsSync(tsdPath)) { - cat(tsdPath, (error, data) => { - if (error !== null) { - console.log(error); - process.exit(); - } - - - if (!hasLicense) { - // add one times Apache license - hasLicense = true; - } else { - // remove Apache License - data = data.split('\n').slice(14).join('\n'); - } - - fs.appendFileSync(bundleTypeScriptDefinitionPath, `// ${tsdFilename}\n${data}\n`); - }); - } -}); + }); + + // build TypeScript-Definition path + const tsdFilename = `${path.basename(folder)}.d.ts`; + const tsdPath = path.resolve(process.cwd(), tsdFilename); + + // if TypeScript-Definition exists + if (fs.existsSync(tsdPath)) { + cat(tsdPath, (error, data) => { + if (error !== null) { + console.log(error); + process.exit(); + } + + if (!hasLicense) { + // add one times Apache license + hasLicense = true; + } else { + // remove Apache License + data = data.split('\n').slice(14).join('\n'); + } + + fs.appendFileSync(bundleTypeScriptDefinitionPath, `// ${tsdFilename}\n${data}\n`); + }); + } +}); \ No newline at end of file diff --git a/package.json b/package.json index 44e926e..9d0dbe0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "extendscript-es5-shim", - "version": "0.2.0", + "version": "0.3.0", "description": "a collection of useful es5-shims for Extendscript", "main": "index.js", "types": "index.d.ts", @@ -21,7 +21,8 @@ ], "contributers": [ "Fabian Morón Zirfas (http://fabianmoronzirfas.me)", - "EugenTepin" + "EugenTepin", + "MrSpoocy (https://github.com/MrSpoocy)" ], "license": "MIT", "bugs": { From 78e6f259625ce053b6421ff499d06e0df9c325b3 Mon Sep 17 00:00:00 2001 From: lumenn-home Date: Thu, 24 Oct 2019 22:18:43 +0200 Subject: [PATCH 7/7] Bundled after correcting version --- index.d.ts | 14 +- index.js | 2680 ++++++++++++++++++++++----------------------- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 1349 insertions(+), 1349 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3b8a6fa..71b8232 100644 --- a/index.d.ts +++ b/index.d.ts @@ -170,6 +170,13 @@ interface JSON { */ declare var JSON: JSON; +// String.d.ts + +interface String { + /** Removes the leading and trailing white space and line terminator characters from a string. */ + trim(): string; +} + // Object.d.ts @@ -285,13 +292,6 @@ interface ObjectConstructor { */ declare var Object: ObjectConstructor; -// String.d.ts - -interface String { - /** Removes the leading and trailing white space and line terminator characters from a string. */ - trim(): string; -} - // Date.d.ts /** Enables basic storage and retrieval of dates and times. */ diff --git a/index.js b/index.js index 709bfea..afa16b4 100644 --- a/index.js +++ b/index.js @@ -1,1381 +1,1381 @@ -//bind.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill - -WARNING! Bound functions used as constructors NOT supported by this polyfill! -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Bound_functions_used_as_constructors -*/ -if (!Function.prototype.bind) { - Function.prototype.bind = function(oThis) { - if (this.__class__ !== 'Function') { - throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); - } - - var aArgs = Array.prototype.slice.call(arguments, 1), - fToBind = this, - fNOP = function() {}, - fBound = function() { - return fToBind.apply(this instanceof fNOP - ? this - : oThis, - aArgs.concat(Array.prototype.slice.call(arguments))); - }; - - if (this.prototype) { - // Function.prototype doesn't have a prototype property - fNOP.prototype = this.prototype; - } - fBound.prototype = new fNOP(); - - return fBound; - }; +//every.js +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every +*/ +if (!Array.prototype.every) { + Array.prototype.every = function(callback, thisArg) { + var T, k; + + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.every called on null or undefined'); + } + + // 1. Let O be the result of calling ToObject passing the this + // value as the argument. + var O = Object(this); + + // 2. Let lenValue be the result of calling the Get internal method + // of O with the argument "length". + // 3. Let len be ToUint32(lenValue). + var len = O.length >>> 0; + + // 4. If IsCallable(callback) is false, throw a TypeError exception. + if (callback.__class__ !== 'Function') { + throw new TypeError(callback + ' is not a function'); + } + + // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + T = (arguments.length > 1) ? thisArg : void 0; + + // 6. Let k be 0. + k = 0; + + // 7. Repeat, while k < len + while (k < len) { + + var kValue; + + // a. Let Pk be ToString(k). + // This is implicit for LHS operands of the in operator + // b. Let kPresent be the result of calling the HasProperty internal + // method of O with argument Pk. + // This step can be combined with c + // c. If kPresent is true, then + if (k in O) { + + // i. Let kValue be the result of calling the Get internal method + // of O with argument Pk. + kValue = O[k]; + + // ii. Let testResult be the result of calling the Call internal method + // of callback with T as the this value and argument list + // containing kValue, k, and O. + var testResult = callback.call(T, kValue, k, O); + + // iii. If ToBoolean(testResult) is false, return false. + if (!testResult) { + return false; + } + } + k++; + } + return true; + }; } //filter.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter -*/ -if (!Array.prototype.filter) { - Array.prototype.filter = function(callback, thisArg) { - - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.filter called on null or undefined'); - } - - var t = Object(this); - var len = t.length >>> 0; - - if (callback.__class__ !== 'Function') { - throw new TypeError(callback + ' is not a function'); - } - - var res = []; - - var T = (arguments.length > 1) ? thisArg : void 0; - - for (var i = 0; i < len; i++) { - if (i in t) { - var val = t[i]; - - // NOTE: Technically this should Object.defineProperty at - // the next index, as push can be affected by - // properties on Object.prototype and Array.prototype. - // But that method's new, and collisions should be - // rare, so use the more-compatible alternative. - if (callback.call(T, val, i, t)) { - res.push(val); - } - } - } - - return res; - }; +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter +*/ +if (!Array.prototype.filter) { + Array.prototype.filter = function(callback, thisArg) { + + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.filter called on null or undefined'); + } + + var t = Object(this); + var len = t.length >>> 0; + + if (callback.__class__ !== 'Function') { + throw new TypeError(callback + ' is not a function'); + } + + var res = []; + + var T = (arguments.length > 1) ? thisArg : void 0; + + for (var i = 0; i < len; i++) { + if (i in t) { + var val = t[i]; + + // NOTE: Technically this should Object.defineProperty at + // the next index, as push can be affected by + // properties on Object.prototype and Array.prototype. + // But that method's new, and collisions should be + // rare, so use the more-compatible alternative. + if (callback.call(T, val, i, t)) { + res.push(val); + } + } + } + + return res; + }; } //forEach.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach -*/ -// Production steps of ECMA-262, Edition 5, 15.4.4.18 -// Reference: http://es5.github.io/#x15.4.4.18 -if (!Array.prototype.forEach) { - Array.prototype.forEach = function(callback, thisArg) { - - - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.forEach called on null or undefined'); - } - - // 1. Let O be the result of calling toObject() passing the - // |this| value as the argument. - var O = Object(this); - - // 2. Let lenValue be the result of calling the Get() internal - // method of O with the argument "length". - // 3. Let len be toUint32(lenValue). - var len = O.length >>> 0; - - // 4. If isCallable(callback) is false, throw a TypeError exception. - // See: http://es5.github.com/#x9.11 - if (callback.__class__ !== 'Function') { - throw new TypeError(callback + ' is not a function'); - } - - // 5. If thisArg was supplied, let T be thisArg; else let - // T be undefined. - var T = (arguments.length > 1) ? thisArg : void 0; - - - // 6. Let k be 0 - //k = 0; - - // 7. Repeat, while k < len - for (var k = 0; k < len; k++) { - var kValue; - // a. Let Pk be ToString(k). - // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the HasProperty - // internal method of O with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - if (k in O) { - // i. Let kValue be the result of calling the Get internal - // method of O with argument Pk. - kValue = O[k]; - // ii. Call the Call internal method of callback with T as - // the this value and argument list containing kValue, k, and O. - callback.call(T, kValue, k, O); - } - } - // 8. return undefined - } +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach +*/ +// Production steps of ECMA-262, Edition 5, 15.4.4.18 +// Reference: http://es5.github.io/#x15.4.4.18 +if (!Array.prototype.forEach) { + Array.prototype.forEach = function(callback, thisArg) { + + + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.forEach called on null or undefined'); + } + + // 1. Let O be the result of calling toObject() passing the + // |this| value as the argument. + var O = Object(this); + + // 2. Let lenValue be the result of calling the Get() internal + // method of O with the argument "length". + // 3. Let len be toUint32(lenValue). + var len = O.length >>> 0; + + // 4. If isCallable(callback) is false, throw a TypeError exception. + // See: http://es5.github.com/#x9.11 + if (callback.__class__ !== 'Function') { + throw new TypeError(callback + ' is not a function'); + } + + // 5. If thisArg was supplied, let T be thisArg; else let + // T be undefined. + var T = (arguments.length > 1) ? thisArg : void 0; + + + // 6. Let k be 0 + //k = 0; + + // 7. Repeat, while k < len + for (var k = 0; k < len; k++) { + var kValue; + // a. Let Pk be ToString(k). + // This is implicit for LHS operands of the in operator + // b. Let kPresent be the result of calling the HasProperty + // internal method of O with argument Pk. + // This step can be combined with c + // c. If kPresent is true, then + if (k in O) { + // i. Let kValue be the result of calling the Get internal + // method of O with argument Pk. + kValue = O[k]; + // ii. Call the Call internal method of callback with T as + // the this value and argument list containing kValue, k, and O. + callback.call(T, kValue, k, O); + } + } + // 8. return undefined + } } //indexOf.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf#Polyfill -*/ -// Production steps of ECMA-262, Edition 5, 15.4.4.14 -// Reference: http://es5.github.io/#x15.4.4.14 -if (!Array.prototype.indexOf) { - Array.prototype.indexOf = function(searchElement, fromIndex) { - - - // 1. Let o be the result of calling ToObject passing - // the this value as the argument. - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.indexOf called on null or undefined'); - } - - var k; - var o = Object(this); - - // 2. Let lenValue be the result of calling the Get - // internal method of o with the argument "length". - // 3. Let len be ToUint32(lenValue). - var len = o.length >>> 0; - - // 4. If len is 0, return -1. - if (len === 0) { - return -1; - } - - // 5. If argument fromIndex was passed let n be - // ToInteger(fromIndex); else let n be 0. - var n = +fromIndex || 0; - - if (Math.abs(n) === Infinity) { - n = 0; - } - - // 6. If n >= len, return -1. - if (n >= len) { - return -1; - } - - // 7. If n >= 0, then Let k be n. - // 8. Else, n<0, Let k be len - abs(n). - // If k is less than 0, then let k be 0. - k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); - - // 9. Repeat, while k < len - while (k < len) { - // a. Let Pk be ToString(k). - // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the - // HasProperty internal method of o with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - // i. Let elementK be the result of calling the Get - // internal method of o with the argument ToString(k). - // ii. Let same be the result of applying the - // Strict Equality Comparison Algorithm to - // searchElement and elementK. - // iii. If same is true, return k. - if (k in o && o[k] === searchElement) { - return k; - } - k++; - } - return -1; - }; +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf#Polyfill +*/ +// Production steps of ECMA-262, Edition 5, 15.4.4.14 +// Reference: http://es5.github.io/#x15.4.4.14 +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function(searchElement, fromIndex) { + + + // 1. Let o be the result of calling ToObject passing + // the this value as the argument. + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.indexOf called on null or undefined'); + } + + var k; + var o = Object(this); + + // 2. Let lenValue be the result of calling the Get + // internal method of o with the argument "length". + // 3. Let len be ToUint32(lenValue). + var len = o.length >>> 0; + + // 4. If len is 0, return -1. + if (len === 0) { + return -1; + } + + // 5. If argument fromIndex was passed let n be + // ToInteger(fromIndex); else let n be 0. + var n = +fromIndex || 0; + + if (Math.abs(n) === Infinity) { + n = 0; + } + + // 6. If n >= len, return -1. + if (n >= len) { + return -1; + } + + // 7. If n >= 0, then Let k be n. + // 8. Else, n<0, Let k be len - abs(n). + // If k is less than 0, then let k be 0. + k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); + + // 9. Repeat, while k < len + while (k < len) { + // a. Let Pk be ToString(k). + // This is implicit for LHS operands of the in operator + // b. Let kPresent be the result of calling the + // HasProperty internal method of o with argument Pk. + // This step can be combined with c + // c. If kPresent is true, then + // i. Let elementK be the result of calling the Get + // internal method of o with the argument ToString(k). + // ii. Let same be the result of applying the + // Strict Equality Comparison Algorithm to + // searchElement and elementK. + // iii. If same is true, return k. + if (k in o && o[k] === searchElement) { + return k; + } + k++; + } + return -1; + }; } -//every.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every -*/ -if (!Array.prototype.every) { - Array.prototype.every = function(callback, thisArg) { - var T, k; - - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.every called on null or undefined'); - } - - // 1. Let O be the result of calling ToObject passing the this - // value as the argument. - var O = Object(this); - - // 2. Let lenValue be the result of calling the Get internal method - // of O with the argument "length". - // 3. Let len be ToUint32(lenValue). - var len = O.length >>> 0; - - // 4. If IsCallable(callback) is false, throw a TypeError exception. - if (callback.__class__ !== 'Function') { - throw new TypeError(callback + ' is not a function'); - } - - // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. - T = (arguments.length > 1) ? thisArg : void 0; - - // 6. Let k be 0. - k = 0; - - // 7. Repeat, while k < len - while (k < len) { - - var kValue; - - // a. Let Pk be ToString(k). - // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the HasProperty internal - // method of O with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - if (k in O) { - - // i. Let kValue be the result of calling the Get internal method - // of O with argument Pk. - kValue = O[k]; - - // ii. Let testResult be the result of calling the Call internal method - // of callback with T as the this value and argument list - // containing kValue, k, and O. - var testResult = callback.call(T, kValue, k, O); - - // iii. If ToBoolean(testResult) is false, return false. - if (!testResult) { - return false; - } - } - k++; - } - return true; - }; +//isArray.js +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray +*/ +if (!Array.isArray) { + Array.isArray = function(arg) { + + if (arg === void 0 || arg === null) { + return false; + } + return (arg.__class__ === 'Array'); + }; } //lastIndexOf.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf -*/ -// Production steps of ECMA-262, Edition 5, 15.4.4.15 -// Reference: http://es5.github.io/#x15.4.4.15 -if (!Array.prototype.lastIndexOf) { - Array.prototype.lastIndexOf = function(searchElement, fromIndex) { - - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.lastIndexOf called on null or undefined'); - } - - var n, k, - t = Object(this), - len = t.length >>> 0; - if (len === 0) { - return -1; - } - - n = len - 1; - if (arguments.length > 1) { - n = Number(arguments[1]); - if (n != n) { - n = 0; - } - else if (n != 0 && n != Infinity && n != -Infinity) { - n = (n > 0 || -1) * Math.floor(Math.abs(n)); - } - } - - for (k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); k >= 0; k--) { - if (k in t && t[k] === searchElement) { - return k; - } - } - return -1; - }; +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf +*/ +// Production steps of ECMA-262, Edition 5, 15.4.4.15 +// Reference: http://es5.github.io/#x15.4.4.15 +if (!Array.prototype.lastIndexOf) { + Array.prototype.lastIndexOf = function(searchElement, fromIndex) { + + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.lastIndexOf called on null or undefined'); + } + + var n, k, + t = Object(this), + len = t.length >>> 0; + if (len === 0) { + return -1; + } + + n = len - 1; + if (arguments.length > 1) { + n = Number(arguments[1]); + if (n != n) { + n = 0; + } + else if (n != 0 && n != Infinity && n != -Infinity) { + n = (n > 0 || -1) * Math.floor(Math.abs(n)); + } + } + + for (k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); k >= 0; k--) { + if (k in t && t[k] === searchElement) { + return k; + } + } + return -1; + }; } //map.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map -*/ -// Production steps of ECMA-262, Edition 5, 15.4.4.19 -// Reference: http://es5.github.io/#x15.4.4.19 -if (!Array.prototype.map) { - - Array.prototype.map = function(callback, thisArg) { - - var T, A, k; - - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.map called on null or undefined'); - } - - // 1. Let O be the result of calling ToObject passing the |this| - // value as the argument. - var O = Object(this); - - // 2. Let lenValue be the result of calling the Get internal - // method of O with the argument "length". - // 3. Let len be ToUint32(lenValue). - var len = O.length >>> 0; - - // 4. If IsCallable(callback) is false, throw a TypeError exception. - // See: http://es5.github.com/#x9.11 - if (callback.__class__ !== 'Function') { - throw new TypeError(callback + ' is not a function'); - } - - // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. - T = (arguments.length > 1) ? thisArg : void 0; - - // 6. Let A be a new array created as if by the expression new Array(len) - // where Array is the standard built-in constructor with that name and - // len is the value of len. - A = new Array(len); - - for (var k = 0; k < len; k++) { - - var kValue, mappedValue; - - // a. Let Pk be ToString(k). - // This is implicit for LHS operands of the in operator - // b. Let kPresent be the result of calling the HasProperty internal - // method of O with argument Pk. - // This step can be combined with c - // c. If kPresent is true, then - if (k in O) { - - // i. Let kValue be the result of calling the Get internal - // method of O with argument Pk. - kValue = O[k]; - - // ii. Let mappedValue be the result of calling the Call internal - // method of callback with T as the this value and argument - // list containing kValue, k, and O. - mappedValue = callback.call(T, kValue, k, O); - - // iii. Call the DefineOwnProperty internal method of A with arguments - // Pk, Property Descriptor - // { Value: mappedValue, - // Writable: true, - // Enumerable: true, - // Configurable: true }, - // and false. - - // In browsers that support Object.defineProperty, use the following: - // Object.defineProperty(A, k, { - // value: mappedValue, - // writable: true, - // enumerable: true, - // configurable: true - // }); - - // For best browser support, use the following: - A[k] = mappedValue; - } - } - // 9. return A - return A; - }; +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map +*/ +// Production steps of ECMA-262, Edition 5, 15.4.4.19 +// Reference: http://es5.github.io/#x15.4.4.19 +if (!Array.prototype.map) { + + Array.prototype.map = function(callback, thisArg) { + + var T, A, k; + + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.map called on null or undefined'); + } + + // 1. Let O be the result of calling ToObject passing the |this| + // value as the argument. + var O = Object(this); + + // 2. Let lenValue be the result of calling the Get internal + // method of O with the argument "length". + // 3. Let len be ToUint32(lenValue). + var len = O.length >>> 0; + + // 4. If IsCallable(callback) is false, throw a TypeError exception. + // See: http://es5.github.com/#x9.11 + if (callback.__class__ !== 'Function') { + throw new TypeError(callback + ' is not a function'); + } + + // 5. If thisArg was supplied, let T be thisArg; else let T be undefined. + T = (arguments.length > 1) ? thisArg : void 0; + + // 6. Let A be a new array created as if by the expression new Array(len) + // where Array is the standard built-in constructor with that name and + // len is the value of len. + A = new Array(len); + + for (var k = 0; k < len; k++) { + + var kValue, mappedValue; + + // a. Let Pk be ToString(k). + // This is implicit for LHS operands of the in operator + // b. Let kPresent be the result of calling the HasProperty internal + // method of O with argument Pk. + // This step can be combined with c + // c. If kPresent is true, then + if (k in O) { + + // i. Let kValue be the result of calling the Get internal + // method of O with argument Pk. + kValue = O[k]; + + // ii. Let mappedValue be the result of calling the Call internal + // method of callback with T as the this value and argument + // list containing kValue, k, and O. + mappedValue = callback.call(T, kValue, k, O); + + // iii. Call the DefineOwnProperty internal method of A with arguments + // Pk, Property Descriptor + // { Value: mappedValue, + // Writable: true, + // Enumerable: true, + // Configurable: true }, + // and false. + + // In browsers that support Object.defineProperty, use the following: + // Object.defineProperty(A, k, { + // value: mappedValue, + // writable: true, + // enumerable: true, + // configurable: true + // }); + + // For best browser support, use the following: + A[k] = mappedValue; + } + } + // 9. return A + return A; + }; } -//isArray.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray -*/ -if (!Array.isArray) { - Array.isArray = function(arg) { - - if (arg === void 0 || arg === null) { - return false; - } - return (arg.__class__ === 'Array'); - }; +//reduce.js +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce +*/ +// Production steps of ECMA-262, Edition 5, 15.4.4.21 +// Reference: http://es5.github.io/#x15.4.4.21 +if (!Array.prototype.reduce) { + Array.prototype.reduce = function(callback, initialValue) { + + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.reduce called on null or undefined'); + } + + if (callback.__class__ !== 'Function') { + throw new TypeError(callback + ' is not a function'); + } + + var t = Object(this), len = t.length >>> 0, k = 0, value; + + if (arguments.length > 1) + { + value = initialValue; + } + else + { + while (k < len && !(k in t)) { + k++; + } + if (k >= len) { + throw new TypeError('Reduce of empty array with no initial value'); + } + value = t[k++]; + } + + for (; k < len; k++) { + if (k in t) { + value = callback(value, t[k], k, t); + } + } + return value; + }; +} +//reduceRight.js +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight +*/ +// Production steps of ECMA-262, Edition 5, 15.4.4.22 +// Reference: http://es5.github.io/#x15.4.4.22 +if (!Array.prototype.reduceRight) { + Array.prototype.reduceRight = function(callback, initialValue) { + + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.reduceRight called on null or undefined'); + } + + if (callback.__class__ !== 'Function') { + throw new TypeError(callback + ' is not a function'); + } + + var t = Object(this), len = t.length >>> 0, k = len - 1, value; + if (arguments.length > 1) + { + value = initialValue; + } + else + { + while (k >= 0 && !(k in t)) { + k--; + } + if (k < 0) { + throw new TypeError('Reduce of empty array with no initial value'); + } + value = t[k--]; + } + + for (; k >= 0; k--) { + if (k in t) { + value = callback(value, t[k], k, t); + } + } + return value; + }; } //some.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some -*/ -// Production steps of ECMA-262, Edition 5, 15.4.4.17 -// Reference: http://es5.github.io/#x15.4.4.17 -if (!Array.prototype.some) { - Array.prototype.some = function(callback, thisArg) { - - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.some called on null or undefined'); - } - - if (callback.__class__ !== 'Function') { - throw new TypeError(callback + ' is not a function'); - } - - var t = Object(this); - var len = t.length >>> 0; - - var T = arguments.length > 1 ? thisArg : void 0; - for (var i = 0; i < len; i++) { - if (i in t && callback.call(T, t[i], i, t)) { - return true; - } - } - - return false; - }; +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some +*/ +// Production steps of ECMA-262, Edition 5, 15.4.4.17 +// Reference: http://es5.github.io/#x15.4.4.17 +if (!Array.prototype.some) { + Array.prototype.some = function(callback, thisArg) { + + if (this === void 0 || this === null) { + throw new TypeError('Array.prototype.some called on null or undefined'); + } + + if (callback.__class__ !== 'Function') { + throw new TypeError(callback + ' is not a function'); + } + + var t = Object(this); + var len = t.length >>> 0; + + var T = arguments.length > 1 ? thisArg : void 0; + for (var i = 0; i < len; i++) { + if (i in t && callback.call(T, t[i], i, t)) { + return true; + } + } + + return false; + }; } -//reduce.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce -*/ -// Production steps of ECMA-262, Edition 5, 15.4.4.21 -// Reference: http://es5.github.io/#x15.4.4.21 -if (!Array.prototype.reduce) { - Array.prototype.reduce = function(callback, initialValue) { - - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.reduce called on null or undefined'); - } - - if (callback.__class__ !== 'Function') { - throw new TypeError(callback + ' is not a function'); - } - - var t = Object(this), len = t.length >>> 0, k = 0, value; - - if (arguments.length > 1) - { - value = initialValue; - } - else - { - while (k < len && !(k in t)) { - k++; - } - if (k >= len) { - throw new TypeError('Reduce of empty array with no initial value'); - } - value = t[k++]; - } - - for (; k < len; k++) { - if (k in t) { - value = callback(value, t[k], k, t); - } - } - return value; - }; +//bind.js +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill + +WARNING! Bound functions used as constructors NOT supported by this polyfill! +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Bound_functions_used_as_constructors +*/ +if (!Function.prototype.bind) { + Function.prototype.bind = function(oThis) { + if (this.__class__ !== 'Function') { + throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); + } + + var aArgs = Array.prototype.slice.call(arguments, 1), + fToBind = this, + fNOP = function() {}, + fBound = function() { + return fToBind.apply(this instanceof fNOP + ? this + : oThis, + aArgs.concat(Array.prototype.slice.call(arguments))); + }; + + if (this.prototype) { + // Function.prototype doesn't have a prototype property + fNOP.prototype = this.prototype; + } + fBound.prototype = new fNOP(); + + return fBound; + }; } -//reduceRight.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight -*/ -// Production steps of ECMA-262, Edition 5, 15.4.4.22 -// Reference: http://es5.github.io/#x15.4.4.22 -if (!Array.prototype.reduceRight) { - Array.prototype.reduceRight = function(callback, initialValue) { - - if (this === void 0 || this === null) { - throw new TypeError('Array.prototype.reduceRight called on null or undefined'); - } - - if (callback.__class__ !== 'Function') { - throw new TypeError(callback + ' is not a function'); - } +//json2.js +// json2.js +// 2017-06-12 +// Public Domain. +// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + +// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO +// NOT CONTROL. + +// This file creates a global JSON object containing two methods: stringify +// and parse. This file provides the ES5 JSON capability to ES3 systems. +// If a project might run on IE8 or earlier, then this file should be included. +// This file does nothing on ES5 systems. + +// JSON.stringify(value, replacer, space) +// value any JavaScript value, usually an object or array. +// replacer an optional parameter that determines how object +// values are stringified for objects. It can be a +// function or an array of strings. +// space an optional parameter that specifies the indentation +// of nested structures. If it is omitted, the text will +// be packed without extra whitespace. If it is a number, +// it will specify the number of spaces to indent at each +// level. If it is a string (such as "\t" or " "), +// it contains the characters used to indent at each level. +// This method produces a JSON text from a JavaScript value. +// When an object value is found, if the object contains a toJSON +// method, its toJSON method will be called and the result will be +// stringified. A toJSON method does not serialize: it returns the +// value represented by the name/value pair that should be serialized, +// or undefined if nothing should be serialized. The toJSON method +// will be passed the key associated with the value, and this will be +// bound to the value. + +// For example, this would serialize Dates as ISO strings. + +// Date.prototype.toJSON = function (key) { +// function f(n) { +// // Format integers to have at least two digits. +// return (n < 10) +// ? "0" + n +// : n; +// } +// return this.getUTCFullYear() + "-" + +// f(this.getUTCMonth() + 1) + "-" + +// f(this.getUTCDate()) + "T" + +// f(this.getUTCHours()) + ":" + +// f(this.getUTCMinutes()) + ":" + +// f(this.getUTCSeconds()) + "Z"; +// }; + +// You can provide an optional replacer method. It will be passed the +// key and value of each member, with this bound to the containing +// object. The value that is returned from your method will be +// serialized. If your method returns undefined, then the member will +// be excluded from the serialization. + +// If the replacer parameter is an array of strings, then it will be +// used to select the members to be serialized. It filters the results +// such that only members with keys listed in the replacer array are +// stringified. + +// Values that do not have JSON representations, such as undefined or +// functions, will not be serialized. Such values in objects will be +// dropped; in arrays they will be replaced with null. You can use +// a replacer function to replace those with JSON values. + +// JSON.stringify(undefined) returns undefined. + +// The optional space parameter produces a stringification of the +// value that is filled with line breaks and indentation to make it +// easier to read. + +// If the space parameter is a non-empty string, then that string will +// be used for indentation. If the space parameter is a number, then +// the indentation will be that many spaces. + +// Example: + +// text = JSON.stringify(["e", {pluribus: "unum"}]); +// // text is '["e",{"pluribus":"unum"}]' + +// text = JSON.stringify(["e", {pluribus: "unum"}], null, "\t"); +// // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' + +// text = JSON.stringify([new Date()], function (key, value) { +// return this[key] instanceof Date +// ? "Date(" + this[key] + ")" +// : value; +// }); +// // text is '["Date(---current time---)"]' + +// JSON.parse(text, reviver) +// This method parses a JSON text to produce an object or array. +// It can throw a SyntaxError exception. + +// The optional reviver parameter is a function that can filter and +// transform the results. It receives each of the keys and values, +// and its return value is used instead of the original value. +// If it returns what it received, then the structure is not modified. +// If it returns undefined then the member is deleted. + +// Example: + +// // Parse the text. Values that look like ISO date strings will +// // be converted to Date objects. + +// myData = JSON.parse(text, function (key, value) { +// var a; +// if (typeof value === "string") { +// a = +// /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); +// if (a) { +// return new Date(Date.UTC( +// +a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6] +// )); +// } +// return value; +// } +// }); + +// myData = JSON.parse( +// "[\"Date(09/09/2001)\"]", +// function (key, value) { +// var d; +// if ( +// typeof value === "string" +// && value.slice(0, 5) === "Date(" +// && value.slice(-1) === ")" +// ) { +// d = new Date(value.slice(5, -1)); +// if (d) { +// return d; +// } +// } +// return value; +// } +// ); + +// This is a reference implementation. You are free to copy, modify, or +// redistribute. + +/*jslint + eval, for, this +*/ + +/*property + JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, + getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, + lastIndex, length, parse, prototype, push, replace, slice, stringify, + test, toJSON, toString, valueOf +*/ + + +// Create a JSON object only if one does not already exist. We create the +// methods in a closure to avoid creating global variables. + +if (typeof JSON !== "object") { + JSON = {}; +} + +(function () { + "use strict"; + + var rx_one = /^[\],:{}\s]*$/; + var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g; + var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g; + var rx_four = /(?:^|:|,)(?:\s*\[)+/g; + var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; + var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; + + function f(n) { + // Format integers to have at least two digits. + return (n < 10) + ? "0" + n + : n; + } + + function this_value() { + return this.valueOf(); + } + + if (typeof Date.prototype.toJSON !== "function") { + + Date.prototype.toJSON = function () { + + return isFinite(this.valueOf()) + ? ( + this.getUTCFullYear() + + "-" + + f(this.getUTCMonth() + 1) + + "-" + + f(this.getUTCDate()) + + "T" + + f(this.getUTCHours()) + + ":" + + f(this.getUTCMinutes()) + + ":" + + f(this.getUTCSeconds()) + + "Z" + ) + : null; + }; + + Boolean.prototype.toJSON = this_value; + Number.prototype.toJSON = this_value; + String.prototype.toJSON = this_value; + } + + var gap; + var indent; + var meta; + var rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + rx_escapable.lastIndex = 0; + return rx_escapable.test(string) + ? "\"" + string.replace(rx_escapable, function (a) { + var c = meta[a]; + return typeof c === "string" + ? c + : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4); + }) + "\"" + : "\"" + string + "\""; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + var i; // The loop counter. + var k; // The member key. + var v; // The member value. + var length; + var mind = gap; + var partial; + var value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if ( + value + && typeof value === "object" + && typeof value.toJSON === "function" + ) { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === "function") { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case "string": + return quote(value); + + case "number": + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return (isFinite(value)) + ? String(value) + : "null"; + + case "boolean": + case "null": + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce "null". The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is "object", we might be dealing with an object or an array or +// null. + + case "object": + +// Due to a specification blunder in ECMAScript, typeof null is "object", +// so watch out for that case. + + if (!value) { + return "null"; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// Is the value an array? + + if (Object.prototype.toString.apply(value) === "[object Array]") { + +// The value is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || "null"; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 + ? "[]" + : gap + ? ( + "[\n" + + gap + + partial.join(",\n" + gap) + + "\n" + + mind + + "]" + ) + : "[" + partial.join(",") + "]"; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === "object") { + length = rep.length; + for (i = 0; i < length; i += 1) { + if (typeof rep[i] === "string") { + k = rep[i]; + v = str(k, value); + if (v) { + partial.push(quote(k) + ( + (gap) + ? ": " + : ":" + ) + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + ( + (gap) + ? ": " + : ":" + ) + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 + ? "{}" + : gap + ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}" + : "{" + partial.join(",") + "}"; + gap = mind; + return v; + } + } + +// If the JSON object does not yet have a stringify method, give it one. + + if (typeof JSON.stringify !== "function") { + meta = { // table of character substitutions + "\b": "\\b", + "\t": "\\t", + "\n": "\\n", + "\f": "\\f", + "\r": "\\r", + "\"": "\\\"", + "\\": "\\\\" + }; + JSON.stringify = function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + var i; + gap = ""; + indent = ""; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === "number") { + for (i = 0; i < space; i += 1) { + indent += " "; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === "string") { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== "function" && ( + typeof replacer !== "object" + || typeof replacer.length !== "number" + )) { + throw new Error("JSON.stringify"); + } + +// Make a fake root object containing our value under the key of "". +// Return the result of stringifying the value. + + return str("", {"": value}); + }; + } + + +// If the JSON object does not yet have a parse method, give it one. + + if (typeof JSON.parse !== "function") { + JSON.parse = function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + var k; + var v; + var value = holder[key]; + if (value && typeof value === "object") { + for (k in value) { + if (Object.prototype.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + text = String(text); + rx_dangerous.lastIndex = 0; + if (rx_dangerous.test(text)) { + text = text.replace(rx_dangerous, function (a) { + return ( + "\\u" + + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) + ); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with "()" and "new" +// because they can cause invocation, and "=" because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with "@" (a non-JSON character). Second, we +// replace all simple value tokens with "]" characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or "]" or +// "," or ":" or "{" or "}". If that is so, then the text is safe for eval. + + if ( + rx_one.test( + text + .replace(rx_two, "@") + .replace(rx_three, "]") + .replace(rx_four, "") + ) + ) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The "{" operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval("(" + text + ")"); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return (typeof reviver === "function") + ? walk({"": j}, "") + : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError("JSON.parse"); + }; + } +}()); - var t = Object(this), len = t.length >>> 0, k = len - 1, value; - if (arguments.length > 1) - { - value = initialValue; - } - else - { - while (k >= 0 && !(k in t)) { - k--; - } - if (k < 0) { - throw new TypeError('Reduce of empty array with no initial value'); - } - value = t[k--]; - } - - for (; k >= 0; k--) { - if (k in t) { - value = callback(value, t[k], k, t); - } - } - return value; - }; -} //create.js -if (!Object.create) { - // Production steps of ECMA-262, Edition 5, 15.2.3.5 - // Reference: http://es5.github.io/#x15.2.3.5 - Object.create = (function() { - // To save on memory, use a shared constructor - function Temp() {} - - // make a safe reference to Object.prototype.hasOwnProperty - var hasOwn = Object.prototype.hasOwnProperty; - - return function(O) { - // 1. If Type(O) is not Object or Null throw a TypeError exception. - if (Object(O) !== O && O !== null) { - throw TypeError('Object prototype may only be an Object or null'); - } - - // 2. Let obj be the result of creating a new object as if by the - // expression new Object() where Object is the standard built-in - // constructor with that name - // 3. Set the [[Prototype]] internal property of obj to O. - Temp.prototype = O; - var obj = new Temp(); - Temp.prototype = null; // Let's not keep a stray reference to O... - - // 4. If the argument Properties is present and not undefined, add - // own properties to obj as if by calling the standard built-in - // function Object.defineProperties with arguments obj and - // Properties. - if (arguments.length > 1) { - // Object.defineProperties does ToObject on its first argument. - var Properties = Object(arguments[1]); - for (var prop in Properties) { - if (hasOwn.call(Properties, prop)) { - var descriptor = Properties[prop]; - if (Object(descriptor) !== descriptor) { - throw TypeError(prop + 'must be an object'); - } - if ('get' in descriptor || 'set' in descriptor) { - throw new TypeError('getters & setters can not be defined on this javascript engine'); - } - if ('value' in descriptor) { - obj[prop] = Properties[prop]; - } - - } - } - } - - // 5. Return obj - return obj; - }; - })(); -} -//defineProperty.js -if (!Object.defineProperty) { - - Object.defineProperty = function defineProperty(object, property, descriptor) { - - if (Object(object) !== object) { - throw new TypeError('Object.defineProperty can only be called on Objects.'); - } - - if (Object(descriptor) !== descriptor) { - throw new TypeError('Property description can only be an Object.'); - } - - if ('get' in descriptor || 'set' in descriptor) { - throw new TypeError('getters & setters can not be defined on this javascript engine'); - } - // If it's a data property. - if ('value' in descriptor) { - // fail silently if 'writable', 'enumerable', or 'configurable' - // are requested but not supported - // can't implement these features; allow true but not false - /* if ( - ('writable' in descriptor && !descriptor.writable) || - ('enumerable' in descriptor && !descriptor.enumerable) || - ('configurable' in descriptor && !descriptor.configurable) - ) - { - throw new RangeError('This implementation of Object.defineProperty does not support configurable, enumerable, or writable properties SET to FALSE.'); - }*/ - - - object[property] = descriptor.value; - } - return object; - } +if (!Object.create) { + // Production steps of ECMA-262, Edition 5, 15.2.3.5 + // Reference: http://es5.github.io/#x15.2.3.5 + Object.create = (function() { + // To save on memory, use a shared constructor + function Temp() {} + + // make a safe reference to Object.prototype.hasOwnProperty + var hasOwn = Object.prototype.hasOwnProperty; + + return function(O) { + // 1. If Type(O) is not Object or Null throw a TypeError exception. + if (Object(O) !== O && O !== null) { + throw TypeError('Object prototype may only be an Object or null'); + } + + // 2. Let obj be the result of creating a new object as if by the + // expression new Object() where Object is the standard built-in + // constructor with that name + // 3. Set the [[Prototype]] internal property of obj to O. + Temp.prototype = O; + var obj = new Temp(); + Temp.prototype = null; // Let's not keep a stray reference to O... + + // 4. If the argument Properties is present and not undefined, add + // own properties to obj as if by calling the standard built-in + // function Object.defineProperties with arguments obj and + // Properties. + if (arguments.length > 1) { + // Object.defineProperties does ToObject on its first argument. + var Properties = Object(arguments[1]); + for (var prop in Properties) { + if (hasOwn.call(Properties, prop)) { + var descriptor = Properties[prop]; + if (Object(descriptor) !== descriptor) { + throw TypeError(prop + 'must be an object'); + } + if ('get' in descriptor || 'set' in descriptor) { + throw new TypeError('getters & setters can not be defined on this javascript engine'); + } + if ('value' in descriptor) { + obj[prop] = Properties[prop]; + } + + } + } + } + + // 5. Return obj + return obj; + }; + })(); } //defineProperties.js -/* -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties#Polyfill -*/ -if (!Object.defineProperties) { - - Object.defineProperties = function(object, props) { - - function hasProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); - } - - function convertToDescriptor(desc) { - - if (Object(desc) !== desc) { - throw new TypeError('Descriptor can only be an Object.'); - } - - - var d = {}; - - if (hasProperty(desc, "enumerable")) { - d.enumerable = !!desc.enumerable; - } - - if (hasProperty(desc, "configurable")) { - d.configurable = !!desc.configurable; - } - - if (hasProperty(desc, "value")) { - d.value = desc.value; - } - - if (hasProperty(desc, "writable")) { - d.writable = !!desc.writable; - } - - if (hasProperty(desc, "get")) { - throw new TypeError('getters & setters can not be defined on this javascript engine'); - } - - if (hasProperty(desc, "set")) { - throw new TypeError('getters & setters can not be defined on this javascript engine'); - } - - return d; - } - - if (Object(object) !== object) { - throw new TypeError('Object.defineProperties can only be called on Objects.'); - } - - if (Object(props) !== props) { - throw new TypeError('Properties can only be an Object.'); - } - - var properties = Object(props); - for (propName in properties) { - if (hasOwnProperty.call(properties, propName)) { - var descr = convertToDescriptor(properties[propName]); - object[propName] = descr.value; - } - } - return object; - } +/* +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties#Polyfill +*/ +if (!Object.defineProperties) { + + Object.defineProperties = function(object, props) { + + function hasProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); + } + + function convertToDescriptor(desc) { + + if (Object(desc) !== desc) { + throw new TypeError('Descriptor can only be an Object.'); + } + + + var d = {}; + + if (hasProperty(desc, "enumerable")) { + d.enumerable = !!desc.enumerable; + } + + if (hasProperty(desc, "configurable")) { + d.configurable = !!desc.configurable; + } + + if (hasProperty(desc, "value")) { + d.value = desc.value; + } + + if (hasProperty(desc, "writable")) { + d.writable = !!desc.writable; + } + + if (hasProperty(desc, "get")) { + throw new TypeError('getters & setters can not be defined on this javascript engine'); + } + + if (hasProperty(desc, "set")) { + throw new TypeError('getters & setters can not be defined on this javascript engine'); + } + + return d; + } + + if (Object(object) !== object) { + throw new TypeError('Object.defineProperties can only be called on Objects.'); + } + + if (Object(props) !== props) { + throw new TypeError('Properties can only be an Object.'); + } + + var properties = Object(props); + for (propName in properties) { + if (hasOwnProperty.call(properties, propName)) { + var descr = convertToDescriptor(properties[propName]); + object[propName] = descr.value; + } + } + return object; + } } -//getOwnPropertyDescriptor.js -if (!Object.getOwnPropertyDescriptor) { - - Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) { - if (Object(object) !== object) { - throw new TypeError('Object.getOwnPropertyDescriptor can only be called on Objects.'); - } - - var descriptor; - if (!Object.prototype.hasOwnProperty.call(object, property)) { - return descriptor; - } - - descriptor = { - enumerable: Object.prototype.propertyIsEnumerable.call(object, property), - configurable: true - }; - - descriptor.value = object[property]; - - var psPropertyType = object.reflect.find(property).type; - descriptor.writable = !(psPropertyType === "readonly"); - - return descriptor; - } +//defineProperty.js +if (!Object.defineProperty) { + + Object.defineProperty = function defineProperty(object, property, descriptor) { + + if (Object(object) !== object) { + throw new TypeError('Object.defineProperty can only be called on Objects.'); + } + + if (Object(descriptor) !== descriptor) { + throw new TypeError('Property description can only be an Object.'); + } + + if ('get' in descriptor || 'set' in descriptor) { + throw new TypeError('getters & setters can not be defined on this javascript engine'); + } + // If it's a data property. + if ('value' in descriptor) { + // fail silently if 'writable', 'enumerable', or 'configurable' + // are requested but not supported + // can't implement these features; allow true but not false + /* if ( + ('writable' in descriptor && !descriptor.writable) || + ('enumerable' in descriptor && !descriptor.enumerable) || + ('configurable' in descriptor && !descriptor.configurable) + ) + { + throw new RangeError('This implementation of Object.defineProperty does not support configurable, enumerable, or writable properties SET to FALSE.'); + }*/ + + + object[property] = descriptor.value; + } + return object; + } } -//freeze.js -/* -https://github.com/es-shims/es5-shim/blob/master/es5-sham.js -*/ -// ES5 15.2.3.9 -// http://es5.github.com/#x15.2.3.9 -if (!Object.freeze) { - Object.freeze = function freeze(object) { - if (Object(object) !== object) { - throw new TypeError('Object.freeze can only be called on Objects.'); - } - // this is misleading and breaks feature-detection, but - // allows "securable" code to "gracefully" degrade to working - // but insecure code. - return object; - }; +//getOwnPropertyDescriptor.js +if (!Object.getOwnPropertyDescriptor) { + + Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) { + if (Object(object) !== object) { + throw new TypeError('Object.getOwnPropertyDescriptor can only be called on Objects.'); + } + + var descriptor; + if (!Object.prototype.hasOwnProperty.call(object, property)) { + return descriptor; + } + + descriptor = { + enumerable: Object.prototype.propertyIsEnumerable.call(object, property), + configurable: true + }; + + descriptor.value = object[property]; + + var psPropertyType = object.reflect.find(property).type; + descriptor.writable = !(psPropertyType === "readonly"); + + return descriptor; + } } //getOwnPropertyNames.js -if (!Object.getOwnPropertyNames) { - Object.getOwnPropertyNames = function getOwnPropertyNames(object) { - - if (Object(object) !== object) { - throw new TypeError('Object.getOwnPropertyNames can only be called on Objects.'); - } - var names = []; - var hasOwnProperty = Object.prototype.hasOwnProperty; - var propertyIsEnumerable = Object.prototype.propertyIsEnumerable; - for (var prop in object) { - if (hasOwnProperty.call(object, prop)) { - names.push(prop); - } - } - var properties = object.reflect.properties; - var methods = object.reflect.methods; - var all = methods.concat(properties); - for (var i = 0; i < all.length; i++) { - var prop = all[i].name; - if (hasOwnProperty.call(object, prop) && !(propertyIsEnumerable.call(object, prop))) { - names.push(prop); - } - } - return names; - }; +if (!Object.getOwnPropertyNames) { + Object.getOwnPropertyNames = function getOwnPropertyNames(object) { + + if (Object(object) !== object) { + throw new TypeError('Object.getOwnPropertyNames can only be called on Objects.'); + } + var names = []; + var hasOwnProperty = Object.prototype.hasOwnProperty; + var propertyIsEnumerable = Object.prototype.propertyIsEnumerable; + for (var prop in object) { + if (hasOwnProperty.call(object, prop)) { + names.push(prop); + } + } + var properties = object.reflect.properties; + var methods = object.reflect.methods; + var all = methods.concat(properties); + for (var i = 0; i < all.length; i++) { + var prop = all[i].name; + if (hasOwnProperty.call(object, prop) && !(propertyIsEnumerable.call(object, prop))) { + names.push(prop); + } + } + return names; + }; +} +//freeze.js +/* +https://github.com/es-shims/es5-shim/blob/master/es5-sham.js +*/ +// ES5 15.2.3.9 +// http://es5.github.com/#x15.2.3.9 +if (!Object.freeze) { + Object.freeze = function freeze(object) { + if (Object(object) !== object) { + throw new TypeError('Object.freeze can only be called on Objects.'); + } + // this is misleading and breaks feature-detection, but + // allows "securable" code to "gracefully" degrade to working + // but insecure code. + return object; + }; } //isExtensible.js -// ES5 15.2.3.13 -// http://es5.github.com/#x15.2.3.13 -if (!Object.isExtensible) { - Object.isExtensible = function isExtensible(object) { - if (Object(object) !== object) { - throw new TypeError('Object.isExtensible can only be called on Objects.'); - } - return true; - }; +// ES5 15.2.3.13 +// http://es5.github.com/#x15.2.3.13 +if (!Object.isExtensible) { + Object.isExtensible = function isExtensible(object) { + if (Object(object) !== object) { + throw new TypeError('Object.isExtensible can only be called on Objects.'); + } + return true; + }; } -//getPrototypeOf.js -if (!Object.getPrototypeOf) { - Object.getPrototypeOf = function(object) { - if (Object(object) !== object) { - throw new TypeError('Object.getPrototypeOf can only be called on Objects.'); - } - return object.__proto__; - } +//isFrozen.js +/* +https://github.com/es-shims/es5-shim/blob/master/es5-sham.js +*/ +// ES5 15.2.3.12 +// http://es5.github.com/#x15.2.3.12 +if (!Object.isFrozen) { + Object.isFrozen = function isFrozen(object) { + if (Object(object) !== object) { + throw new TypeError('Object.isFrozen can only be called on Objects.'); + } + return false; + }; } //isSealed.js -/* -https://github.com/es-shims/es5-shim/blob/master/es5-sham.js -*/ -// ES5 15.2.3.11 -// http://es5.github.com/#x15.2.3.11 -if (!Object.isSealed) { - Object.isSealed = function isSealed(object) { - if (Object(object) !== object) { - throw new TypeError('Object.isSealed can only be called on Objects.'); - } - return false; - }; +/* +https://github.com/es-shims/es5-shim/blob/master/es5-sham.js +*/ +// ES5 15.2.3.11 +// http://es5.github.com/#x15.2.3.11 +if (!Object.isSealed) { + Object.isSealed = function isSealed(object) { + if (Object(object) !== object) { + throw new TypeError('Object.isSealed can only be called on Objects.'); + } + return false; + }; } -//isFrozen.js -/* -https://github.com/es-shims/es5-shim/blob/master/es5-sham.js -*/ -// ES5 15.2.3.12 -// http://es5.github.com/#x15.2.3.12 -if (!Object.isFrozen) { - Object.isFrozen = function isFrozen(object) { - if (Object(object) !== object) { - throw new TypeError('Object.isFrozen can only be called on Objects.'); - } - return false; - }; +//getPrototypeOf.js +if (!Object.getPrototypeOf) { + Object.getPrototypeOf = function(object) { + if (Object(object) !== object) { + throw new TypeError('Object.getPrototypeOf can only be called on Objects.'); + } + return object.__proto__; + } } //keys.js -if (!Object.keys) { - Object.keys = function(object) { - if (Object(object) !== object) { - throw new TypeError('Object.keys can only be called on Objects.'); - } - var hasOwnProperty = Object.prototype.hasOwnProperty; - var result = []; - for (var prop in object) { - if (hasOwnProperty.call(object, prop)) { - result.push(prop); - } - } - return result; - }; +if (!Object.keys) { + Object.keys = function(object) { + if (Object(object) !== object) { + throw new TypeError('Object.keys can only be called on Objects.'); + } + var hasOwnProperty = Object.prototype.hasOwnProperty; + var result = []; + for (var prop in object) { + if (hasOwnProperty.call(object, prop)) { + result.push(prop); + } + } + return result; + }; } //preventExtensions.js -/* -https://github.com/es-shims/es5-shim/blob/master/es5-sham.js -*/ -// ES5 15.2.3.10 -// http://es5.github.com/#x15.2.3.10 -if (!Object.preventExtensions) { - Object.preventExtensions = function preventExtensions(object) { - - if (Object(object) !== object) { - throw new TypeError('Object.preventExtensions can only be called on Objects.'); - } - // this is misleading and breaks feature-detection, but - // allows "securable" code to "gracefully" degrade to working - // but insecure code. - return object; - }; +/* +https://github.com/es-shims/es5-shim/blob/master/es5-sham.js +*/ +// ES5 15.2.3.10 +// http://es5.github.com/#x15.2.3.10 +if (!Object.preventExtensions) { + Object.preventExtensions = function preventExtensions(object) { + + if (Object(object) !== object) { + throw new TypeError('Object.preventExtensions can only be called on Objects.'); + } + // this is misleading and breaks feature-detection, but + // allows "securable" code to "gracefully" degrade to working + // but insecure code. + return object; + }; } //seal.js -/* -https://github.com/es-shims/es5-shim/blob/master/es5-sham.js -*/ -// ES5 15.2.3.8 -// http://es5.github.com/#x15.2.3.8 -if (!Object.seal) { - Object.seal = function seal(object) { - if (Object(object) !== object) { - throw new TypeError('Object.seal can only be called on Objects.'); - } - // this is misleading and breaks feature-detection, but - // allows "securable" code to "gracefully" degrade to working - // but insecure code. - return object; - }; -} -//json2.js -// json2.js -// 2017-06-12 -// Public Domain. -// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. - -// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO -// NOT CONTROL. - -// This file creates a global JSON object containing two methods: stringify -// and parse. This file provides the ES5 JSON capability to ES3 systems. -// If a project might run on IE8 or earlier, then this file should be included. -// This file does nothing on ES5 systems. - -// JSON.stringify(value, replacer, space) -// value any JavaScript value, usually an object or array. -// replacer an optional parameter that determines how object -// values are stringified for objects. It can be a -// function or an array of strings. -// space an optional parameter that specifies the indentation -// of nested structures. If it is omitted, the text will -// be packed without extra whitespace. If it is a number, -// it will specify the number of spaces to indent at each -// level. If it is a string (such as "\t" or " "), -// it contains the characters used to indent at each level. -// This method produces a JSON text from a JavaScript value. -// When an object value is found, if the object contains a toJSON -// method, its toJSON method will be called and the result will be -// stringified. A toJSON method does not serialize: it returns the -// value represented by the name/value pair that should be serialized, -// or undefined if nothing should be serialized. The toJSON method -// will be passed the key associated with the value, and this will be -// bound to the value. - -// For example, this would serialize Dates as ISO strings. - -// Date.prototype.toJSON = function (key) { -// function f(n) { -// // Format integers to have at least two digits. -// return (n < 10) -// ? "0" + n -// : n; -// } -// return this.getUTCFullYear() + "-" + -// f(this.getUTCMonth() + 1) + "-" + -// f(this.getUTCDate()) + "T" + -// f(this.getUTCHours()) + ":" + -// f(this.getUTCMinutes()) + ":" + -// f(this.getUTCSeconds()) + "Z"; -// }; - -// You can provide an optional replacer method. It will be passed the -// key and value of each member, with this bound to the containing -// object. The value that is returned from your method will be -// serialized. If your method returns undefined, then the member will -// be excluded from the serialization. - -// If the replacer parameter is an array of strings, then it will be -// used to select the members to be serialized. It filters the results -// such that only members with keys listed in the replacer array are -// stringified. - -// Values that do not have JSON representations, such as undefined or -// functions, will not be serialized. Such values in objects will be -// dropped; in arrays they will be replaced with null. You can use -// a replacer function to replace those with JSON values. - -// JSON.stringify(undefined) returns undefined. - -// The optional space parameter produces a stringification of the -// value that is filled with line breaks and indentation to make it -// easier to read. - -// If the space parameter is a non-empty string, then that string will -// be used for indentation. If the space parameter is a number, then -// the indentation will be that many spaces. - -// Example: - -// text = JSON.stringify(["e", {pluribus: "unum"}]); -// // text is '["e",{"pluribus":"unum"}]' - -// text = JSON.stringify(["e", {pluribus: "unum"}], null, "\t"); -// // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' - -// text = JSON.stringify([new Date()], function (key, value) { -// return this[key] instanceof Date -// ? "Date(" + this[key] + ")" -// : value; -// }); -// // text is '["Date(---current time---)"]' - -// JSON.parse(text, reviver) -// This method parses a JSON text to produce an object or array. -// It can throw a SyntaxError exception. - -// The optional reviver parameter is a function that can filter and -// transform the results. It receives each of the keys and values, -// and its return value is used instead of the original value. -// If it returns what it received, then the structure is not modified. -// If it returns undefined then the member is deleted. - -// Example: - -// // Parse the text. Values that look like ISO date strings will -// // be converted to Date objects. - -// myData = JSON.parse(text, function (key, value) { -// var a; -// if (typeof value === "string") { -// a = -// /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); -// if (a) { -// return new Date(Date.UTC( -// +a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6] -// )); -// } -// return value; -// } -// }); - -// myData = JSON.parse( -// "[\"Date(09/09/2001)\"]", -// function (key, value) { -// var d; -// if ( -// typeof value === "string" -// && value.slice(0, 5) === "Date(" -// && value.slice(-1) === ")" -// ) { -// d = new Date(value.slice(5, -1)); -// if (d) { -// return d; -// } -// } -// return value; -// } -// ); - -// This is a reference implementation. You are free to copy, modify, or -// redistribute. - -/*jslint - eval, for, this -*/ - -/*property - JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, - getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, - lastIndex, length, parse, prototype, push, replace, slice, stringify, - test, toJSON, toString, valueOf -*/ - - -// Create a JSON object only if one does not already exist. We create the -// methods in a closure to avoid creating global variables. - -if (typeof JSON !== "object") { - JSON = {}; +/* +https://github.com/es-shims/es5-shim/blob/master/es5-sham.js +*/ +// ES5 15.2.3.8 +// http://es5.github.com/#x15.2.3.8 +if (!Object.seal) { + Object.seal = function seal(object) { + if (Object(object) !== object) { + throw new TypeError('Object.seal can only be called on Objects.'); + } + // this is misleading and breaks feature-detection, but + // allows "securable" code to "gracefully" degrade to working + // but insecure code. + return object; + }; } - -(function () { - "use strict"; - - var rx_one = /^[\],:{}\s]*$/; - var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g; - var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g; - var rx_four = /(?:^|:|,)(?:\s*\[)+/g; - var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; - var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; - - function f(n) { - // Format integers to have at least two digits. - return (n < 10) - ? "0" + n - : n; - } - - function this_value() { - return this.valueOf(); - } - - if (typeof Date.prototype.toJSON !== "function") { - - Date.prototype.toJSON = function () { - - return isFinite(this.valueOf()) - ? ( - this.getUTCFullYear() - + "-" - + f(this.getUTCMonth() + 1) - + "-" - + f(this.getUTCDate()) - + "T" - + f(this.getUTCHours()) - + ":" - + f(this.getUTCMinutes()) - + ":" - + f(this.getUTCSeconds()) - + "Z" - ) - : null; - }; - - Boolean.prototype.toJSON = this_value; - Number.prototype.toJSON = this_value; - String.prototype.toJSON = this_value; - } - - var gap; - var indent; - var meta; - var rep; - - - function quote(string) { - -// If the string contains no control characters, no quote characters, and no -// backslash characters, then we can safely slap some quotes around it. -// Otherwise we must also replace the offending characters with safe escape -// sequences. - - rx_escapable.lastIndex = 0; - return rx_escapable.test(string) - ? "\"" + string.replace(rx_escapable, function (a) { - var c = meta[a]; - return typeof c === "string" - ? c - : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4); - }) + "\"" - : "\"" + string + "\""; - } - - - function str(key, holder) { - -// Produce a string from holder[key]. - - var i; // The loop counter. - var k; // The member key. - var v; // The member value. - var length; - var mind = gap; - var partial; - var value = holder[key]; - -// If the value has a toJSON method, call it to obtain a replacement value. - - if ( - value - && typeof value === "object" - && typeof value.toJSON === "function" - ) { - value = value.toJSON(key); - } - -// If we were called with a replacer function, then call the replacer to -// obtain a replacement value. - - if (typeof rep === "function") { - value = rep.call(holder, key, value); - } - -// What happens next depends on the value's type. - - switch (typeof value) { - case "string": - return quote(value); - - case "number": - -// JSON numbers must be finite. Encode non-finite numbers as null. - - return (isFinite(value)) - ? String(value) - : "null"; - - case "boolean": - case "null": - -// If the value is a boolean or null, convert it to a string. Note: -// typeof null does not produce "null". The case is included here in -// the remote chance that this gets fixed someday. - - return String(value); - -// If the type is "object", we might be dealing with an object or an array or -// null. - - case "object": - -// Due to a specification blunder in ECMAScript, typeof null is "object", -// so watch out for that case. - - if (!value) { - return "null"; - } - -// Make an array to hold the partial results of stringifying this object value. - - gap += indent; - partial = []; - -// Is the value an array? - - if (Object.prototype.toString.apply(value) === "[object Array]") { - -// The value is an array. Stringify every element. Use null as a placeholder -// for non-JSON values. - - length = value.length; - for (i = 0; i < length; i += 1) { - partial[i] = str(i, value) || "null"; - } - -// Join all of the elements together, separated with commas, and wrap them in -// brackets. - - v = partial.length === 0 - ? "[]" - : gap - ? ( - "[\n" - + gap - + partial.join(",\n" + gap) - + "\n" - + mind - + "]" - ) - : "[" + partial.join(",") + "]"; - gap = mind; - return v; - } - -// If the replacer is an array, use it to select the members to be stringified. - - if (rep && typeof rep === "object") { - length = rep.length; - for (i = 0; i < length; i += 1) { - if (typeof rep[i] === "string") { - k = rep[i]; - v = str(k, value); - if (v) { - partial.push(quote(k) + ( - (gap) - ? ": " - : ":" - ) + v); - } - } - } - } else { - -// Otherwise, iterate through all of the keys in the object. - - for (k in value) { - if (Object.prototype.hasOwnProperty.call(value, k)) { - v = str(k, value); - if (v) { - partial.push(quote(k) + ( - (gap) - ? ": " - : ":" - ) + v); - } - } - } - } - -// Join all of the member texts together, separated with commas, -// and wrap them in braces. - - v = partial.length === 0 - ? "{}" - : gap - ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}" - : "{" + partial.join(",") + "}"; - gap = mind; - return v; - } - } - -// If the JSON object does not yet have a stringify method, give it one. - - if (typeof JSON.stringify !== "function") { - meta = { // table of character substitutions - "\b": "\\b", - "\t": "\\t", - "\n": "\\n", - "\f": "\\f", - "\r": "\\r", - "\"": "\\\"", - "\\": "\\\\" - }; - JSON.stringify = function (value, replacer, space) { - -// The stringify method takes a value and an optional replacer, and an optional -// space parameter, and returns a JSON text. The replacer can be a function -// that can replace values, or an array of strings that will select the keys. -// A default replacer method can be provided. Use of the space parameter can -// produce text that is more easily readable. - - var i; - gap = ""; - indent = ""; - -// If the space parameter is a number, make an indent string containing that -// many spaces. - - if (typeof space === "number") { - for (i = 0; i < space; i += 1) { - indent += " "; - } - -// If the space parameter is a string, it will be used as the indent string. - - } else if (typeof space === "string") { - indent = space; - } - -// If there is a replacer, it must be a function or an array. -// Otherwise, throw an error. - - rep = replacer; - if (replacer && typeof replacer !== "function" && ( - typeof replacer !== "object" - || typeof replacer.length !== "number" - )) { - throw new Error("JSON.stringify"); - } - -// Make a fake root object containing our value under the key of "". -// Return the result of stringifying the value. - - return str("", {"": value}); - }; - } - - -// If the JSON object does not yet have a parse method, give it one. - - if (typeof JSON.parse !== "function") { - JSON.parse = function (text, reviver) { - -// The parse method takes a text and an optional reviver function, and returns -// a JavaScript value if the text is a valid JSON text. - - var j; - - function walk(holder, key) { - -// The walk method is used to recursively walk the resulting structure so -// that modifications can be made. - - var k; - var v; - var value = holder[key]; - if (value && typeof value === "object") { - for (k in value) { - if (Object.prototype.hasOwnProperty.call(value, k)) { - v = walk(value, k); - if (v !== undefined) { - value[k] = v; - } else { - delete value[k]; - } - } - } - } - return reviver.call(holder, key, value); - } - - -// Parsing happens in four stages. In the first stage, we replace certain -// Unicode characters with escape sequences. JavaScript handles many characters -// incorrectly, either silently deleting them, or treating them as line endings. - - text = String(text); - rx_dangerous.lastIndex = 0; - if (rx_dangerous.test(text)) { - text = text.replace(rx_dangerous, function (a) { - return ( - "\\u" - + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) - ); - }); - } - -// In the second stage, we run the text against regular expressions that look -// for non-JSON patterns. We are especially concerned with "()" and "new" -// because they can cause invocation, and "=" because it can cause mutation. -// But just to be safe, we want to reject all unexpected forms. - -// We split the second stage into 4 regexp operations in order to work around -// crippling inefficiencies in IE's and Safari's regexp engines. First we -// replace the JSON backslash pairs with "@" (a non-JSON character). Second, we -// replace all simple value tokens with "]" characters. Third, we delete all -// open brackets that follow a colon or comma or that begin the text. Finally, -// we look to see that the remaining characters are only whitespace or "]" or -// "," or ":" or "{" or "}". If that is so, then the text is safe for eval. - - if ( - rx_one.test( - text - .replace(rx_two, "@") - .replace(rx_three, "]") - .replace(rx_four, "") - ) - ) { - -// In the third stage we use the eval function to compile the text into a -// JavaScript structure. The "{" operator is subject to a syntactic ambiguity -// in JavaScript: it can begin a block or an object literal. We wrap the text -// in parens to eliminate the ambiguity. - - j = eval("(" + text + ")"); - -// In the optional fourth stage, we recursively walk the new structure, passing -// each name/value pair to a reviver function for possible transformation. - - return (typeof reviver === "function") - ? walk({"": j}, "") - : j; - } - -// If the text is not JSON parseable, then a SyntaxError is thrown. - - throw new SyntaxError("JSON.parse"); - }; - } -}()); - //trim.js -/* -https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/Trim -*/ -if (!String.prototype.trim) { - // Вырезаем BOM и неразрывный пробел - String.prototype.trim = function() { - return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); - }; +/* +https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/String/Trim +*/ +if (!String.prototype.trim) { + // Вырезаем BOM и неразрывный пробел + String.prototype.trim = function() { + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + }; } //toISOString.js /* diff --git a/package-lock.json b/package-lock.json index 2fa4b57..dfde254 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "extendscript-es5-shim", - "version": "0.2.0", + "version": "0.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9d0dbe0..5eeb4a5 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "sham", "prototype" ], - "contributers": [ + "contributors": [ "Fabian Morón Zirfas (http://fabianmoronzirfas.me)", "EugenTepin", "MrSpoocy (https://github.com/MrSpoocy)"