associativearray
Version:
722 lines (651 loc) • 22 kB
JavaScript
var aa =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
function exportAll(lib) {
for (var name in lib) {
if (!exports.hasOwnProperty(name)) exports[name] = lib[name];
}
}
exportAll(__webpack_require__(1));
exportAll(__webpack_require__(18));
exportAll(__webpack_require__(17));
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var existjs_1 = __webpack_require__(2);
var pattern_1 = __webpack_require__(6);
var validation_1 = __webpack_require__(17);
var AssociativeArray = /** @class */ (function (_super) {
__extends(AssociativeArray, _super);
function AssociativeArray() {
return _super !== null && _super.apply(this, arguments) || this;
}
// Recursive output
AssociativeArray.prototype.stringify = function (tab) {
if (tab === void 0) { tab = ""; }
var trace = "";
for (var i in this.names) {
trace += tab + "[" + this.names[i] + "] ";
if (existjs_1.isObject(this.values[i])) {
if (validation_1.isAssociativeArray(this.values[i])) {
trace += "\n" + this.values[i].stringify(tab + "__ ");
}
else {
trace += JSON.stringify(this.values[i]) + "\n";
}
}
else if (existjs_1.isArray(this.values[i])) {
trace += JSON.stringify(this.values[i]) + "\n";
}
else if (existjs_1.isString(this.values[i])) {
trace += "\"" + this.values[i] + "\"\n";
}
else {
trace += this.values[i] + "\n";
}
}
;
return trace;
};
// Get object (no recursion)
AssociativeArray.prototype.object = function () {
var object = {};
for (var i in this.names) {
object[this.names[i]] = this.values[i];
}
return object;
};
// Import from object (no recursion)
AssociativeArray.prototype.fromObject = function (object) {
for (var name_1 in object) {
this.add(name_1, object[name_1]);
}
};
// Export as array form (recursive)
AssociativeArray.prototype.exportArray = function () {
var complex = [];
for (var i in this.names) {
if (validation_1.isAssociativeArray(this.values[i])) {
var value = this.values[i].exportArray();
var type = "AssociativeArray";
}
else {
var value = this.values[i];
var type = "Object";
}
complex.push({
name: this.names[i],
value: value,
type: type
});
}
return complex;
};
// Import from array form (recursive)
AssociativeArray.prototype.importArray = function (array) {
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
var v = array_1[_i];
if (!existjs_1.exist(v.name) || !existjs_1.exist(v.value) || !existjs_1.exist(v.type)) {
throw "Invalid Array";
}
if (v.type === "AssociativeArray") {
var associativeArray = new AssociativeArray();
associativeArray.importArray(v.value);
this.add(v.name, associativeArray);
}
else {
this.add(v.name, v.value);
}
}
};
return AssociativeArray;
}(pattern_1.Pattern));
exports.AssociativeArray = AssociativeArray;
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
function exportAll(lib) {
for (var name in lib) {
if (!exports.hasOwnProperty(name)) exports[name] = lib[name];
}
}
exportAll(__webpack_require__(3));
exportAll(__webpack_require__(4));
exportAll(__webpack_require__(5));
/***/ }),
/* 3 */
/***/ (function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Check type
function isObject(objectToCheck) {
return Object.prototype.toString
.call(objectToCheck) === '[object Object]';
}
exports.isObject = isObject;
function isNumber(numberToCheck) {
return Object.prototype.toString
.call(numberToCheck) === '[object Number]';
}
exports.isNumber = isNumber;
function isString(stringToCheck) {
return Object.prototype.toString
.call(stringToCheck) === '[object String]';
}
exports.isString = isString;
function isArray(arrayToCheck) {
return Object.prototype.toString
.call(arrayToCheck) === '[object Array]';
}
exports.isArray = isArray;
function isFunction(functionToCheck) {
return Object.prototype.toString
.call(functionToCheck) === '[object Function]';
}
exports.isFunction = isFunction;
function isBoolean(booleanToCheck) {
return Object.prototype.toString
.call(booleanToCheck) === '[object Boolean]';
}
exports.isBoolean = isBoolean;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var check_types_1 = __webpack_require__(3);
// Does the object exist?
function exist(obj) {
if (obj === undefined || obj === null || (check_types_1.isNumber(obj) && isNaN(obj))) {
return false;
}
else {
return true;
}
}
exports.exist = exist;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var exist_1 = __webpack_require__(4);
// Choose first existing object
function or() {
var list = [];
for (var _i = 0; _i < arguments.length; _i++) {
list[_i] = arguments[_i];
}
for (var _a = 0, list_1 = list; _a < list_1.length; _a++) {
var value = list_1[_a];
if (exist_1.exist(value)) {
return value;
}
}
return null;
}
exports.or = or;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var existjs_1 = __webpack_require__(2);
var rndmjs_1 = __webpack_require__(7);
var Pattern = /** @class */ (function () {
function Pattern() {
this.length = 0;
this.names = [];
this.values = [];
this.id = 0;
this.keys = {};
}
Pattern.prototype.updateKeys = function () {
var keys = {};
for (var i in this.names) {
keys[this.names[i]] = i;
}
this.keys = keys;
};
// Add new element with name
Pattern.prototype.add = function (name, value) {
if (existjs_1.exist(this.keys[name])) {
this.change(name, value);
return;
}
this.names.push(name);
this.values.push(value);
this.length = this.names.length;
this.keys[name] = this.length - 1;
};
// Get value by name
Pattern.prototype.value = function (name) {
return this.values[this.keys[name]];
};
// Add new unnamed element
Pattern.prototype.push = function (value) {
var id = "id" + rndmjs_1.randstr(5) + this.id++;
this.add(id, value);
return id;
};
// Change value by name
Pattern.prototype.change = function (name, value) {
if (!existjs_1.exist(this.keys[name])) {
return;
}
this.values[this.keys[name]] = value;
};
// Remote element by name
Pattern.prototype.remove = function (name) {
if (!existjs_1.exist(this.keys[name])) {
return;
}
if (this.length === 1) {
this.names = [];
this.values = [];
}
else {
this.names.splice(this.keys[name], 1);
this.values.splice(this.keys[name], 1);
}
this.length = this.names.length;
delete this.keys[name];
};
// Get name by value. Only first occurrence.
Pattern.prototype.search = function (value) {
var i = this.values.indexOf(value);
if (i === -1) {
return undefined;
}
return this.names[i];
};
Pattern.prototype.forEach = function (callback) {
for (var i in this.names) {
var breakPoint = callback(this.values[i], this.names[i]);
if (breakPoint === "break") {
break;
}
}
};
// Get string form of all elements
Pattern.prototype.toString = function () {
var trace = "";
for (var i in this.names) {
trace += "[" + this.names[i] + "] " + this.values[i] + "\n";
}
;
return trace;
};
// Change name of element
Pattern.prototype.rename = function (name, newname) {
this.add(newname, this.value(name));
this.remove(name);
};
// Reverse Pattern
Pattern.prototype.reverse = function () {
this.values.reverse();
this.names.reverse();
};
// Copy Pattern
Pattern.prototype.copy = function (pattern) {
this.values = pattern.values.slice();
this.names = pattern.names.slice();
this.length = pattern.length;
this.id = Math.max(this.id, pattern.id);
this.updateKeys();
};
// Share values
Pattern.prototype.share = function (pattern, names) {
for (var _i = 0, names_1 = names; _i < names_1.length; _i++) {
var name_1 = names_1[_i];
pattern.add(name_1, this.values[this.keys[name_1]]);
}
pattern.id = Math.max(pattern.id, this.id);
};
// Get array
Pattern.prototype.array = function () {
var complex = [];
for (var i in this.names) {
complex.push({
name: this.names[i],
value: this.values[i]
});
}
return complex;
};
// Import from array
Pattern.prototype.fromArray = function (array) {
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
var v = array_1[_i];
this.push(v);
}
};
// Sort Pattern
Pattern.prototype.sort = function (handler) {
var array = this.array();
array.sort(handler);
for (var i in array) {
this.names[i] = array[i].name;
this.values[i] = array[i].value;
}
this.updateKeys();
};
// Shuffle Pattern
Pattern.prototype.shuffle = function () {
var array = this.array();
for (var i = array.length; i; i--) {
var j = Math.floor(Math.random() * i);
_a = [array[j], array[i - 1]], array[i - 1] = _a[0], array[j] = _a[1];
}
for (var i in array) {
this.names[i] = array[i].name;
this.values[i] = array[i].value;
}
this.updateKeys();
var _a;
};
// Concat Pattern
Pattern.prototype.concat = function () {
var patterns = [];
for (var _i = 0; _i < arguments.length; _i++) {
patterns[_i] = arguments[_i];
}
for (var _a = 0, patterns_1 = patterns; _a < patterns_1.length; _a++) {
var pattern = patterns_1[_a];
this.names = this.names.concat(pattern.names);
this.values = this.values.concat(pattern.values);
this.id = Math.max(this.id, pattern.id);
}
this.length = this.names.length;
this.updateKeys();
};
return Pattern;
}());
exports.Pattern = Pattern;
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
function exportAll(lib) {
for (var name in lib) {
if (!exports.hasOwnProperty(name)) exports[name] = lib[name];
}
}
exportAll(__webpack_require__(8));
exportAll(__webpack_require__(9));
exportAll(__webpack_require__(11));
exportAll(__webpack_require__(12));
exportAll(__webpack_require__(16));
exportAll(__webpack_require__(15));
exportAll(__webpack_require__(14));
exportAll(__webpack_require__(13));
/***/ }),
/* 8 */
/***/ (function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// More simple random function
function rand(a, b) {
var c;
var d;
c = b - a;
if (c < 0) {
return -1;
}
d = Math.random() * c;
d = Math.round(d);
d += a;
return d;
}
exports.rand = rand;
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var generate_rand_symbols_1 = __webpack_require__(10);
// Get random hex color
function randcolor() {
return '#' + generate_rand_symbols_1.generateRandSymbols(16, 6);
}
exports.randcolor = randcolor;
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rand_1 = __webpack_require__(8);
// Generate random symbols
function generateRandSymbols(radix, length) {
if (radix < 2) {
radix = 2;
}
if (radix > 36) {
radix = 36;
}
var symbols = '';
for (var i = 0; i < length; i++) {
symbols += rand_1.rand(0, radix - 1).toString(radix);
}
return symbols;
}
exports.generateRandSymbols = generateRandSymbols;
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var generate_rand_symbols_1 = __webpack_require__(10);
// Get random string
function randstr(length) {
return generate_rand_symbols_1.generateRandSymbols(36, length);
}
exports.randstr = randstr;
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var dict_1 = __webpack_require__(13);
var rand_custom_string_1 = __webpack_require__(14);
// Get random string with 64 symbals dict [a-z,A-Z,0-9,-,_]
function randstr64(length) {
return rand_custom_string_1.randCustomString(dict_1.dict64, length);
}
exports.randstr64 = randstr64;
/***/ }),
/* 13 */
/***/ (function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
exports.alphabet = alphabet;
var numerals = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
exports.numerals = numerals;
var dict16 = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
exports.dict16 = dict16;
var Alphabet = [];
exports.Alphabet = Alphabet;
for (var _i = 0, alphabet_1 = alphabet; _i < alphabet_1.length; _i++) {
var letter = alphabet_1[_i];
Alphabet.push(letter.toUpperCase());
}
var dict36 = alphabet.concat(numerals);
exports.dict36 = dict36;
var extra = ['-', '_'];
var dict64 = dict36.concat(extra).concat(Alphabet);
exports.dict64 = dict64;
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var randvalue_1 = __webpack_require__(15);
// Get random string with custon dict
function randCustomString(dict, length) {
var trace = '';
for (var i = 0; i < length; i++) {
trace += randvalue_1.randvalue(dict);
}
return trace;
}
exports.randCustomString = randCustomString;
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rand_1 = __webpack_require__(8);
// Get random value of an array
function randvalue(array) {
return array[rand_1.rand(0, array.length - 1)];
}
exports.randvalue = randvalue;
/***/ }),
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var dict_1 = __webpack_require__(13);
var rand_custom_string_1 = __webpack_require__(14);
// Get random text (without numerals)
function randtext(length) {
return rand_custom_string_1.randCustomString(dict_1.alphabet, length);
}
exports.randtext = randtext;
/***/ }),
/* 17 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var existjs_1 = __webpack_require__(2);
var associativearray_1 = __webpack_require__(1);
var dictionary_1 = __webpack_require__(18);
function isAssociativeArray(object) {
if (!existjs_1.exist(object))
return false;
return (object instanceof associativearray_1.AssociativeArray) ? true : false;
}
exports.isAssociativeArray = isAssociativeArray;
function isDictionary(object) {
if (!existjs_1.exist(object))
return false;
return (object instanceof dictionary_1.Dictionary) ? true : false;
}
exports.isDictionary = isDictionary;
/***/ }),
/* 18 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var pattern_1 = __webpack_require__(6);
var Dictionary = /** @class */ (function (_super) {
__extends(Dictionary, _super);
function Dictionary() {
return _super !== null && _super.apply(this, arguments) || this;
}
Dictionary.prototype.add = function (name, value) {
_super.prototype.add.call(this, name, value);
};
Dictionary.prototype.value = function (name) {
return this.values[this.keys[name]];
};
Dictionary.prototype.push = function (value) {
return _super.prototype.push.call(this, value);
};
Dictionary.prototype.change = function (name, value) {
_super.prototype.change.call(this, name, value);
};
Dictionary.prototype.search = function (value) {
return _super.prototype.search.call(this, value);
};
Dictionary.prototype.copy = function (dictionary) {
_super.prototype.copy.call(this, dictionary);
};
Dictionary.prototype.share = function (dictionary, names) {
_super.prototype.share.call(this, dictionary, names);
};
Dictionary.prototype.concat = function () {
var dictionaries = [];
for (var _i = 0; _i < arguments.length; _i++) {
dictionaries[_i] = arguments[_i];
}
_super.prototype.concat.apply(this, dictionaries);
};
Dictionary.prototype.array = function () {
var complex = [];
for (var i in this.names) {
complex.push({
name: this.names[i],
value: this.values[i]
});
}
return complex;
};
Dictionary.prototype.fromArray = function (array) {
_super.prototype.fromArray.call(this, array);
};
Dictionary.prototype.forEach = function (callback) {
_super.prototype.forEach.call(this, callback);
};
Dictionary.prototype.sort = function (handler) {
_super.prototype.sort.call(this, handler);
};
return Dictionary;
}(pattern_1.Pattern));
exports.Dictionary = Dictionary;
/***/ })
/******/ ]);