|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Localbase = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = void 0; |
|
|
|
var _localbase = _interopRequireDefault(require("./localbase/localbase")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
var _default = _localbase["default"]; |
|
exports["default"] = _default; |
|
module.exports = exports.default; |
|
|
|
},{"./localbase/localbase":16}],2:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = error; |
|
|
|
var _logger = _interopRequireDefault(require("../utils/logger")); |
|
|
|
var _reset = _interopRequireDefault(require("../api-utils/reset")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function error(message) { |
|
_reset["default"].call(this); |
|
|
|
_logger["default"].error.call(this, message); |
|
|
|
return "Error: ".concat(message); |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{"../api-utils/reset":3,"../utils/logger":18}],3:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = reset; |
|
|
|
function reset() { |
|
this.collectionName = null; |
|
this.orderByProperty = null; |
|
this.orderByDirection = null; |
|
this.limitBy = null; |
|
this.docSelectionCriteria = null; |
|
this.userErrors = []; |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{}],4:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = selectionLevel; |
|
|
|
function selectionLevel() { |
|
var level; |
|
if (!this.collectionName && !this.docSelectionCriteria) level = 'db';else if (this.collectionName && !this.docSelectionCriteria) level = 'collection';else if (this.collectionName && this.docSelectionCriteria) level = 'doc'; |
|
return level; |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{}],5:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = showUserErrors; |
|
|
|
var _logger = _interopRequireDefault(require("../utils/logger")); |
|
|
|
var _reset = _interopRequireDefault(require("./reset")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function showUserErrors() { |
|
for (var i = 0; i < this.userErrors.length; i++) { |
|
_logger["default"].error.call(this, this.userErrors[i]); |
|
} |
|
|
|
_reset["default"].call(this); |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{"../utils/logger":18,"./reset":3}],6:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = success; |
|
|
|
var _logger = _interopRequireDefault(require("../utils/logger")); |
|
|
|
var _reset = _interopRequireDefault(require("../api-utils/reset")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function success(message, data) { |
|
_reset["default"].call(this); |
|
|
|
_logger["default"].log.call(this, message, data); |
|
|
|
return "Success: ".concat(message, " ").concat(JSON.stringify(data)); |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{"../api-utils/reset":3,"../utils/logger":18}],7:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = add; |
|
|
|
var _success = _interopRequireDefault(require("../../api-utils/success")); |
|
|
|
var _error = _interopRequireDefault(require("../../api-utils/error")); |
|
|
|
var _showUserErrors = _interopRequireDefault(require("../../api-utils/showUserErrors")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
|
|
|
var UUID = require('ordered-uuid'); |
|
|
|
function add(data, keyProvided) { |
|
var _this = this; |
|
|
|
|
|
if (!data) { |
|
this.userErrors.push('No data specified in add() method. You must use an object, e.g { id: 1, name: "Bill", age: 47 }'); |
|
} else if (!(_typeof(data) == 'object' && data instanceof Array == false)) { |
|
this.userErrors.push('Data passed to .add() must be an object. Not an array, string, number or boolean.'); |
|
} |
|
|
|
|
|
if (!this.userErrors.length) { |
|
var collectionName = this.collectionName; |
|
return new Promise(function (resolve, reject) { |
|
var key = null; |
|
|
|
if (!keyProvided) { |
|
key = UUID.generate(); |
|
} else { |
|
key = keyProvided; |
|
} |
|
|
|
return _this.lf[collectionName].setItem(key, data).then(function () { |
|
resolve(_success["default"].call(_this, "Document added to \"".concat(collectionName, "\" collection:"), { |
|
key: key, |
|
data: data |
|
})); |
|
})["catch"](function (err) { |
|
reject(_error["default"].call(_this, "Could not add Document to ".concat(collectionName, " collection."))); |
|
}); |
|
}); |
|
} else { |
|
_showUserErrors["default"].call(this); |
|
} |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{"../../api-utils/error":2,"../../api-utils/showUserErrors":5,"../../api-utils/success":6,"ordered-uuid":21}],8:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = deleteIt; |
|
|
|
var _isSubset = _interopRequireDefault(require("../../utils/isSubset")); |
|
|
|
var _logger = _interopRequireDefault(require("../../utils/logger")); |
|
|
|
var _selectionLevel = _interopRequireDefault(require("../../api-utils/selectionLevel")); |
|
|
|
var _success = _interopRequireDefault(require("../../api-utils/success")); |
|
|
|
var _error = _interopRequireDefault(require("../../api-utils/error")); |
|
|
|
var _showUserErrors = _interopRequireDefault(require("../../api-utils/showUserErrors")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
|
|
|
function deleteIt() { |
|
var _this = this; |
|
|
|
return new Promise(function (resolve, reject) { |
|
|
|
_this.deleteDatabase = function () { |
|
var dbName = _this.dbName; |
|
indexedDB.deleteDatabase(dbName); |
|
resolve(_success["default"].call(_this, "Database \"".concat(dbName, "\" deleted."))); |
|
}; |
|
|
|
|
|
_this.deleteCollection = function () { |
|
var dbName = _this.dbName; |
|
var collectionName = _this.collectionName; |
|
|
|
_this.addToDeleteCollectionQueue = function (collectionName) { |
|
_this.deleteCollectionQueue.queue.push(collectionName); |
|
|
|
_this.runDeleteCollectionQueue(); |
|
}; |
|
|
|
_this.runDeleteCollectionQueue = function () { |
|
if (_this.deleteCollectionQueue.running == false) { |
|
_this.deleteCollectionQueue.running = true; |
|
|
|
_this.deleteNextCollectionFromQueue(); |
|
} |
|
}; |
|
|
|
_this.deleteNextCollectionFromQueue = function () { |
|
if (_this.deleteCollectionQueue.queue.length) { |
|
var collectionToDelete = _this.deleteCollectionQueue.queue[0]; |
|
|
|
_this.deleteCollectionQueue.queue.shift(); |
|
|
|
_this.lf[collectionToDelete].dropInstance({ |
|
name: dbName, |
|
storeName: collectionToDelete |
|
}).then(function () { |
|
_this.deleteNextCollectionFromQueue(); |
|
|
|
resolve(_success["default"].call(_this, "Collection \"".concat(collectionToDelete, "\" deleted."))); |
|
})["catch"](function (error) { |
|
reject(error.call(_this, "Collection \"".concat(collectionToDelete, "\" could not be deleted."))); |
|
}); |
|
} else { |
|
_this.deleteCollectionQueue.running = false; |
|
} |
|
}; |
|
|
|
_this.addToDeleteCollectionQueue(collectionName); |
|
}; |
|
|
|
|
|
_this.deleteDocument = function () { |
|
var collectionName = _this.collectionName; |
|
var docSelectionCriteria = _this.docSelectionCriteria; |
|
|
|
_this.deleteDocumentByCriteria = function () { |
|
var keysForDeletion = []; |
|
|
|
_this.lf[collectionName].iterate(function (value, key) { |
|
if ((0, _isSubset["default"])(value, docSelectionCriteria)) { |
|
keysForDeletion.push(key); |
|
} |
|
}).then(function () { |
|
if (!keysForDeletion.length) { |
|
reject(_error["default"].call(_this, "No Documents found in \"".concat(collectionName, "\" Collection with criteria ").concat(JSON.stringify(docSelectionCriteria), ". No documents deleted."))); |
|
} |
|
|
|
if (keysForDeletion.length > 1) { |
|
_logger["default"].warn.call(_this, "Multiple documents (".concat(keysForDeletion.length, ") with ").concat(JSON.stringify(docSelectionCriteria), " found.")); |
|
} |
|
}).then(function () { |
|
keysForDeletion.forEach(function (key, index) { |
|
_this.lf[collectionName].removeItem(key).then(function () { |
|
if (index === keysForDeletion.length - 1) { |
|
resolve(_success["default"].call(_this, "".concat(keysForDeletion.length, " Document").concat(keysForDeletion.length > 1 ? 's' : '', " with ").concat(JSON.stringify(docSelectionCriteria), " deleted."))); |
|
} |
|
})["catch"](function (err) { |
|
reject(_error["default"].call(_this, "Could not delete ".concat(keysForDeletion.length, " Documents in ").concat(collectionName, " Collection."))); |
|
}); |
|
}); |
|
}); |
|
}; |
|
|
|
|
|
_this.deleteDocumentByKey = function () { |
|
_this.lf[collectionName].getItem(docSelectionCriteria).then(function (value) { |
|
if (value) { |
|
_this.lf[collectionName].removeItem(docSelectionCriteria).then(function () { |
|
resolve(_success["default"].call(_this, "Document with key ".concat(JSON.stringify(docSelectionCriteria), " deleted."))); |
|
})["catch"](function (err) { |
|
reject(_error["default"].call(this, "No Document found in \"".concat(collectionName, "\" Collection with key ").concat(JSON.stringify(docSelectionCriteria), ". No document was deleted."))); |
|
}); |
|
} else { |
|
reject(_error["default"].call(_this, "No Document found in \"".concat(collectionName, "\" Collection with key ").concat(JSON.stringify(docSelectionCriteria), ". No document was deleted."))); |
|
} |
|
}); |
|
}; |
|
|
|
if (_typeof(docSelectionCriteria) == 'object') { |
|
return _this.deleteDocumentByCriteria(); |
|
} else { |
|
return _this.deleteDocumentByKey(); |
|
} |
|
}; |
|
|
|
if (!_this.userErrors.length) { |
|
var currentSelectionLevel = _selectionLevel["default"].call(_this); |
|
|
|
if (currentSelectionLevel == 'db') { |
|
return _this.deleteDatabase(); |
|
} else if (currentSelectionLevel == 'collection') { |
|
return _this.deleteCollection(); |
|
} else if (currentSelectionLevel == 'doc') { |
|
return _this.deleteDocument(); |
|
} |
|
} else { |
|
_showUserErrors["default"].call(_this); |
|
} |
|
}); |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{"../../api-utils/error":2,"../../api-utils/selectionLevel":4,"../../api-utils/showUserErrors":5,"../../api-utils/success":6,"../../utils/isSubset":17,"../../utils/logger":18}],9:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = get; |
|
|
|
var _isSubset = _interopRequireDefault(require("../../utils/isSubset")); |
|
|
|
var _logger = _interopRequireDefault(require("../../utils/logger")); |
|
|
|
var _reset = _interopRequireDefault(require("../../api-utils/reset")); |
|
|
|
var _selectionLevel = _interopRequireDefault(require("../../api-utils/selectionLevel")); |
|
|
|
var _showUserErrors = _interopRequireDefault(require("../../api-utils/showUserErrors")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
|
|
|
function get() { |
|
var _this = this; |
|
|
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { |
|
keys: false |
|
}; |
|
|
|
|
|
this.getCollection = function () { |
|
var collectionName = _this.collectionName; |
|
var orderByProperty = _this.orderByProperty; |
|
var orderByDirection = _this.orderByDirection; |
|
var limitBy = _this.limitBy; |
|
var collection = []; |
|
return _this.lf[collectionName].iterate(function (value, key) { |
|
var collectionItem = {}; |
|
|
|
if (!options.keys) { |
|
collectionItem = value; |
|
} else { |
|
collectionItem = { |
|
key: key, |
|
data: value |
|
}; |
|
} |
|
|
|
collection.push(collectionItem); |
|
}).then(function () { |
|
var logMessage = "Got \"".concat(collectionName, "\" collection"); |
|
|
|
if (orderByProperty) { |
|
logMessage += ", ordered by \"".concat(orderByProperty, "\""); |
|
|
|
if (!options.keys) { |
|
collection.sort(function (a, b) { |
|
return a[orderByProperty].toString().localeCompare(b[orderByProperty].toString()); |
|
}); |
|
} else { |
|
collection.sort(function (a, b) { |
|
return a.data[orderByProperty].toString().localeCompare(b.data[orderByProperty].toString()); |
|
}); |
|
} |
|
} |
|
|
|
if (orderByDirection == 'desc') { |
|
logMessage += " (descending)"; |
|
collection.reverse(); |
|
} |
|
|
|
|
|
if (limitBy) { |
|
logMessage += ", limited to ".concat(limitBy); |
|
collection = collection.splice(0, limitBy); |
|
} |
|
|
|
logMessage += ":"; |
|
|
|
_logger["default"].log.call(_this, logMessage, collection); |
|
|
|
_reset["default"].call(_this); |
|
|
|
return collection; |
|
}); |
|
}; |
|
|
|
|
|
this.getDocument = function () { |
|
var collectionName = _this.collectionName; |
|
var docSelectionCriteria = _this.docSelectionCriteria; |
|
var collection = []; |
|
var document = {}; |
|
|
|
_this.getDocumentByCriteria = function () { |
|
return _this.lf[collectionName].iterate(function (value, key) { |
|
if ((0, _isSubset["default"])(value, docSelectionCriteria)) { |
|
collection.push(value); |
|
} |
|
}).then(function () { |
|
if (!collection.length) { |
|
_logger["default"].error.call(_this, "Could not find Document in \"".concat(collectionName, "\" collection with criteria: ").concat(JSON.stringify(docSelectionCriteria))); |
|
} else { |
|
document = collection[0]; |
|
|
|
_logger["default"].log.call(_this, "Got Document with ".concat(JSON.stringify(docSelectionCriteria), ":"), document); |
|
|
|
_reset["default"].call(_this); |
|
|
|
return document; |
|
} |
|
}); |
|
}; |
|
|
|
|
|
_this.getDocumentByKey = function () { |
|
return _this.lf[collectionName].getItem(docSelectionCriteria).then(function (value) { |
|
document = value; |
|
|
|
if (document) { |
|
_logger["default"].log.call(_this, "Got Document with key ".concat(JSON.stringify(docSelectionCriteria), ":"), document); |
|
} else { |
|
_logger["default"].error.call(_this, "Could not find Document in \"".concat(collectionName, "\" collection with Key: ").concat(JSON.stringify(docSelectionCriteria))); |
|
} |
|
|
|
_reset["default"].call(_this); |
|
|
|
return document; |
|
})["catch"](function (err) { |
|
_logger["default"].error.call(_this, "Could not find Document in \"".concat(collectionName, "\" collection with Key: ").concat(JSON.stringify(docSelectionCriteria))); |
|
|
|
_reset["default"].call(_this); |
|
}); |
|
}; |
|
|
|
if (_typeof(docSelectionCriteria) == 'object') { |
|
return _this.getDocumentByCriteria(); |
|
} else { |
|
return _this.getDocumentByKey(); |
|
} |
|
}; |
|
|
|
|
|
if (!(_typeof(options) == 'object' && options instanceof Array == false)) { |
|
this.userErrors.push('Data passed to .get() must be an object. Not an array, string, number or boolean. The object must contain a "keys" property set to true or false, e.g. { keys: true }'); |
|
} else { |
|
if (!options.hasOwnProperty('keys')) { |
|
this.userErrors.push('Object passed to get() method must contain a "keys" property set to boolean true or false, e.g. { keys: true }'); |
|
} else { |
|
if (typeof options.keys !== 'boolean') { |
|
this.userErrors.push('Property "keys" passed into get() method must be assigned a boolean value (true or false). Not a string or integer.'); |
|
} |
|
} |
|
} |
|
|
|
if (!this.userErrors.length) { |
|
var currentSelectionLevel = _selectionLevel["default"].call(this); |
|
|
|
if (currentSelectionLevel == 'collection') { |
|
return this.getCollection(); |
|
} else if (currentSelectionLevel == 'doc') { |
|
return this.getDocument(); |
|
} |
|
} else { |
|
_showUserErrors["default"].call(this); |
|
|
|
return null; |
|
} |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{"../../api-utils/reset":3,"../../api-utils/selectionLevel":4,"../../api-utils/showUserErrors":5,"../../utils/isSubset":17,"../../utils/logger":18}],10:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = set; |
|
|
|
var _logger = _interopRequireDefault(require("../../utils/logger")); |
|
|
|
var _isSubset = _interopRequireDefault(require("../../utils/isSubset")); |
|
|
|
var _success = _interopRequireDefault(require("../../api-utils/success")); |
|
|
|
var _error = _interopRequireDefault(require("../../api-utils/error")); |
|
|
|
var _showUserErrors = _interopRequireDefault(require("../../api-utils/showUserErrors")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
|
|
|
function set(newDocument) { |
|
var _this = this; |
|
|
|
var collectionName = this.collectionName; |
|
var docSelectionCriteria = this.docSelectionCriteria; |
|
return new Promise(function (resolve, reject) { |
|
|
|
_this.setDocumentByCriteria = function () { |
|
var docsToSet = []; |
|
|
|
_this.lf[collectionName].iterate(function (value, key) { |
|
if ((0, _isSubset["default"])(value, docSelectionCriteria)) { |
|
docsToSet.push({ |
|
key: key, |
|
newDocument: newDocument |
|
}); |
|
} |
|
}).then(function () { |
|
if (!docsToSet.length) { |
|
reject(_error["default"].call(_this, "No Documents found in ".concat(collectionName, " Collection with criteria ").concat(JSON.stringify(docSelectionCriteria), "."))); |
|
} |
|
|
|
if (docsToSet.length > 1) { |
|
_logger["default"].warn.call(_this, "Multiple documents (".concat(docsToSet.length, ") with ").concat(JSON.stringify(docSelectionCriteria), " found for setting.")); |
|
} |
|
}).then(function () { |
|
docsToSet.forEach(function (docToSet, index) { |
|
_this.lf[collectionName].setItem(docToSet.key, docToSet.newDocument).then(function (value) { |
|
if (index === docsToSet.length - 1) { |
|
resolve(_success["default"].call(_this, "".concat(docsToSet.length, " Document").concat(docsToSet.length > 1 ? 's' : '', " in \"").concat(collectionName, "\" collection with ").concat(JSON.stringify(docSelectionCriteria), " set to:"), newDocument)); |
|
} |
|
})["catch"](function (err) { |
|
reject(_error["default"].call(_this, "Could not set ".concat(docsToSet.length, " Documents in ").concat(collectionName, " Collection."))); |
|
}); |
|
}); |
|
}); |
|
}; |
|
|
|
|
|
_this.setDocumentByKey = function () { |
|
_this.lf[collectionName].setItem(docSelectionCriteria, newDocument).then(function (value) { |
|
resolve(_success["default"].call(_this, "Document in \"".concat(collectionName, "\" collection with key ").concat(JSON.stringify(docSelectionCriteria), " set to:"), newDocument)); |
|
})["catch"](function (err) { |
|
reject(_error["default"].call(_this, "Document in \"".concat(collectionName, "\" collection with key ").concat(JSON.stringify(docSelectionCriteria), " could not be set."))); |
|
}); |
|
}; |
|
|
|
|
|
if (!newDocument) { |
|
_this.userErrors.push('No new Document object provided to set() method. Use an object e.g. { id: 1, name: "Bill", age: 47 }'); |
|
} else if (!(_typeof(newDocument) == 'object' && newDocument instanceof Array == false)) { |
|
_this.userErrors.push('Data passed to .set() must be an object. Not an array, string, number or boolean.'); |
|
} |
|
|
|
if (!_this.userErrors.length) { |
|
if (_typeof(docSelectionCriteria) == 'object') { |
|
return _this.setDocumentByCriteria(); |
|
} else { |
|
return _this.setDocumentByKey(); |
|
} |
|
} else { |
|
_showUserErrors["default"].call(_this); |
|
} |
|
}); |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{"../../api-utils/error":2,"../../api-utils/showUserErrors":5,"../../api-utils/success":6,"../../utils/isSubset":17,"../../utils/logger":18}],11:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = update; |
|
|
|
var _logger = _interopRequireDefault(require("../../utils/logger")); |
|
|
|
var _isSubset = _interopRequireDefault(require("../../utils/isSubset")); |
|
|
|
var _updateObject = _interopRequireDefault(require("../../utils/updateObject")); |
|
|
|
var _success = _interopRequireDefault(require("../../api-utils/success")); |
|
|
|
var _error = _interopRequireDefault(require("../../api-utils/error")); |
|
|
|
var _showUserErrors = _interopRequireDefault(require("../../api-utils/showUserErrors")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
|
|
|
function update(docUpdates) { |
|
var _this = this; |
|
|
|
var collectionName = this.collectionName; |
|
var docSelectionCriteria = this.docSelectionCriteria; |
|
return new Promise(function (resolve, reject) { |
|
|
|
_this.updateDocumentByCriteria = function () { |
|
var docsToUpdate = []; |
|
|
|
_this.lf[collectionName].iterate(function (value, key) { |
|
if ((0, _isSubset["default"])(value, docSelectionCriteria)) { |
|
var newDocument = (0, _updateObject["default"])(value, docUpdates); |
|
docsToUpdate.push({ |
|
key: key, |
|
newDocument: newDocument |
|
}); |
|
} |
|
}).then(function () { |
|
if (!docsToUpdate.length) { |
|
reject(_error["default"].call(_this, "No Documents found in ".concat(collectionName, " Collection with criteria ").concat(JSON.stringify(docSelectionCriteria), "."))); |
|
} |
|
|
|
if (docsToUpdate.length > 1) { |
|
_logger["default"].warn.call(_this, "Multiple documents (".concat(docsToUpdate.length, ") with ").concat(JSON.stringify(docSelectionCriteria), " found for updating.")); |
|
} |
|
}).then(function () { |
|
docsToUpdate.forEach(function (docToUpdate, index) { |
|
_this.lf[collectionName].setItem(docToUpdate.key, docToUpdate.newDocument).then(function (value) { |
|
if (index === docsToUpdate.length - 1) { |
|
resolve(_success["default"].call(_this, "".concat(docsToUpdate.length, " Document").concat(docsToUpdate.length > 1 ? 's' : '', " in \"").concat(collectionName, "\" collection with ").concat(JSON.stringify(docSelectionCriteria), " updated with:"), docUpdates)); |
|
} |
|
})["catch"](function (err) { |
|
reject(_error["default"].call(_this, "Could not update ".concat(docsToUpdate.length, " Documents in ").concat(collectionName, " Collection."))); |
|
}); |
|
}); |
|
}); |
|
}; |
|
|
|
|
|
_this.updateDocumentByKey = function () { |
|
var newDocument = {}; |
|
|
|
_this.lf[collectionName].getItem(docSelectionCriteria).then(function (value) { |
|
newDocument = (0, _updateObject["default"])(value, docUpdates); |
|
|
|
_this.lf[collectionName].setItem(docSelectionCriteria, newDocument); |
|
|
|
resolve(_success["default"].call(_this, "Document in \"".concat(collectionName, "\" collection with key ").concat(JSON.stringify(docSelectionCriteria), " updated to:"), newDocument)); |
|
})["catch"](function (err) { |
|
reject(_error["default"].call(_this, "No Document found in \"".concat(collectionName, "\" collection with key ").concat(JSON.stringify(docSelectionCriteria)))); |
|
}); |
|
}; |
|
|
|
|
|
if (!docUpdates) { |
|
_this.userErrors.push('No update object provided to update() method. Use an object e.g. { name: "William" }'); |
|
} else if (!(_typeof(docUpdates) == 'object' && docUpdates instanceof Array == false)) { |
|
_this.userErrors.push('Data passed to .update() must be an object. Not an array, string, number or boolean.'); |
|
} |
|
|
|
if (!_this.userErrors.length) { |
|
if (_typeof(docSelectionCriteria) == 'object') { |
|
_this.updateDocumentByCriteria(); |
|
} else { |
|
_this.updateDocumentByKey(); |
|
} |
|
} else { |
|
_showUserErrors["default"].call(_this); |
|
} |
|
}); |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{"../../api-utils/error":2,"../../api-utils/showUserErrors":5,"../../api-utils/success":6,"../../utils/isSubset":17,"../../utils/logger":18,"../../utils/updateObject":19}],12:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = limit; |
|
|
|
function limit(limitBy) { |
|
if (!limitBy) { |
|
this.userErrors.push("No integer specified in limit() method."); |
|
} else if (!Number.isInteger(limitBy)) { |
|
this.userErrors.push("Limit parameter in limit() method must be an integer (e.g. 3) and not a float, boolean, string or object."); |
|
} else { |
|
this.limitBy = limitBy; |
|
} |
|
|
|
return this; |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{}],13:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = orderBy; |
|
|
|
function orderBy(property, direction) { |
|
if (!property) { |
|
this.userErrors.push("No field name specified in orderBy() method. Use a string e.g. 'name'"); |
|
} else if (typeof property !== 'string') { |
|
this.userErrors.push("First parameter in orderBy() method must be a string (a field name) e.g. 'name'"); |
|
} else { |
|
this.orderByProperty = property; |
|
} |
|
|
|
if (direction) { |
|
if (direction !== 'asc' && direction !== 'desc') { |
|
this.userErrors.push("Second parameter in orderBy() method must be a string set to 'asc' or 'desc'."); |
|
} else { |
|
this.orderByDirection = direction; |
|
} |
|
} |
|
|
|
return this; |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{}],14:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = collection; |
|
|
|
var _localforage = _interopRequireDefault(require("localforage")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function collection(collectionName) { |
|
if (!collectionName) { |
|
this.userErrors.push('No collection name specified in collection() method.'); |
|
return this; |
|
} else if (typeof collectionName !== 'string') { |
|
this.userErrors.push('Collection name in collection() method must be a string and not an object, number or boolean.'); |
|
return this; |
|
} else { |
|
this.collectionName = collectionName; |
|
var dbName = this.dbName; |
|
|
|
|
|
if (!(collectionName in this.lf)) { |
|
this.lf[collectionName] = _localforage["default"].createInstance({ |
|
driver: _localforage["default"].INDEXEDDB, |
|
name: dbName, |
|
storeName: collectionName |
|
}); |
|
} |
|
|
|
return this; |
|
} |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{"localforage":20}],15:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = doc; |
|
|
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
|
|
|
function doc(docSelectionCriteria) { |
|
if (!docSelectionCriteria) { |
|
this.userErrors.push('No document criteria specified in doc() method. Use a string (with a key) or an object (with criteria) e.g. { id: 1 }'); |
|
} else if (typeof docSelectionCriteria !== 'string' && _typeof(docSelectionCriteria) !== 'object') { |
|
this.userErrors.push('Document criteria specified in doc() method must not be a number or boolean. Use a string (with a key) or an object (with criteria) e.g. { id: 1 }'); |
|
} else { |
|
this.docSelectionCriteria = docSelectionCriteria; |
|
} |
|
|
|
return this; |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{}],16:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = void 0; |
|
|
|
var _collection = _interopRequireDefault(require("./api/selectors/collection")); |
|
|
|
var _doc = _interopRequireDefault(require("./api/selectors/doc")); |
|
|
|
var _orderBy = _interopRequireDefault(require("./api/filters/orderBy")); |
|
|
|
var _limit = _interopRequireDefault(require("./api/filters/limit")); |
|
|
|
var _get = _interopRequireDefault(require("./api/actions/get")); |
|
|
|
var _add = _interopRequireDefault(require("./api/actions/add")); |
|
|
|
var _update = _interopRequireDefault(require("./api/actions/update")); |
|
|
|
var _set = _interopRequireDefault(require("./api/actions/set")); |
|
|
|
var _delete = _interopRequireDefault(require("./api/actions/delete")); |
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } |
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
|
|
|
|
var Localbase = function Localbase(dbName) { |
|
_classCallCheck(this, Localbase); |
|
|
|
|
|
this.dbName = dbName; |
|
this.lf = {}; |
|
|
|
this.collectionName = null; |
|
this.orderByProperty = null; |
|
this.orderByDirection = null; |
|
this.limitBy = null; |
|
this.docSelectionCriteria = null; |
|
|
|
this.deleteCollectionQueue = { |
|
queue: [], |
|
running: false |
|
}; |
|
|
|
this.config = { |
|
debug: true |
|
}; |
|
|
|
this.userErrors = []; |
|
|
|
this.collection = _collection["default"].bind(this); |
|
this.doc = _doc["default"].bind(this); |
|
|
|
this.orderBy = _orderBy["default"].bind(this); |
|
this.limit = _limit["default"].bind(this); |
|
|
|
this.get = _get["default"].bind(this); |
|
this.add = _add["default"].bind(this); |
|
this.update = _update["default"].bind(this); |
|
this.set = _set["default"].bind(this); |
|
this["delete"] = _delete["default"].bind(this); |
|
}; |
|
|
|
exports["default"] = Localbase; |
|
module.exports = exports.default; |
|
|
|
},{"./api/actions/add":7,"./api/actions/delete":8,"./api/actions/get":9,"./api/actions/set":10,"./api/actions/update":11,"./api/filters/limit":12,"./api/filters/orderBy":13,"./api/selectors/collection":14,"./api/selectors/doc":15}],17:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = isSubset; |
|
|
|
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } |
|
|
|
function isSubset(superObj, subObj) { |
|
return Object.keys(subObj).every(function (ele) { |
|
if (_typeof(subObj[ele]) == 'object') { |
|
return isSubset(superObj[ele], subObj[ele]); |
|
} |
|
|
|
return subObj[ele] === superObj[ele]; |
|
}); |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{}],18:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = void 0; |
|
var logger = { |
|
baseStyle: "\n padding: 2px 5px;\n background-color: #124F5C;\n border-radius: 4px;\n color: white; \n ", |
|
colors: { |
|
log: '#124F5C', |
|
error: '#ed2939', |
|
warn: '#f39c12' |
|
}, |
|
log: function log(message, secondary) { |
|
if ("development" == 'development' && this.config.debug) { |
|
var style = logger.baseStyle + "background-color: ".concat(logger.colors.log); |
|
|
|
if (secondary) { |
|
console.log('%clocalbase', style, message, secondary); |
|
} else { |
|
console.log('%clocalbase', style, message); |
|
} |
|
} |
|
}, |
|
error: function error(message, secondary) { |
|
if ("development" == 'development' && this.config.debug) { |
|
var style = logger.baseStyle + "background-color: ".concat(logger.colors.error); |
|
console.error('%clocalbase', style, message); |
|
} |
|
}, |
|
warn: function warn(message, secondary) { |
|
if ("development" == 'development' && this.config.debug) { |
|
var style = logger.baseStyle + "background-color: ".concat(logger.colors.warn); |
|
console.warn('%clocalbase', style, message); |
|
} |
|
} |
|
}; |
|
var _default = logger; |
|
exports["default"] = _default; |
|
module.exports = exports.default; |
|
|
|
},{}],19:[function(require,module,exports){ |
|
"use strict"; |
|
|
|
Object.defineProperty(exports, "__esModule", { |
|
value: true |
|
}); |
|
exports["default"] = updateObject; |
|
|
|
function updateObject(obj |
|
|
|
) { |
|
for (var i = 1; i < arguments.length; i++) { |
|
for (var prop in arguments[i]) { |
|
var val = arguments[i][prop]; |
|
|
|
|
|
|
|
|
|
obj[prop] = val; |
|
} |
|
} |
|
|
|
return obj; |
|
} |
|
|
|
module.exports = exports.default; |
|
|
|
},{}],20:[function(require,module,exports){ |
|
(function (global){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.localforage = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw (f.code="MODULE_NOT_FOUND", f)}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ |
|
(function (global){ |
|
'use strict'; |
|
var Mutation = global.MutationObserver || global.WebKitMutationObserver; |
|
|
|
var scheduleDrain; |
|
|
|
{ |
|
if (Mutation) { |
|
var called = 0; |
|
var observer = new Mutation(nextTick); |
|
var element = global.document.createTextNode(''); |
|
observer.observe(element, { |
|
characterData: true |
|
}); |
|
scheduleDrain = function () { |
|
element.data = (called = ++called % 2); |
|
}; |
|
} else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') { |
|
var channel = new global.MessageChannel(); |
|
channel.port1.onmessage = nextTick; |
|
scheduleDrain = function () { |
|
channel.port2.postMessage(0); |
|
}; |
|
} else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) { |
|
scheduleDrain = function () { |
|
|
|
|
|
|
|
var scriptEl = global.document.createElement('script'); |
|
scriptEl.onreadystatechange = function () { |
|
nextTick(); |
|
|
|
scriptEl.onreadystatechange = null; |
|
scriptEl.parentNode.removeChild(scriptEl); |
|
scriptEl = null; |
|
}; |
|
global.document.documentElement.appendChild(scriptEl); |
|
}; |
|
} else { |
|
scheduleDrain = function () { |
|
setTimeout(nextTick, 0); |
|
}; |
|
} |
|
} |
|
|
|
var draining; |
|
var queue = []; |
|
|
|
function nextTick() { |
|
draining = true; |
|
var i, oldQueue; |
|
var len = queue.length; |
|
while (len) { |
|
oldQueue = queue; |
|
queue = []; |
|
i = -1; |
|
while (++i < len) { |
|
oldQueue[i](); |
|
} |
|
len = queue.length; |
|
} |
|
draining = false; |
|
} |
|
|
|
module.exports = immediate; |
|
function immediate(task) { |
|
if (queue.push(task) === 1 && !draining) { |
|
scheduleDrain(); |
|
} |
|
} |
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
|
},{}],2:[function(_dereq_,module,exports){ |
|
'use strict'; |
|
var immediate = _dereq_(1); |
|
|
|
|
|
function INTERNAL() {} |
|
|
|
var handlers = {}; |
|
|
|
var REJECTED = ['REJECTED']; |
|
var FULFILLED = ['FULFILLED']; |
|
var PENDING = ['PENDING']; |
|
|
|
module.exports = Promise; |
|
|
|
function Promise(resolver) { |
|
if (typeof resolver !== 'function') { |
|
throw new TypeError('resolver must be a function'); |
|
} |
|
this.state = PENDING; |
|
this.queue = []; |
|
this.outcome = void 0; |
|
if (resolver !== INTERNAL) { |
|
safelyResolveThenable(this, resolver); |
|
} |
|
} |
|
|
|
Promise.prototype["catch"] = function (onRejected) { |
|
return this.then(null, onRejected); |
|
}; |
|
Promise.prototype.then = function (onFulfilled, onRejected) { |
|
if (typeof onFulfilled !== 'function' && this.state === FULFILLED || |
|
typeof onRejected !== 'function' && this.state === REJECTED) { |
|
return this; |
|
} |
|
var promise = new this.constructor(INTERNAL); |
|
if (this.state !== PENDING) { |
|
var resolver = this.state === FULFILLED ? onFulfilled : onRejected; |
|
unwrap(promise, resolver, this.outcome); |
|
} else { |
|
this.queue.push(new QueueItem(promise, onFulfilled, onRejected)); |
|
} |
|
|
|
return promise; |
|
}; |
|
function QueueItem(promise, onFulfilled, onRejected) { |
|
this.promise = promise; |
|
if (typeof onFulfilled === 'function') { |
|
this.onFulfilled = onFulfilled; |
|
this.callFulfilled = this.otherCallFulfilled; |
|
} |
|
if (typeof onRejected === 'function') { |
|
this.onRejected = onRejected; |
|
this.callRejected = this.otherCallRejected; |
|
} |
|
} |
|
QueueItem.prototype.callFulfilled = function (value) { |
|
handlers.resolve(this.promise, value); |
|
}; |
|
QueueItem.prototype.otherCallFulfilled = function (value) { |
|
unwrap(this.promise, this.onFulfilled, value); |
|
}; |
|
QueueItem.prototype.callRejected = function (value) { |
|
handlers.reject(this.promise, value); |
|
}; |
|
QueueItem.prototype.otherCallRejected = function (value) { |
|
unwrap(this.promise, this.onRejected, value); |
|
}; |
|
|
|
function unwrap(promise, func, value) { |
|
immediate(function () { |
|
var returnValue; |
|
try { |
|
returnValue = func(value); |
|
} catch (e) { |
|
return handlers.reject(promise, e); |
|
} |
|
if (returnValue === promise) { |
|
handlers.reject(promise, new TypeError('Cannot resolve promise with itself')); |
|
} else { |
|
handlers.resolve(promise, returnValue); |
|
} |
|
}); |
|
} |
|
|
|
handlers.resolve = function (self, value) { |
|
var result = tryCatch(getThen, value); |
|
if (result.status === 'error') { |
|
return handlers.reject(self, result.value); |
|
} |
|
var thenable = result.value; |
|
|
|
if (thenable) { |
|
safelyResolveThenable(self, thenable); |
|
} else { |
|
self.state = FULFILLED; |
|
self.outcome = value; |
|
var i = -1; |
|
var len = self.queue.length; |
|
while (++i < len) { |
|
self.queue[i].callFulfilled(value); |
|
} |
|
} |
|
return self; |
|
}; |
|
handlers.reject = function (self, error) { |
|
self.state = REJECTED; |
|
self.outcome = error; |
|
var i = -1; |
|
var len = self.queue.length; |
|
while (++i < len) { |
|
self.queue[i].callRejected(error); |
|
} |
|
return self; |
|
}; |
|
|
|
function getThen(obj) { |
|
|
|
var then = obj && obj.then; |
|
if (obj && (typeof obj === 'object' || typeof obj === 'function') && typeof then === 'function') { |
|
return function appyThen() { |
|
then.apply(obj, arguments); |
|
}; |
|
} |
|
} |
|
|
|
function safelyResolveThenable(self, thenable) { |
|
|
|
var called = false; |
|
function onError(value) { |
|
if (called) { |
|
return; |
|
} |
|
called = true; |
|
handlers.reject(self, value); |
|
} |
|
|
|
function onSuccess(value) { |
|
if (called) { |
|
return; |
|
} |
|
called = true; |
|
handlers.resolve(self, value); |
|
} |
|
|
|
function tryToUnwrap() { |
|
thenable(onSuccess, onError); |
|
} |
|
|
|
var result = tryCatch(tryToUnwrap); |
|
if (result.status === 'error') { |
|
onError(result.value); |
|
} |
|
} |
|
|
|
function tryCatch(func, value) { |
|
var out = {}; |
|
try { |
|
out.value = func(value); |
|
out.status = 'success'; |
|
} catch (e) { |
|
out.status = 'error'; |
|
out.value = e; |
|
} |
|
return out; |
|
} |
|
|
|
Promise.resolve = resolve; |
|
function resolve(value) { |
|
if (value instanceof this) { |
|
return value; |
|
} |
|
return handlers.resolve(new this(INTERNAL), value); |
|
} |
|
|
|
Promise.reject = reject; |
|
function reject(reason) { |
|
var promise = new this(INTERNAL); |
|
return handlers.reject(promise, reason); |
|
} |
|
|
|
Promise.all = all; |
|
function all(iterable) { |
|
var self = this; |
|
if (Object.prototype.toString.call(iterable) !== '[object Array]') { |
|
return this.reject(new TypeError('must be an array')); |
|
} |
|
|
|
var len = iterable.length; |
|
var called = false; |
|
if (!len) { |
|
return this.resolve([]); |
|
} |
|
|
|
var values = new Array(len); |
|
var resolved = 0; |
|
var i = -1; |
|
var promise = new this(INTERNAL); |
|
|
|
while (++i < len) { |
|
allResolver(iterable[i], i); |
|
} |
|
return promise; |
|
function allResolver(value, i) { |
|
self.resolve(value).then(resolveFromAll, function (error) { |
|
if (!called) { |
|
called = true; |
|
handlers.reject(promise, error); |
|
} |
|
}); |
|
function resolveFromAll(outValue) { |
|
values[i] = outValue; |
|
if (++resolved === len && !called) { |
|
called = true; |
|
handlers.resolve(promise, values); |
|
} |
|
} |
|
} |
|
} |
|
|
|
Promise.race = race; |
|
function race(iterable) { |
|
var self = this; |
|
if (Object.prototype.toString.call(iterable) !== '[object Array]') { |
|
return this.reject(new TypeError('must be an array')); |
|
} |
|
|
|
var len = iterable.length; |
|
var called = false; |
|
if (!len) { |
|
return this.resolve([]); |
|
} |
|
|
|
var i = -1; |
|
var promise = new this(INTERNAL); |
|
|
|
while (++i < len) { |
|
resolver(iterable[i]); |
|
} |
|
return promise; |
|
function resolver(value) { |
|
self.resolve(value).then(function (response) { |
|
if (!called) { |
|
called = true; |
|
handlers.resolve(promise, response); |
|
} |
|
}, function (error) { |
|
if (!called) { |
|
called = true; |
|
handlers.reject(promise, error); |
|
} |
|
}); |
|
} |
|
} |
|
|
|
},{"1":1}],3:[function(_dereq_,module,exports){ |
|
(function (global){ |
|
'use strict'; |
|
if (typeof global.Promise !== 'function') { |
|
global.Promise = _dereq_(2); |
|
} |
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
|
},{"2":2}],4:[function(_dereq_,module,exports){ |
|
'use strict'; |
|
|
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; |
|
|
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
|
|
|
function getIDB() { |
|
|
|
try { |
|
if (typeof indexedDB !== 'undefined') { |
|
return indexedDB; |
|
} |
|
if (typeof webkitIndexedDB !== 'undefined') { |
|
return webkitIndexedDB; |
|
} |
|
if (typeof mozIndexedDB !== 'undefined') { |
|
return mozIndexedDB; |
|
} |
|
if (typeof OIndexedDB !== 'undefined') { |
|
return OIndexedDB; |
|
} |
|
if (typeof msIndexedDB !== 'undefined') { |
|
return msIndexedDB; |
|
} |
|
} catch (e) { |
|
return; |
|
} |
|
} |
|
|
|
var idb = getIDB(); |
|
|
|
function isIndexedDBValid() { |
|
try { |
|
|
|
|
|
if (!idb || !idb.open) { |
|
return false; |
|
} |
|
|
|
|
|
|
|
|
|
var isSafari = typeof openDatabase !== 'undefined' && /(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) && !/BlackBerry/.test(navigator.platform); |
|
|
|
var hasFetch = typeof fetch === 'function' && fetch.toString().indexOf('[native code') !== -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (!isSafari || hasFetch) && typeof indexedDB !== 'undefined' && |
|
|
|
|
|
|
|
|
|
typeof IDBKeyRange !== 'undefined'; |
|
} catch (e) { |
|
return false; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createBlob(parts, properties) { |
|
|
|
parts = parts || []; |
|
properties = properties || {}; |
|
try { |
|
return new Blob(parts, properties); |
|
} catch (e) { |
|
if (e.name !== 'TypeError') { |
|
throw e; |
|
} |
|
var Builder = typeof BlobBuilder !== 'undefined' ? BlobBuilder : typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder : typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : WebKitBlobBuilder; |
|
var builder = new Builder(); |
|
for (var i = 0; i < parts.length; i += 1) { |
|
builder.append(parts[i]); |
|
} |
|
return builder.getBlob(properties.type); |
|
} |
|
} |
|
|
|
|
|
|
|
if (typeof Promise === 'undefined') { |
|
|
|
|
|
_dereq_(3); |
|
} |
|
var Promise$1 = Promise; |
|
|
|
function executeCallback(promise, callback) { |
|
if (callback) { |
|
promise.then(function (result) { |
|
callback(null, result); |
|
}, function (error) { |
|
callback(error); |
|
}); |
|
} |
|
} |
|
|
|
function executeTwoCallbacks(promise, callback, errorCallback) { |
|
if (typeof callback === 'function') { |
|
promise.then(callback); |
|
} |
|
|
|
if (typeof errorCallback === 'function') { |
|
promise["catch"](errorCallback); |
|
} |
|
} |
|
|
|
function normalizeKey(key) { |
|
|
|
if (typeof key !== 'string') { |
|
console.warn(key + ' used as a key, but it is not a string.'); |
|
key = String(key); |
|
} |
|
|
|
return key; |
|
} |
|
|
|
function getCallback() { |
|
if (arguments.length && typeof arguments[arguments.length - 1] === 'function') { |
|
return arguments[arguments.length - 1]; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
var DETECT_BLOB_SUPPORT_STORE = 'local-forage-detect-blob-support'; |
|
var supportsBlobs = void 0; |
|
var dbContexts = {}; |
|
var toString = Object.prototype.toString; |
|
|
|
|
|
var READ_ONLY = 'readonly'; |
|
var READ_WRITE = 'readwrite'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
function _binStringToArrayBuffer(bin) { |
|
var length = bin.length; |
|
var buf = new ArrayBuffer(length); |
|
var arr = new Uint8Array(buf); |
|
for (var i = 0; i < length; i++) { |
|
arr[i] = bin.charCodeAt(i); |
|
} |
|
return buf; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function _checkBlobSupportWithoutCaching(idb) { |
|
return new Promise$1(function (resolve) { |
|
var txn = idb.transaction(DETECT_BLOB_SUPPORT_STORE, READ_WRITE); |
|
var blob = createBlob(['']); |
|
txn.objectStore(DETECT_BLOB_SUPPORT_STORE).put(blob, 'key'); |
|
|
|
txn.onabort = function (e) { |
|
|
|
|
|
e.preventDefault(); |
|
e.stopPropagation(); |
|
resolve(false); |
|
}; |
|
|
|
txn.oncomplete = function () { |
|
var matchedChrome = navigator.userAgent.match(/Chrome\/(\d+)/); |
|
var matchedEdge = navigator.userAgent.match(/Edge\//); |
|
|
|
|
|
resolve(matchedEdge || !matchedChrome || parseInt(matchedChrome[1], 10) >= 43); |
|
}; |
|
})["catch"](function () { |
|
return false; |
|
}); |
|
} |
|
|
|
function _checkBlobSupport(idb) { |
|
if (typeof supportsBlobs === 'boolean') { |
|
return Promise$1.resolve(supportsBlobs); |
|
} |
|
return _checkBlobSupportWithoutCaching(idb).then(function (value) { |
|
supportsBlobs = value; |
|
return supportsBlobs; |
|
}); |
|
} |
|
|
|
function _deferReadiness(dbInfo) { |
|
var dbContext = dbContexts[dbInfo.name]; |
|
|
|
|
|
var deferredOperation = {}; |
|
|
|
deferredOperation.promise = new Promise$1(function (resolve, reject) { |
|
deferredOperation.resolve = resolve; |
|
deferredOperation.reject = reject; |
|
}); |
|
|
|
|
|
dbContext.deferredOperations.push(deferredOperation); |
|
|
|
|
|
if (!dbContext.dbReady) { |
|
dbContext.dbReady = deferredOperation.promise; |
|
} else { |
|
dbContext.dbReady = dbContext.dbReady.then(function () { |
|
return deferredOperation.promise; |
|
}); |
|
} |
|
} |
|
|
|
function _advanceReadiness(dbInfo) { |
|
var dbContext = dbContexts[dbInfo.name]; |
|
|
|
|
|
var deferredOperation = dbContext.deferredOperations.pop(); |
|
|
|
|
|
|
|
if (deferredOperation) { |
|
deferredOperation.resolve(); |
|
return deferredOperation.promise; |
|
} |
|
} |
|
|
|
function _rejectReadiness(dbInfo, err) { |
|
var dbContext = dbContexts[dbInfo.name]; |
|
|
|
|
|
var deferredOperation = dbContext.deferredOperations.pop(); |
|
|
|
|
|
|
|
if (deferredOperation) { |
|
deferredOperation.reject(err); |
|
return deferredOperation.promise; |
|
} |
|
} |
|
|
|
function _getConnection(dbInfo, upgradeNeeded) { |
|
return new Promise$1(function (resolve, reject) { |
|
dbContexts[dbInfo.name] = dbContexts[dbInfo.name] || createDbContext(); |
|
|
|
if (dbInfo.db) { |
|
if (upgradeNeeded) { |
|
_deferReadiness(dbInfo); |
|
dbInfo.db.close(); |
|
} else { |
|
return resolve(dbInfo.db); |
|
} |
|
} |
|
|
|
var dbArgs = [dbInfo.name]; |
|
|
|
if (upgradeNeeded) { |
|
dbArgs.push(dbInfo.version); |
|
} |
|
|
|
var openreq = idb.open.apply(idb, dbArgs); |
|
|
|
if (upgradeNeeded) { |
|
openreq.onupgradeneeded = function (e) { |
|
var db = openreq.result; |
|
try { |
|
db.createObjectStore(dbInfo.storeName); |
|
if (e.oldVersion <= 1) { |
|
|
|
db.createObjectStore(DETECT_BLOB_SUPPORT_STORE); |
|
} |
|
} catch (ex) { |
|
if (ex.name === 'ConstraintError') { |
|
console.warn('The database "' + dbInfo.name + '"' + ' has been upgraded from version ' + e.oldVersion + ' to version ' + e.newVersion + ', but the storage "' + dbInfo.storeName + '" already exists.'); |
|
} else { |
|
throw ex; |
|
} |
|
} |
|
}; |
|
} |
|
|
|
openreq.onerror = function (e) { |
|
e.preventDefault(); |
|
reject(openreq.error); |
|
}; |
|
|
|
openreq.onsuccess = function () { |
|
resolve(openreq.result); |
|
_advanceReadiness(dbInfo); |
|
}; |
|
}); |
|
} |
|
|
|
function _getOriginalConnection(dbInfo) { |
|
return _getConnection(dbInfo, false); |
|
} |
|
|
|
function _getUpgradedConnection(dbInfo) { |
|
return _getConnection(dbInfo, true); |
|
} |
|
|
|
function _isUpgradeNeeded(dbInfo, defaultVersion) { |
|
if (!dbInfo.db) { |
|
return true; |
|
} |
|
|
|
var isNewStore = !dbInfo.db.objectStoreNames.contains(dbInfo.storeName); |
|
var isDowngrade = dbInfo.version < dbInfo.db.version; |
|
var isUpgrade = dbInfo.version > dbInfo.db.version; |
|
|
|
if (isDowngrade) { |
|
|
|
|
|
if (dbInfo.version !== defaultVersion) { |
|
console.warn('The database "' + dbInfo.name + '"' + " can't be downgraded from version " + dbInfo.db.version + ' to version ' + dbInfo.version + '.'); |
|
} |
|
|
|
dbInfo.version = dbInfo.db.version; |
|
} |
|
|
|
if (isUpgrade || isNewStore) { |
|
|
|
|
|
|
|
if (isNewStore) { |
|
var incVersion = dbInfo.db.version + 1; |
|
if (incVersion > dbInfo.version) { |
|
dbInfo.version = incVersion; |
|
} |
|
} |
|
|
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
|
|
function _encodeBlob(blob) { |
|
return new Promise$1(function (resolve, reject) { |
|
var reader = new FileReader(); |
|
reader.onerror = reject; |
|
reader.onloadend = function (e) { |
|
var base64 = btoa(e.target.result || ''); |
|
resolve({ |
|
__local_forage_encoded_blob: true, |
|
data: base64, |
|
type: blob.type |
|
}); |
|
}; |
|
reader.readAsBinaryString(blob); |
|
}); |
|
} |
|
|
|
|
|
function _decodeBlob(encodedBlob) { |
|
var arrayBuff = _binStringToArrayBuffer(atob(encodedBlob.data)); |
|
return createBlob([arrayBuff], { type: encodedBlob.type }); |
|
} |
|
|
|
|
|
function _isEncodedBlob(value) { |
|
return value && value.__local_forage_encoded_blob; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function _fullyReady(callback) { |
|
var self = this; |
|
|
|
var promise = self._initReady().then(function () { |
|
var dbContext = dbContexts[self._dbInfo.name]; |
|
|
|
if (dbContext && dbContext.dbReady) { |
|
return dbContext.dbReady; |
|
} |
|
}); |
|
|
|
executeTwoCallbacks(promise, callback, callback); |
|
return promise; |
|
} |
|
|
|
|
|
|
|
|
|
function _tryReconnect(dbInfo) { |
|
_deferReadiness(dbInfo); |
|
|
|
var dbContext = dbContexts[dbInfo.name]; |
|
var forages = dbContext.forages; |
|
|
|
for (var i = 0; i < forages.length; i++) { |
|
var forage = forages[i]; |
|
if (forage._dbInfo.db) { |
|
forage._dbInfo.db.close(); |
|
forage._dbInfo.db = null; |
|
} |
|
} |
|
dbInfo.db = null; |
|
|
|
return _getOriginalConnection(dbInfo).then(function (db) { |
|
dbInfo.db = db; |
|
if (_isUpgradeNeeded(dbInfo)) { |
|
|
|
return _getUpgradedConnection(dbInfo); |
|
} |
|
return db; |
|
}).then(function (db) { |
|
|
|
|
|
dbInfo.db = dbContext.db = db; |
|
for (var i = 0; i < forages.length; i++) { |
|
forages[i]._dbInfo.db = db; |
|
} |
|
})["catch"](function (err) { |
|
_rejectReadiness(dbInfo, err); |
|
throw err; |
|
}); |
|
} |
|
|
|
|
|
|
|
function createTransaction(dbInfo, mode, callback, retries) { |
|
if (retries === undefined) { |
|
retries = 1; |
|
} |
|
|
|
try { |
|
var tx = dbInfo.db.transaction(dbInfo.storeName, mode); |
|
callback(null, tx); |
|
} catch (err) { |
|
if (retries > 0 && (!dbInfo.db || err.name === 'InvalidStateError' || err.name === 'NotFoundError')) { |
|
return Promise$1.resolve().then(function () { |
|
if (!dbInfo.db || err.name === 'NotFoundError' && !dbInfo.db.objectStoreNames.contains(dbInfo.storeName) && dbInfo.version <= dbInfo.db.version) { |
|
|
|
if (dbInfo.db) { |
|
dbInfo.version = dbInfo.db.version + 1; |
|
} |
|
|
|
return _getUpgradedConnection(dbInfo); |
|
} |
|
}).then(function () { |
|
return _tryReconnect(dbInfo).then(function () { |
|
createTransaction(dbInfo, mode, callback, retries - 1); |
|
}); |
|
})["catch"](callback); |
|
} |
|
|
|
callback(err); |
|
} |
|
} |
|
|
|
function createDbContext() { |
|
return { |
|
|
|
forages: [], |
|
|
|
db: null, |
|
|
|
dbReady: null, |
|
|
|
deferredOperations: [] |
|
}; |
|
} |
|
|
|
|
|
|
|
function _initStorage(options) { |
|
var self = this; |
|
var dbInfo = { |
|
db: null |
|
}; |
|
|
|
if (options) { |
|
for (var i in options) { |
|
dbInfo[i] = options[i]; |
|
} |
|
} |
|
|
|
|
|
var dbContext = dbContexts[dbInfo.name]; |
|
|
|
|
|
if (!dbContext) { |
|
dbContext = createDbContext(); |
|
|
|
dbContexts[dbInfo.name] = dbContext; |
|
} |
|
|
|
|
|
dbContext.forages.push(self); |
|
|
|
|
|
if (!self._initReady) { |
|
self._initReady = self.ready; |
|
self.ready = _fullyReady; |
|
} |
|
|
|
|
|
var initPromises = []; |
|
|
|
function ignoreErrors() { |
|
|
|
|
|
return Promise$1.resolve(); |
|
} |
|
|
|
for (var j = 0; j < dbContext.forages.length; j++) { |
|
var forage = dbContext.forages[j]; |
|
if (forage !== self) { |
|
|
|
initPromises.push(forage._initReady()["catch"](ignoreErrors)); |
|
} |
|
} |
|
|
|
|
|
var forages = dbContext.forages.slice(0); |
|
|
|
|
|
|
|
return Promise$1.all(initPromises).then(function () { |
|
dbInfo.db = dbContext.db; |
|
|
|
return _getOriginalConnection(dbInfo); |
|
}).then(function (db) { |
|
dbInfo.db = db; |
|
if (_isUpgradeNeeded(dbInfo, self._defaultConfig.version)) { |
|
|
|
return _getUpgradedConnection(dbInfo); |
|
} |
|
return db; |
|
}).then(function (db) { |
|
dbInfo.db = dbContext.db = db; |
|
self._dbInfo = dbInfo; |
|
|
|
for (var k = 0; k < forages.length; k++) { |
|
var forage = forages[k]; |
|
if (forage !== self) { |
|
|
|
forage._dbInfo.db = dbInfo.db; |
|
forage._dbInfo.version = dbInfo.version; |
|
} |
|
} |
|
}); |
|
} |
|
|
|
function getItem(key, callback) { |
|
var self = this; |
|
|
|
key = normalizeKey(key); |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) { |
|
if (err) { |
|
return reject(err); |
|
} |
|
|
|
try { |
|
var store = transaction.objectStore(self._dbInfo.storeName); |
|
var req = store.get(key); |
|
|
|
req.onsuccess = function () { |
|
var value = req.result; |
|
if (value === undefined) { |
|
value = null; |
|
} |
|
if (_isEncodedBlob(value)) { |
|
value = _decodeBlob(value); |
|
} |
|
resolve(value); |
|
}; |
|
|
|
req.onerror = function () { |
|
reject(req.error); |
|
}; |
|
} catch (e) { |
|
reject(e); |
|
} |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
function iterate(iterator, callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) { |
|
if (err) { |
|
return reject(err); |
|
} |
|
|
|
try { |
|
var store = transaction.objectStore(self._dbInfo.storeName); |
|
var req = store.openCursor(); |
|
var iterationNumber = 1; |
|
|
|
req.onsuccess = function () { |
|
var cursor = req.result; |
|
|
|
if (cursor) { |
|
var value = cursor.value; |
|
if (_isEncodedBlob(value)) { |
|
value = _decodeBlob(value); |
|
} |
|
var result = iterator(value, cursor.key, iterationNumber++); |
|
|
|
|
|
|
|
|
|
if (result !== void 0) { |
|
resolve(result); |
|
} else { |
|
cursor["continue"](); |
|
} |
|
} else { |
|
resolve(); |
|
} |
|
}; |
|
|
|
req.onerror = function () { |
|
reject(req.error); |
|
}; |
|
} catch (e) { |
|
reject(e); |
|
} |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
|
|
return promise; |
|
} |
|
|
|
function setItem(key, value, callback) { |
|
var self = this; |
|
|
|
key = normalizeKey(key); |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
var dbInfo; |
|
self.ready().then(function () { |
|
dbInfo = self._dbInfo; |
|
if (toString.call(value) === '[object Blob]') { |
|
return _checkBlobSupport(dbInfo.db).then(function (blobSupport) { |
|
if (blobSupport) { |
|
return value; |
|
} |
|
return _encodeBlob(value); |
|
}); |
|
} |
|
return value; |
|
}).then(function (value) { |
|
createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) { |
|
if (err) { |
|
return reject(err); |
|
} |
|
|
|
try { |
|
var store = transaction.objectStore(self._dbInfo.storeName); |
|
|
|
|
|
|
|
|
|
|
|
if (value === null) { |
|
value = undefined; |
|
} |
|
|
|
var req = store.put(value, key); |
|
|
|
transaction.oncomplete = function () { |
|
|
|
|
|
|
|
|
|
|
|
|
|
if (value === undefined) { |
|
value = null; |
|
} |
|
|
|
resolve(value); |
|
}; |
|
transaction.onabort = transaction.onerror = function () { |
|
var err = req.error ? req.error : req.transaction.error; |
|
reject(err); |
|
}; |
|
} catch (e) { |
|
reject(e); |
|
} |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function removeItem(key, callback) { |
|
var self = this; |
|
|
|
key = normalizeKey(key); |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) { |
|
if (err) { |
|
return reject(err); |
|
} |
|
|
|
try { |
|
var store = transaction.objectStore(self._dbInfo.storeName); |
|
|
|
|
|
|
|
|
|
|
|
var req = store["delete"](key); |
|
transaction.oncomplete = function () { |
|
resolve(); |
|
}; |
|
|
|
transaction.onerror = function () { |
|
reject(req.error); |
|
}; |
|
|
|
|
|
|
|
transaction.onabort = function () { |
|
var err = req.error ? req.error : req.transaction.error; |
|
reject(err); |
|
}; |
|
} catch (e) { |
|
reject(e); |
|
} |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function clear(callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) { |
|
if (err) { |
|
return reject(err); |
|
} |
|
|
|
try { |
|
var store = transaction.objectStore(self._dbInfo.storeName); |
|
var req = store.clear(); |
|
|
|
transaction.oncomplete = function () { |
|
resolve(); |
|
}; |
|
|
|
transaction.onabort = transaction.onerror = function () { |
|
var err = req.error ? req.error : req.transaction.error; |
|
reject(err); |
|
}; |
|
} catch (e) { |
|
reject(e); |
|
} |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function length(callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) { |
|
if (err) { |
|
return reject(err); |
|
} |
|
|
|
try { |
|
var store = transaction.objectStore(self._dbInfo.storeName); |
|
var req = store.count(); |
|
|
|
req.onsuccess = function () { |
|
resolve(req.result); |
|
}; |
|
|
|
req.onerror = function () { |
|
reject(req.error); |
|
}; |
|
} catch (e) { |
|
reject(e); |
|
} |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function key(n, callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
if (n < 0) { |
|
resolve(null); |
|
|
|
return; |
|
} |
|
|
|
self.ready().then(function () { |
|
createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) { |
|
if (err) { |
|
return reject(err); |
|
} |
|
|
|
try { |
|
var store = transaction.objectStore(self._dbInfo.storeName); |
|
var advanced = false; |
|
var req = store.openKeyCursor(); |
|
|
|
req.onsuccess = function () { |
|
var cursor = req.result; |
|
if (!cursor) { |
|
|
|
resolve(null); |
|
|
|
return; |
|
} |
|
|
|
if (n === 0) { |
|
|
|
|
|
resolve(cursor.key); |
|
} else { |
|
if (!advanced) { |
|
|
|
|
|
advanced = true; |
|
cursor.advance(n); |
|
} else { |
|
|
|
resolve(cursor.key); |
|
} |
|
} |
|
}; |
|
|
|
req.onerror = function () { |
|
reject(req.error); |
|
}; |
|
} catch (e) { |
|
reject(e); |
|
} |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function keys(callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) { |
|
if (err) { |
|
return reject(err); |
|
} |
|
|
|
try { |
|
var store = transaction.objectStore(self._dbInfo.storeName); |
|
var req = store.openKeyCursor(); |
|
var keys = []; |
|
|
|
req.onsuccess = function () { |
|
var cursor = req.result; |
|
|
|
if (!cursor) { |
|
resolve(keys); |
|
return; |
|
} |
|
|
|
keys.push(cursor.key); |
|
cursor["continue"](); |
|
}; |
|
|
|
req.onerror = function () { |
|
reject(req.error); |
|
}; |
|
} catch (e) { |
|
reject(e); |
|
} |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function dropInstance(options, callback) { |
|
callback = getCallback.apply(this, arguments); |
|
|
|
var currentConfig = this.config(); |
|
options = typeof options !== 'function' && options || {}; |
|
if (!options.name) { |
|
options.name = options.name || currentConfig.name; |
|
options.storeName = options.storeName || currentConfig.storeName; |
|
} |
|
|
|
var self = this; |
|
var promise; |
|
if (!options.name) { |
|
promise = Promise$1.reject('Invalid arguments'); |
|
} else { |
|
var isCurrentDb = options.name === currentConfig.name && self._dbInfo.db; |
|
|
|
var dbPromise = isCurrentDb ? Promise$1.resolve(self._dbInfo.db) : _getOriginalConnection(options).then(function (db) { |
|
var dbContext = dbContexts[options.name]; |
|
var forages = dbContext.forages; |
|
dbContext.db = db; |
|
for (var i = 0; i < forages.length; i++) { |
|
forages[i]._dbInfo.db = db; |
|
} |
|
return db; |
|
}); |
|
|
|
if (!options.storeName) { |
|
promise = dbPromise.then(function (db) { |
|
_deferReadiness(options); |
|
|
|
var dbContext = dbContexts[options.name]; |
|
var forages = dbContext.forages; |
|
|
|
db.close(); |
|
for (var i = 0; i < forages.length; i++) { |
|
var forage = forages[i]; |
|
forage._dbInfo.db = null; |
|
} |
|
|
|
var dropDBPromise = new Promise$1(function (resolve, reject) { |
|
var req = idb.deleteDatabase(options.name); |
|
|
|
req.onerror = req.onblocked = function (err) { |
|
var db = req.result; |
|
if (db) { |
|
db.close(); |
|
} |
|
reject(err); |
|
}; |
|
|
|
req.onsuccess = function () { |
|
var db = req.result; |
|
if (db) { |
|
db.close(); |
|
} |
|
resolve(db); |
|
}; |
|
}); |
|
|
|
return dropDBPromise.then(function (db) { |
|
dbContext.db = db; |
|
for (var i = 0; i < forages.length; i++) { |
|
var _forage = forages[i]; |
|
_advanceReadiness(_forage._dbInfo); |
|
} |
|
})["catch"](function (err) { |
|
(_rejectReadiness(options, err) || Promise$1.resolve())["catch"](function () {}); |
|
throw err; |
|
}); |
|
}); |
|
} else { |
|
promise = dbPromise.then(function (db) { |
|
if (!db.objectStoreNames.contains(options.storeName)) { |
|
return; |
|
} |
|
|
|
var newVersion = db.version + 1; |
|
|
|
_deferReadiness(options); |
|
|
|
var dbContext = dbContexts[options.name]; |
|
var forages = dbContext.forages; |
|
|
|
db.close(); |
|
for (var i = 0; i < forages.length; i++) { |
|
var forage = forages[i]; |
|
forage._dbInfo.db = null; |
|
forage._dbInfo.version = newVersion; |
|
} |
|
|
|
var dropObjectPromise = new Promise$1(function (resolve, reject) { |
|
var req = idb.open(options.name, newVersion); |
|
|
|
req.onerror = function (err) { |
|
var db = req.result; |
|
db.close(); |
|
reject(err); |
|
}; |
|
|
|
req.onupgradeneeded = function () { |
|
var db = req.result; |
|
db.deleteObjectStore(options.storeName); |
|
}; |
|
|
|
req.onsuccess = function () { |
|
var db = req.result; |
|
db.close(); |
|
resolve(db); |
|
}; |
|
}); |
|
|
|
return dropObjectPromise.then(function (db) { |
|
dbContext.db = db; |
|
for (var j = 0; j < forages.length; j++) { |
|
var _forage2 = forages[j]; |
|
_forage2._dbInfo.db = db; |
|
_advanceReadiness(_forage2._dbInfo); |
|
} |
|
})["catch"](function (err) { |
|
(_rejectReadiness(options, err) || Promise$1.resolve())["catch"](function () {}); |
|
throw err; |
|
}); |
|
}); |
|
} |
|
} |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
var asyncStorage = { |
|
_driver: 'asyncStorage', |
|
_initStorage: _initStorage, |
|
_support: isIndexedDBValid(), |
|
iterate: iterate, |
|
getItem: getItem, |
|
setItem: setItem, |
|
removeItem: removeItem, |
|
clear: clear, |
|
length: length, |
|
key: key, |
|
keys: keys, |
|
dropInstance: dropInstance |
|
}; |
|
|
|
function isWebSQLValid() { |
|
return typeof openDatabase === 'function'; |
|
} |
|
|
|
|
|
|
|
|
|
var BASE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
|
|
var BLOB_TYPE_PREFIX = '~~local_forage_type~'; |
|
var BLOB_TYPE_PREFIX_REGEX = /^~~local_forage_type~([^~]+)~/; |
|
|
|
var SERIALIZED_MARKER = '__lfsc__:'; |
|
var SERIALIZED_MARKER_LENGTH = SERIALIZED_MARKER.length; |
|
|
|
|
|
var TYPE_ARRAYBUFFER = 'arbf'; |
|
var TYPE_BLOB = 'blob'; |
|
var TYPE_INT8ARRAY = 'si08'; |
|
var TYPE_UINT8ARRAY = 'ui08'; |
|
var TYPE_UINT8CLAMPEDARRAY = 'uic8'; |
|
var TYPE_INT16ARRAY = 'si16'; |
|
var TYPE_INT32ARRAY = 'si32'; |
|
var TYPE_UINT16ARRAY = 'ur16'; |
|
var TYPE_UINT32ARRAY = 'ui32'; |
|
var TYPE_FLOAT32ARRAY = 'fl32'; |
|
var TYPE_FLOAT64ARRAY = 'fl64'; |
|
var TYPE_SERIALIZED_MARKER_LENGTH = SERIALIZED_MARKER_LENGTH + TYPE_ARRAYBUFFER.length; |
|
|
|
var toString$1 = Object.prototype.toString; |
|
|
|
function stringToBuffer(serializedString) { |
|
|
|
var bufferLength = serializedString.length * 0.75; |
|
var len = serializedString.length; |
|
var i; |
|
var p = 0; |
|
var encoded1, encoded2, encoded3, encoded4; |
|
|
|
if (serializedString[serializedString.length - 1] === '=') { |
|
bufferLength--; |
|
if (serializedString[serializedString.length - 2] === '=') { |
|
bufferLength--; |
|
} |
|
} |
|
|
|
var buffer = new ArrayBuffer(bufferLength); |
|
var bytes = new Uint8Array(buffer); |
|
|
|
for (i = 0; i < len; i += 4) { |
|
encoded1 = BASE_CHARS.indexOf(serializedString[i]); |
|
encoded2 = BASE_CHARS.indexOf(serializedString[i + 1]); |
|
encoded3 = BASE_CHARS.indexOf(serializedString[i + 2]); |
|
encoded4 = BASE_CHARS.indexOf(serializedString[i + 3]); |
|
|
|
|
|
bytes[p++] = encoded1 << 2 | encoded2 >> 4; |
|
bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2; |
|
bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63; |
|
} |
|
return buffer; |
|
} |
|
|
|
|
|
|
|
function bufferToString(buffer) { |
|
|
|
var bytes = new Uint8Array(buffer); |
|
var base64String = ''; |
|
var i; |
|
|
|
for (i = 0; i < bytes.length; i += 3) { |
|
|
|
base64String += BASE_CHARS[bytes[i] >> 2]; |
|
base64String += BASE_CHARS[(bytes[i] & 3) << 4 | bytes[i + 1] >> 4]; |
|
base64String += BASE_CHARS[(bytes[i + 1] & 15) << 2 | bytes[i + 2] >> 6]; |
|
base64String += BASE_CHARS[bytes[i + 2] & 63]; |
|
} |
|
|
|
if (bytes.length % 3 === 2) { |
|
base64String = base64String.substring(0, base64String.length - 1) + '='; |
|
} else if (bytes.length % 3 === 1) { |
|
base64String = base64String.substring(0, base64String.length - 2) + '=='; |
|
} |
|
|
|
return base64String; |
|
} |
|
|
|
|
|
|
|
|
|
function serialize(value, callback) { |
|
var valueType = ''; |
|
if (value) { |
|
valueType = toString$1.call(value); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (value && (valueType === '[object ArrayBuffer]' || value.buffer && toString$1.call(value.buffer) === '[object ArrayBuffer]')) { |
|
|
|
|
|
var buffer; |
|
var marker = SERIALIZED_MARKER; |
|
|
|
if (value instanceof ArrayBuffer) { |
|
buffer = value; |
|
marker += TYPE_ARRAYBUFFER; |
|
} else { |
|
buffer = value.buffer; |
|
|
|
if (valueType === '[object Int8Array]') { |
|
marker += TYPE_INT8ARRAY; |
|
} else if (valueType === '[object Uint8Array]') { |
|
marker += TYPE_UINT8ARRAY; |
|
} else if (valueType === '[object Uint8ClampedArray]') { |
|
marker += TYPE_UINT8CLAMPEDARRAY; |
|
} else if (valueType === '[object Int16Array]') { |
|
marker += TYPE_INT16ARRAY; |
|
} else if (valueType === '[object Uint16Array]') { |
|
marker += TYPE_UINT16ARRAY; |
|
} else if (valueType === '[object Int32Array]') { |
|
marker += TYPE_INT32ARRAY; |
|
} else if (valueType === '[object Uint32Array]') { |
|
marker += TYPE_UINT32ARRAY; |
|
} else if (valueType === '[object Float32Array]') { |
|
marker += TYPE_FLOAT32ARRAY; |
|
} else if (valueType === '[object Float64Array]') { |
|
marker += TYPE_FLOAT64ARRAY; |
|
} else { |
|
callback(new Error('Failed to get type for BinaryArray')); |
|
} |
|
} |
|
|
|
callback(marker + bufferToString(buffer)); |
|
} else if (valueType === '[object Blob]') { |
|
|
|
var fileReader = new FileReader(); |
|
|
|
fileReader.onload = function () { |
|
|
|
var str = BLOB_TYPE_PREFIX + value.type + '~' + bufferToString(this.result); |
|
|
|
callback(SERIALIZED_MARKER + TYPE_BLOB + str); |
|
}; |
|
|
|
fileReader.readAsArrayBuffer(value); |
|
} else { |
|
try { |
|
callback(JSON.stringify(value)); |
|
} catch (e) { |
|
console.error("Couldn't convert value into a JSON string: ", value); |
|
|
|
callback(null, e); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function deserialize(value) { |
|
|
|
|
|
|
|
if (value.substring(0, SERIALIZED_MARKER_LENGTH) !== SERIALIZED_MARKER) { |
|
return JSON.parse(value); |
|
} |
|
|
|
|
|
|
|
|
|
var serializedString = value.substring(TYPE_SERIALIZED_MARKER_LENGTH); |
|
var type = value.substring(SERIALIZED_MARKER_LENGTH, TYPE_SERIALIZED_MARKER_LENGTH); |
|
|
|
var blobType; |
|
|
|
|
|
if (type === TYPE_BLOB && BLOB_TYPE_PREFIX_REGEX.test(serializedString)) { |
|
var matcher = serializedString.match(BLOB_TYPE_PREFIX_REGEX); |
|
blobType = matcher[1]; |
|
serializedString = serializedString.substring(matcher[0].length); |
|
} |
|
var buffer = stringToBuffer(serializedString); |
|
|
|
|
|
|
|
switch (type) { |
|
case TYPE_ARRAYBUFFER: |
|
return buffer; |
|
case TYPE_BLOB: |
|
return createBlob([buffer], { type: blobType }); |
|
case TYPE_INT8ARRAY: |
|
return new Int8Array(buffer); |
|
case TYPE_UINT8ARRAY: |
|
return new Uint8Array(buffer); |
|
case TYPE_UINT8CLAMPEDARRAY: |
|
return new Uint8ClampedArray(buffer); |
|
case TYPE_INT16ARRAY: |
|
return new Int16Array(buffer); |
|
case TYPE_UINT16ARRAY: |
|
return new Uint16Array(buffer); |
|
case TYPE_INT32ARRAY: |
|
return new Int32Array(buffer); |
|
case TYPE_UINT32ARRAY: |
|
return new Uint32Array(buffer); |
|
case TYPE_FLOAT32ARRAY: |
|
return new Float32Array(buffer); |
|
case TYPE_FLOAT64ARRAY: |
|
return new Float64Array(buffer); |
|
default: |
|
throw new Error('Unkown type: ' + type); |
|
} |
|
} |
|
|
|
var localforageSerializer = { |
|
serialize: serialize, |
|
deserialize: deserialize, |
|
stringToBuffer: stringToBuffer, |
|
bufferToString: bufferToString |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createDbTable(t, dbInfo, callback, errorCallback) { |
|
t.executeSql('CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName + ' ' + '(id INTEGER PRIMARY KEY, key unique, value)', [], callback, errorCallback); |
|
} |
|
|
|
|
|
|
|
function _initStorage$1(options) { |
|
var self = this; |
|
var dbInfo = { |
|
db: null |
|
}; |
|
|
|
if (options) { |
|
for (var i in options) { |
|
dbInfo[i] = typeof options[i] !== 'string' ? options[i].toString() : options[i]; |
|
} |
|
} |
|
|
|
var dbInfoPromise = new Promise$1(function (resolve, reject) { |
|
|
|
|
|
try { |
|
dbInfo.db = openDatabase(dbInfo.name, String(dbInfo.version), dbInfo.description, dbInfo.size); |
|
} catch (e) { |
|
return reject(e); |
|
} |
|
|
|
|
|
dbInfo.db.transaction(function (t) { |
|
createDbTable(t, dbInfo, function () { |
|
self._dbInfo = dbInfo; |
|
resolve(); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}, reject); |
|
}); |
|
|
|
dbInfo.serializer = localforageSerializer; |
|
return dbInfoPromise; |
|
} |
|
|
|
function tryExecuteSql(t, dbInfo, sqlStatement, args, callback, errorCallback) { |
|
t.executeSql(sqlStatement, args, callback, function (t, error) { |
|
if (error.code === error.SYNTAX_ERR) { |
|
t.executeSql('SELECT name FROM sqlite_master ' + "WHERE type='table' AND name = ?", [dbInfo.storeName], function (t, results) { |
|
if (!results.rows.length) { |
|
|
|
|
|
createDbTable(t, dbInfo, function () { |
|
t.executeSql(sqlStatement, args, callback, errorCallback); |
|
}, errorCallback); |
|
} else { |
|
errorCallback(t, error); |
|
} |
|
}, errorCallback); |
|
} else { |
|
errorCallback(t, error); |
|
} |
|
}, errorCallback); |
|
} |
|
|
|
function getItem$1(key, callback) { |
|
var self = this; |
|
|
|
key = normalizeKey(key); |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
dbInfo.db.transaction(function (t) { |
|
tryExecuteSql(t, dbInfo, 'SELECT * FROM ' + dbInfo.storeName + ' WHERE key = ? LIMIT 1', [key], function (t, results) { |
|
var result = results.rows.length ? results.rows.item(0).value : null; |
|
|
|
|
|
|
|
if (result) { |
|
result = dbInfo.serializer.deserialize(result); |
|
} |
|
|
|
resolve(result); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function iterate$1(iterator, callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
|
|
dbInfo.db.transaction(function (t) { |
|
tryExecuteSql(t, dbInfo, 'SELECT * FROM ' + dbInfo.storeName, [], function (t, results) { |
|
var rows = results.rows; |
|
var length = rows.length; |
|
|
|
for (var i = 0; i < length; i++) { |
|
var item = rows.item(i); |
|
var result = item.value; |
|
|
|
|
|
|
|
if (result) { |
|
result = dbInfo.serializer.deserialize(result); |
|
} |
|
|
|
result = iterator(result, item.key, i + 1); |
|
|
|
|
|
|
|
if (result !== void 0) { |
|
resolve(result); |
|
return; |
|
} |
|
} |
|
|
|
resolve(); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function _setItem(key, value, callback, retriesLeft) { |
|
var self = this; |
|
|
|
key = normalizeKey(key); |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
|
|
|
|
|
|
if (value === undefined) { |
|
value = null; |
|
} |
|
|
|
|
|
var originalValue = value; |
|
|
|
var dbInfo = self._dbInfo; |
|
dbInfo.serializer.serialize(value, function (value, error) { |
|
if (error) { |
|
reject(error); |
|
} else { |
|
dbInfo.db.transaction(function (t) { |
|
tryExecuteSql(t, dbInfo, 'INSERT OR REPLACE INTO ' + dbInfo.storeName + ' ' + '(key, value) VALUES (?, ?)', [key, value], function () { |
|
resolve(originalValue); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}, function (sqlError) { |
|
|
|
|
|
if (sqlError.code === sqlError.QUOTA_ERR) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (retriesLeft > 0) { |
|
resolve(_setItem.apply(self, [key, originalValue, callback, retriesLeft - 1])); |
|
return; |
|
} |
|
reject(sqlError); |
|
} |
|
}); |
|
} |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function setItem$1(key, value, callback) { |
|
return _setItem.apply(this, [key, value, callback, 1]); |
|
} |
|
|
|
function removeItem$1(key, callback) { |
|
var self = this; |
|
|
|
key = normalizeKey(key); |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
dbInfo.db.transaction(function (t) { |
|
tryExecuteSql(t, dbInfo, 'DELETE FROM ' + dbInfo.storeName + ' WHERE key = ?', [key], function () { |
|
resolve(); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
|
|
function clear$1(callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
dbInfo.db.transaction(function (t) { |
|
tryExecuteSql(t, dbInfo, 'DELETE FROM ' + dbInfo.storeName, [], function () { |
|
resolve(); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
|
|
function length$1(callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
dbInfo.db.transaction(function (t) { |
|
|
|
tryExecuteSql(t, dbInfo, 'SELECT COUNT(key) as c FROM ' + dbInfo.storeName, [], function (t, results) { |
|
var result = results.rows.item(0).c; |
|
resolve(result); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function key$1(n, callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
dbInfo.db.transaction(function (t) { |
|
tryExecuteSql(t, dbInfo, 'SELECT key FROM ' + dbInfo.storeName + ' WHERE id = ? LIMIT 1', [n + 1], function (t, results) { |
|
var result = results.rows.length ? results.rows.item(0).key : null; |
|
resolve(result); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function keys$1(callback) { |
|
var self = this; |
|
|
|
var promise = new Promise$1(function (resolve, reject) { |
|
self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
dbInfo.db.transaction(function (t) { |
|
tryExecuteSql(t, dbInfo, 'SELECT key FROM ' + dbInfo.storeName, [], function (t, results) { |
|
var keys = []; |
|
|
|
for (var i = 0; i < results.rows.length; i++) { |
|
keys.push(results.rows.item(i).key); |
|
} |
|
|
|
resolve(keys); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}); |
|
})["catch"](reject); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
|
|
function getAllStoreNames(db) { |
|
return new Promise$1(function (resolve, reject) { |
|
db.transaction(function (t) { |
|
t.executeSql('SELECT name FROM sqlite_master ' + "WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'", [], function (t, results) { |
|
var storeNames = []; |
|
|
|
for (var i = 0; i < results.rows.length; i++) { |
|
storeNames.push(results.rows.item(i).name); |
|
} |
|
|
|
resolve({ |
|
db: db, |
|
storeNames: storeNames |
|
}); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}, function (sqlError) { |
|
reject(sqlError); |
|
}); |
|
}); |
|
} |
|
|
|
function dropInstance$1(options, callback) { |
|
callback = getCallback.apply(this, arguments); |
|
|
|
var currentConfig = this.config(); |
|
options = typeof options !== 'function' && options || {}; |
|
if (!options.name) { |
|
options.name = options.name || currentConfig.name; |
|
options.storeName = options.storeName || currentConfig.storeName; |
|
} |
|
|
|
var self = this; |
|
var promise; |
|
if (!options.name) { |
|
promise = Promise$1.reject('Invalid arguments'); |
|
} else { |
|
promise = new Promise$1(function (resolve) { |
|
var db; |
|
if (options.name === currentConfig.name) { |
|
|
|
db = self._dbInfo.db; |
|
} else { |
|
db = openDatabase(options.name, '', '', 0); |
|
} |
|
|
|
if (!options.storeName) { |
|
|
|
resolve(getAllStoreNames(db)); |
|
} else { |
|
resolve({ |
|
db: db, |
|
storeNames: [options.storeName] |
|
}); |
|
} |
|
}).then(function (operationInfo) { |
|
return new Promise$1(function (resolve, reject) { |
|
operationInfo.db.transaction(function (t) { |
|
function dropTable(storeName) { |
|
return new Promise$1(function (resolve, reject) { |
|
t.executeSql('DROP TABLE IF EXISTS ' + storeName, [], function () { |
|
resolve(); |
|
}, function (t, error) { |
|
reject(error); |
|
}); |
|
}); |
|
} |
|
|
|
var operations = []; |
|
for (var i = 0, len = operationInfo.storeNames.length; i < len; i++) { |
|
operations.push(dropTable(operationInfo.storeNames[i])); |
|
} |
|
|
|
Promise$1.all(operations).then(function () { |
|
resolve(); |
|
})["catch"](function (e) { |
|
reject(e); |
|
}); |
|
}, function (sqlError) { |
|
reject(sqlError); |
|
}); |
|
}); |
|
}); |
|
} |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
var webSQLStorage = { |
|
_driver: 'webSQLStorage', |
|
_initStorage: _initStorage$1, |
|
_support: isWebSQLValid(), |
|
iterate: iterate$1, |
|
getItem: getItem$1, |
|
setItem: setItem$1, |
|
removeItem: removeItem$1, |
|
clear: clear$1, |
|
length: length$1, |
|
key: key$1, |
|
keys: keys$1, |
|
dropInstance: dropInstance$1 |
|
}; |
|
|
|
function isLocalStorageValid() { |
|
try { |
|
return typeof localStorage !== 'undefined' && 'setItem' in localStorage && |
|
|
|
!!localStorage.setItem; |
|
} catch (e) { |
|
return false; |
|
} |
|
} |
|
|
|
function _getKeyPrefix(options, defaultConfig) { |
|
var keyPrefix = options.name + '/'; |
|
|
|
if (options.storeName !== defaultConfig.storeName) { |
|
keyPrefix += options.storeName + '/'; |
|
} |
|
return keyPrefix; |
|
} |
|
|
|
|
|
function checkIfLocalStorageThrows() { |
|
var localStorageTestKey = '_localforage_support_test'; |
|
|
|
try { |
|
localStorage.setItem(localStorageTestKey, true); |
|
localStorage.removeItem(localStorageTestKey); |
|
|
|
return false; |
|
} catch (e) { |
|
return true; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function _isLocalStorageUsable() { |
|
return !checkIfLocalStorageThrows() || localStorage.length > 0; |
|
} |
|
|
|
|
|
function _initStorage$2(options) { |
|
var self = this; |
|
var dbInfo = {}; |
|
if (options) { |
|
for (var i in options) { |
|
dbInfo[i] = options[i]; |
|
} |
|
} |
|
|
|
dbInfo.keyPrefix = _getKeyPrefix(options, self._defaultConfig); |
|
|
|
if (!_isLocalStorageUsable()) { |
|
return Promise$1.reject(); |
|
} |
|
|
|
self._dbInfo = dbInfo; |
|
dbInfo.serializer = localforageSerializer; |
|
|
|
return Promise$1.resolve(); |
|
} |
|
|
|
|
|
|
|
function clear$2(callback) { |
|
var self = this; |
|
var promise = self.ready().then(function () { |
|
var keyPrefix = self._dbInfo.keyPrefix; |
|
|
|
for (var i = localStorage.length - 1; i >= 0; i--) { |
|
var key = localStorage.key(i); |
|
|
|
if (key.indexOf(keyPrefix) === 0) { |
|
localStorage.removeItem(key); |
|
} |
|
} |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
|
|
|
|
function getItem$2(key, callback) { |
|
var self = this; |
|
|
|
key = normalizeKey(key); |
|
|
|
var promise = self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
var result = localStorage.getItem(dbInfo.keyPrefix + key); |
|
|
|
|
|
|
|
|
|
|
|
if (result) { |
|
result = dbInfo.serializer.deserialize(result); |
|
} |
|
|
|
return result; |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
function iterate$2(iterator, callback) { |
|
var self = this; |
|
|
|
var promise = self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
var keyPrefix = dbInfo.keyPrefix; |
|
var keyPrefixLength = keyPrefix.length; |
|
var length = localStorage.length; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var iterationNumber = 1; |
|
|
|
for (var i = 0; i < length; i++) { |
|
var key = localStorage.key(i); |
|
if (key.indexOf(keyPrefix) !== 0) { |
|
continue; |
|
} |
|
var value = localStorage.getItem(key); |
|
|
|
|
|
|
|
|
|
|
|
if (value) { |
|
value = dbInfo.serializer.deserialize(value); |
|
} |
|
|
|
value = iterator(value, key.substring(keyPrefixLength), iterationNumber++); |
|
|
|
if (value !== void 0) { |
|
return value; |
|
} |
|
} |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
function key$2(n, callback) { |
|
var self = this; |
|
var promise = self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
var result; |
|
try { |
|
result = localStorage.key(n); |
|
} catch (error) { |
|
result = null; |
|
} |
|
|
|
|
|
if (result) { |
|
result = result.substring(dbInfo.keyPrefix.length); |
|
} |
|
|
|
return result; |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function keys$2(callback) { |
|
var self = this; |
|
var promise = self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
var length = localStorage.length; |
|
var keys = []; |
|
|
|
for (var i = 0; i < length; i++) { |
|
var itemKey = localStorage.key(i); |
|
if (itemKey.indexOf(dbInfo.keyPrefix) === 0) { |
|
keys.push(itemKey.substring(dbInfo.keyPrefix.length)); |
|
} |
|
} |
|
|
|
return keys; |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
function length$2(callback) { |
|
var self = this; |
|
var promise = self.keys().then(function (keys) { |
|
return keys.length; |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
function removeItem$2(key, callback) { |
|
var self = this; |
|
|
|
key = normalizeKey(key); |
|
|
|
var promise = self.ready().then(function () { |
|
var dbInfo = self._dbInfo; |
|
localStorage.removeItem(dbInfo.keyPrefix + key); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
function setItem$2(key, value, callback) { |
|
var self = this; |
|
|
|
key = normalizeKey(key); |
|
|
|
var promise = self.ready().then(function () { |
|
|
|
|
|
if (value === undefined) { |
|
value = null; |
|
} |
|
|
|
|
|
var originalValue = value; |
|
|
|
return new Promise$1(function (resolve, reject) { |
|
var dbInfo = self._dbInfo; |
|
dbInfo.serializer.serialize(value, function (value, error) { |
|
if (error) { |
|
reject(error); |
|
} else { |
|
try { |
|
localStorage.setItem(dbInfo.keyPrefix + key, value); |
|
resolve(originalValue); |
|
} catch (e) { |
|
|
|
|
|
if (e.name === 'QuotaExceededError' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') { |
|
reject(e); |
|
} |
|
reject(e); |
|
} |
|
} |
|
}); |
|
}); |
|
}); |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
function dropInstance$2(options, callback) { |
|
callback = getCallback.apply(this, arguments); |
|
|
|
options = typeof options !== 'function' && options || {}; |
|
if (!options.name) { |
|
var currentConfig = this.config(); |
|
options.name = options.name || currentConfig.name; |
|
options.storeName = options.storeName || currentConfig.storeName; |
|
} |
|
|
|
var self = this; |
|
var promise; |
|
if (!options.name) { |
|
promise = Promise$1.reject('Invalid arguments'); |
|
} else { |
|
promise = new Promise$1(function (resolve) { |
|
if (!options.storeName) { |
|
resolve(options.name + '/'); |
|
} else { |
|
resolve(_getKeyPrefix(options, self._defaultConfig)); |
|
} |
|
}).then(function (keyPrefix) { |
|
for (var i = localStorage.length - 1; i >= 0; i--) { |
|
var key = localStorage.key(i); |
|
|
|
if (key.indexOf(keyPrefix) === 0) { |
|
localStorage.removeItem(key); |
|
} |
|
} |
|
}); |
|
} |
|
|
|
executeCallback(promise, callback); |
|
return promise; |
|
} |
|
|
|
var localStorageWrapper = { |
|
_driver: 'localStorageWrapper', |
|
_initStorage: _initStorage$2, |
|
_support: isLocalStorageValid(), |
|
iterate: iterate$2, |
|
getItem: getItem$2, |
|
setItem: setItem$2, |
|
removeItem: removeItem$2, |
|
clear: clear$2, |
|
length: length$2, |
|
key: key$2, |
|
keys: keys$2, |
|
dropInstance: dropInstance$2 |
|
}; |
|
|
|
var sameValue = function sameValue(x, y) { |
|
return x === y || typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y); |
|
}; |
|
|
|
var includes = function includes(array, searchElement) { |
|
var len = array.length; |
|
var i = 0; |
|
while (i < len) { |
|
if (sameValue(array[i], searchElement)) { |
|
return true; |
|
} |
|
i++; |
|
} |
|
|
|
return false; |
|
}; |
|
|
|
var isArray = Array.isArray || function (arg) { |
|
return Object.prototype.toString.call(arg) === '[object Array]'; |
|
}; |
|
|
|
|
|
|
|
var DefinedDrivers = {}; |
|
|
|
var DriverSupport = {}; |
|
|
|
var DefaultDrivers = { |
|
INDEXEDDB: asyncStorage, |
|
WEBSQL: webSQLStorage, |
|
LOCALSTORAGE: localStorageWrapper |
|
}; |
|
|
|
var DefaultDriverOrder = [DefaultDrivers.INDEXEDDB._driver, DefaultDrivers.WEBSQL._driver, DefaultDrivers.LOCALSTORAGE._driver]; |
|
|
|
var OptionalDriverMethods = ['dropInstance']; |
|
|
|
var LibraryMethods = ['clear', 'getItem', 'iterate', 'key', 'keys', 'length', 'removeItem', 'setItem'].concat(OptionalDriverMethods); |
|
|
|
var DefaultConfig = { |
|
description: '', |
|
driver: DefaultDriverOrder.slice(), |
|
name: 'localforage', |
|
|
|
|
|
size: 4980736, |
|
storeName: 'keyvaluepairs', |
|
version: 1.0 |
|
}; |
|
|
|
function callWhenReady(localForageInstance, libraryMethod) { |
|
localForageInstance[libraryMethod] = function () { |
|
var _args = arguments; |
|
return localForageInstance.ready().then(function () { |
|
return localForageInstance[libraryMethod].apply(localForageInstance, _args); |
|
}); |
|
}; |
|
} |
|
|
|
function extend() { |
|
for (var i = 1; i < arguments.length; i++) { |
|
var arg = arguments[i]; |
|
|
|
if (arg) { |
|
for (var _key in arg) { |
|
if (arg.hasOwnProperty(_key)) { |
|
if (isArray(arg[_key])) { |
|
arguments[0][_key] = arg[_key].slice(); |
|
} else { |
|
arguments[0][_key] = arg[_key]; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
return arguments[0]; |
|
} |
|
|
|
var LocalForage = function () { |
|
function LocalForage(options) { |
|
_classCallCheck(this, LocalForage); |
|
|
|
for (var driverTypeKey in DefaultDrivers) { |
|
if (DefaultDrivers.hasOwnProperty(driverTypeKey)) { |
|
var driver = DefaultDrivers[driverTypeKey]; |
|
var driverName = driver._driver; |
|
this[driverTypeKey] = driverName; |
|
|
|
if (!DefinedDrivers[driverName]) { |
|
|
|
|
|
|
|
this.defineDriver(driver); |
|
} |
|
} |
|
} |
|
|
|
this._defaultConfig = extend({}, DefaultConfig); |
|
this._config = extend({}, this._defaultConfig, options); |
|
this._driverSet = null; |
|
this._initDriver = null; |
|
this._ready = false; |
|
this._dbInfo = null; |
|
|
|
this._wrapLibraryMethodsWithReady(); |
|
this.setDriver(this._config.driver)["catch"](function () {}); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LocalForage.prototype.config = function config(options) { |
|
|
|
|
|
|
|
if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object') { |
|
|
|
|
|
if (this._ready) { |
|
return new Error("Can't call config() after localforage " + 'has been used.'); |
|
} |
|
|
|
for (var i in options) { |
|
if (i === 'storeName') { |
|
options[i] = options[i].replace(/\W/g, '_'); |
|
} |
|
|
|
if (i === 'version' && typeof options[i] !== 'number') { |
|
return new Error('Database version must be a number.'); |
|
} |
|
|
|
this._config[i] = options[i]; |
|
} |
|
|
|
|
|
|
|
if ('driver' in options && options.driver) { |
|
return this.setDriver(this._config.driver); |
|
} |
|
|
|
return true; |
|
} else if (typeof options === 'string') { |
|
return this._config[options]; |
|
} else { |
|
return this._config; |
|
} |
|
}; |
|
|
|
|
|
|
|
|
|
|
|
LocalForage.prototype.defineDriver = function defineDriver(driverObject, callback, errorCallback) { |
|
var promise = new Promise$1(function (resolve, reject) { |
|
try { |
|
var driverName = driverObject._driver; |
|
var complianceError = new Error('Custom driver not compliant; see ' + 'https://mozilla.github.io/localForage/#definedriver'); |
|
|
|
|
|
|
|
if (!driverObject._driver) { |
|
reject(complianceError); |
|
return; |
|
} |
|
|
|
var driverMethods = LibraryMethods.concat('_initStorage'); |
|
for (var i = 0, len = driverMethods.length; i < len; i++) { |
|
var driverMethodName = driverMethods[i]; |
|
|
|
|
|
|
|
var isRequired = !includes(OptionalDriverMethods, driverMethodName); |
|
if ((isRequired || driverObject[driverMethodName]) && typeof driverObject[driverMethodName] !== 'function') { |
|
reject(complianceError); |
|
return; |
|
} |
|
} |
|
|
|
var configureMissingMethods = function configureMissingMethods() { |
|
var methodNotImplementedFactory = function methodNotImplementedFactory(methodName) { |
|
return function () { |
|
var error = new Error('Method ' + methodName + ' is not implemented by the current driver'); |
|
var promise = Promise$1.reject(error); |
|
executeCallback(promise, arguments[arguments.length - 1]); |
|
return promise; |
|
}; |
|
}; |
|
|
|
for (var _i = 0, _len = OptionalDriverMethods.length; _i < _len; _i++) { |
|
var optionalDriverMethod = OptionalDriverMethods[_i]; |
|
if (!driverObject[optionalDriverMethod]) { |
|
driverObject[optionalDriverMethod] = methodNotImplementedFactory(optionalDriverMethod); |
|
} |
|
} |
|
}; |
|
|
|
configureMissingMethods(); |
|
|
|
var setDriverSupport = function setDriverSupport(support) { |
|
if (DefinedDrivers[driverName]) { |
|
console.info('Redefining LocalForage driver: ' + driverName); |
|
} |
|
DefinedDrivers[driverName] = driverObject; |
|
DriverSupport[driverName] = support; |
|
|
|
|
|
|
|
resolve(); |
|
}; |
|
|
|
if ('_support' in driverObject) { |
|
if (driverObject._support && typeof driverObject._support === 'function') { |
|
driverObject._support().then(setDriverSupport, reject); |
|
} else { |
|
setDriverSupport(!!driverObject._support); |
|
} |
|
} else { |
|
setDriverSupport(true); |
|
} |
|
} catch (e) { |
|
reject(e); |
|
} |
|
}); |
|
|
|
executeTwoCallbacks(promise, callback, errorCallback); |
|
return promise; |
|
}; |
|
|
|
LocalForage.prototype.driver = function driver() { |
|
return this._driver || null; |
|
}; |
|
|
|
LocalForage.prototype.getDriver = function getDriver(driverName, callback, errorCallback) { |
|
var getDriverPromise = DefinedDrivers[driverName] ? Promise$1.resolve(DefinedDrivers[driverName]) : Promise$1.reject(new Error('Driver not found.')); |
|
|
|
executeTwoCallbacks(getDriverPromise, callback, errorCallback); |
|
return getDriverPromise; |
|
}; |
|
|
|
LocalForage.prototype.getSerializer = function getSerializer(callback) { |
|
var serializerPromise = Promise$1.resolve(localforageSerializer); |
|
executeTwoCallbacks(serializerPromise, callback); |
|
return serializerPromise; |
|
}; |
|
|
|
LocalForage.prototype.ready = function ready(callback) { |
|
var self = this; |
|
|
|
var promise = self._driverSet.then(function () { |
|
if (self._ready === null) { |
|
self._ready = self._initDriver(); |
|
} |
|
|
|
return self._ready; |
|
}); |
|
|
|
executeTwoCallbacks(promise, callback, callback); |
|
return promise; |
|
}; |
|
|
|
LocalForage.prototype.setDriver = function setDriver(drivers, callback, errorCallback) { |
|
var self = this; |
|
|
|
if (!isArray(drivers)) { |
|
drivers = [drivers]; |
|
} |
|
|
|
var supportedDrivers = this._getSupportedDrivers(drivers); |
|
|
|
function setDriverToConfig() { |
|
self._config.driver = self.driver(); |
|
} |
|
|
|
function extendSelfWithDriver(driver) { |
|
self._extend(driver); |
|
setDriverToConfig(); |
|
|
|
self._ready = self._initStorage(self._config); |
|
return self._ready; |
|
} |
|
|
|
function initDriver(supportedDrivers) { |
|
return function () { |
|
var currentDriverIndex = 0; |
|
|
|
function driverPromiseLoop() { |
|
while (currentDriverIndex < supportedDrivers.length) { |
|
var driverName = supportedDrivers[currentDriverIndex]; |
|
currentDriverIndex++; |
|
|
|
self._dbInfo = null; |
|
self._ready = null; |
|
|
|
return self.getDriver(driverName).then(extendSelfWithDriver)["catch"](driverPromiseLoop); |
|
} |
|
|
|
setDriverToConfig(); |
|
var error = new Error('No available storage method found.'); |
|
self._driverSet = Promise$1.reject(error); |
|
return self._driverSet; |
|
} |
|
|
|
return driverPromiseLoop(); |
|
}; |
|
} |
|
|
|
|
|
|
|
|
|
var oldDriverSetDone = this._driverSet !== null ? this._driverSet["catch"](function () { |
|
return Promise$1.resolve(); |
|
}) : Promise$1.resolve(); |
|
|
|
this._driverSet = oldDriverSetDone.then(function () { |
|
var driverName = supportedDrivers[0]; |
|
self._dbInfo = null; |
|
self._ready = null; |
|
|
|
return self.getDriver(driverName).then(function (driver) { |
|
self._driver = driver._driver; |
|
setDriverToConfig(); |
|
self._wrapLibraryMethodsWithReady(); |
|
self._initDriver = initDriver(supportedDrivers); |
|
}); |
|
})["catch"](function () { |
|
setDriverToConfig(); |
|
var error = new Error('No available storage method found.'); |
|
self._driverSet = Promise$1.reject(error); |
|
return self._driverSet; |
|
}); |
|
|
|
executeTwoCallbacks(this._driverSet, callback, errorCallback); |
|
return this._driverSet; |
|
}; |
|
|
|
LocalForage.prototype.supports = function supports(driverName) { |
|
return !!DriverSupport[driverName]; |
|
}; |
|
|
|
LocalForage.prototype._extend = function _extend(libraryMethodsAndProperties) { |
|
extend(this, libraryMethodsAndProperties); |
|
}; |
|
|
|
LocalForage.prototype._getSupportedDrivers = function _getSupportedDrivers(drivers) { |
|
var supportedDrivers = []; |
|
for (var i = 0, len = drivers.length; i < len; i++) { |
|
var driverName = drivers[i]; |
|
if (this.supports(driverName)) { |
|
supportedDrivers.push(driverName); |
|
} |
|
} |
|
return supportedDrivers; |
|
}; |
|
|
|
LocalForage.prototype._wrapLibraryMethodsWithReady = function _wrapLibraryMethodsWithReady() { |
|
|
|
|
|
|
|
|
|
for (var i = 0, len = LibraryMethods.length; i < len; i++) { |
|
callWhenReady(this, LibraryMethods[i]); |
|
} |
|
}; |
|
|
|
LocalForage.prototype.createInstance = function createInstance(options) { |
|
return new LocalForage(options); |
|
}; |
|
|
|
return LocalForage; |
|
}(); |
|
|
|
|
|
|
|
|
|
|
|
var localforage_js = new LocalForage(); |
|
|
|
module.exports = localforage_js; |
|
|
|
},{"3":3}]},{},[4])(4) |
|
}); |
|
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) |
|
},{}],21:[function(require,module,exports){ |
|
(function (Buffer){ |
|
'use strict'; |
|
|
|
var uuid = require('uuid'); |
|
|
|
module.exports = { |
|
generate: function() { |
|
var unordered = uuid.v1(); |
|
return unordered.substr(14, 4) + unordered.substr(9, 4) + unordered.substr(0, 8) + unordered.substr(19, 4) + unordered.substr(24, unordered.length); |
|
}, |
|
|
|
toBinary16: function(orderedUuid) { |
|
return new Buffer(orderedUuid, 'hex'); |
|
}, |
|
|
|
fromBinary16: function(binaryOrderedUuid) { |
|
return binaryOrderedUuid.toString('hex'); |
|
} |
|
}; |
|
|
|
}).call(this,require("buffer").Buffer) |
|
},{"buffer":28,"uuid":22}],22:[function(require,module,exports){ |
|
var v1 = require('./v1'); |
|
var v4 = require('./v4'); |
|
|
|
var uuid = v4; |
|
uuid.v1 = v1; |
|
uuid.v4 = v4; |
|
|
|
module.exports = uuid; |
|
|
|
},{"./v1":25,"./v4":26}],23:[function(require,module,exports){ |
|
|
|
|
|
|
|
|
|
var byteToHex = []; |
|
for (var i = 0; i < 256; ++i) { |
|
byteToHex[i] = (i + 0x100).toString(16).substr(1); |
|
} |
|
|
|
function bytesToUuid(buf, offset) { |
|
var i = offset || 0; |
|
var bth = byteToHex; |
|
|
|
return ([ |
|
bth[buf[i++]], bth[buf[i++]], |
|
bth[buf[i++]], bth[buf[i++]], '-', |
|
bth[buf[i++]], bth[buf[i++]], '-', |
|
bth[buf[i++]], bth[buf[i++]], '-', |
|
bth[buf[i++]], bth[buf[i++]], '-', |
|
bth[buf[i++]], bth[buf[i++]], |
|
bth[buf[i++]], bth[buf[i++]], |
|
bth[buf[i++]], bth[buf[i++]] |
|
]).join(''); |
|
} |
|
|
|
module.exports = bytesToUuid; |
|
|
|
},{}],24:[function(require,module,exports){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) || |
|
(typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto)); |
|
|
|
if (getRandomValues) { |
|
|
|
var rnds8 = new Uint8Array(16); |
|
|
|
module.exports = function whatwgRNG() { |
|
getRandomValues(rnds8); |
|
return rnds8; |
|
}; |
|
} else { |
|
|
|
|
|
|
|
|
|
var rnds = new Array(16); |
|
|
|
module.exports = function mathRNG() { |
|
for (var i = 0, r; i < 16; i++) { |
|
if ((i & 0x03) === 0) r = Math.random() * 0x100000000; |
|
rnds[i] = r >>> ((i & 0x03) << 3) & 0xff; |
|
} |
|
|
|
return rnds; |
|
}; |
|
} |
|
|
|
},{}],25:[function(require,module,exports){ |
|
var rng = require('./lib/rng'); |
|
var bytesToUuid = require('./lib/bytesToUuid'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
var _nodeId; |
|
var _clockseq; |
|
|
|
|
|
var _lastMSecs = 0; |
|
var _lastNSecs = 0; |
|
|
|
|
|
function v1(options, buf, offset) { |
|
var i = buf && offset || 0; |
|
var b = buf || []; |
|
|
|
options = options || {}; |
|
var node = options.node || _nodeId; |
|
var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; |
|
|
|
|
|
|
|
|
|
if (node == null || clockseq == null) { |
|
var seedBytes = rng(); |
|
if (node == null) { |
|
|
|
node = _nodeId = [ |
|
seedBytes[0] | 0x01, |
|
seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5] |
|
]; |
|
} |
|
if (clockseq == null) { |
|
|
|
clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime(); |
|
|
|
|
|
|
|
var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; |
|
|
|
|
|
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000; |
|
|
|
|
|
if (dt < 0 && options.clockseq === undefined) { |
|
clockseq = clockseq + 1 & 0x3fff; |
|
} |
|
|
|
|
|
|
|
if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) { |
|
nsecs = 0; |
|
} |
|
|
|
|
|
if (nsecs >= 10000) { |
|
throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec'); |
|
} |
|
|
|
_lastMSecs = msecs; |
|
_lastNSecs = nsecs; |
|
_clockseq = clockseq; |
|
|
|
|
|
msecs += 12219292800000; |
|
|
|
|
|
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000; |
|
b[i++] = tl >>> 24 & 0xff; |
|
b[i++] = tl >>> 16 & 0xff; |
|
b[i++] = tl >>> 8 & 0xff; |
|
b[i++] = tl & 0xff; |
|
|
|
|
|
var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff; |
|
b[i++] = tmh >>> 8 & 0xff; |
|
b[i++] = tmh & 0xff; |
|
|
|
|
|
b[i++] = tmh >>> 24 & 0xf | 0x10; |
|
b[i++] = tmh >>> 16 & 0xff; |
|
|
|
|
|
b[i++] = clockseq >>> 8 | 0x80; |
|
|
|
|
|
b[i++] = clockseq & 0xff; |
|
|
|
|
|
for (var n = 0; n < 6; ++n) { |
|
b[i + n] = node[n]; |
|
} |
|
|
|
return buf ? buf : bytesToUuid(b); |
|
} |
|
|
|
module.exports = v1; |
|
|
|
},{"./lib/bytesToUuid":23,"./lib/rng":24}],26:[function(require,module,exports){ |
|
var rng = require('./lib/rng'); |
|
var bytesToUuid = require('./lib/bytesToUuid'); |
|
|
|
function v4(options, buf, offset) { |
|
var i = buf && offset || 0; |
|
|
|
if (typeof(options) == 'string') { |
|
buf = options === 'binary' ? new Array(16) : null; |
|
options = null; |
|
} |
|
options = options || {}; |
|
|
|
var rnds = options.random || (options.rng || rng)(); |
|
|
|
|
|
rnds[6] = (rnds[6] & 0x0f) | 0x40; |
|
rnds[8] = (rnds[8] & 0x3f) | 0x80; |
|
|
|
|
|
if (buf) { |
|
for (var ii = 0; ii < 16; ++ii) { |
|
buf[i + ii] = rnds[ii]; |
|
} |
|
} |
|
|
|
return buf || bytesToUuid(rnds); |
|
} |
|
|
|
module.exports = v4; |
|
|
|
},{"./lib/bytesToUuid":23,"./lib/rng":24}],27:[function(require,module,exports){ |
|
'use strict' |
|
|
|
exports.byteLength = byteLength |
|
exports.toByteArray = toByteArray |
|
exports.fromByteArray = fromByteArray |
|
|
|
var lookup = [] |
|
var revLookup = [] |
|
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array |
|
|
|
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' |
|
for (var i = 0, len = code.length; i < len; ++i) { |
|
lookup[i] = code[i] |
|
revLookup[code.charCodeAt(i)] = i |
|
} |
|
|
|
|
|
|
|
revLookup['-'.charCodeAt(0)] = 62 |
|
revLookup['_'.charCodeAt(0)] = 63 |
|
|
|
function getLens (b64) { |
|
var len = b64.length |
|
|
|
if (len % 4 > 0) { |
|
throw new Error('Invalid string. Length must be a multiple of 4') |
|
} |
|
|
|
|
|
|
|
var validLen = b64.indexOf('=') |
|
if (validLen === -1) validLen = len |
|
|
|
var placeHoldersLen = validLen === len |
|
? 0 |
|
: 4 - (validLen % 4) |
|
|
|
return [validLen, placeHoldersLen] |
|
} |
|
|
|
|
|
function byteLength (b64) { |
|
var lens = getLens(b64) |
|
var validLen = lens[0] |
|
var placeHoldersLen = lens[1] |
|
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen |
|
} |
|
|
|
function _byteLength (b64, validLen, placeHoldersLen) { |
|
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen |
|
} |
|
|
|
function toByteArray (b64) { |
|
var tmp |
|
var lens = getLens(b64) |
|
var validLen = lens[0] |
|
var placeHoldersLen = lens[1] |
|
|
|
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)) |
|
|
|
var curByte = 0 |
|
|
|
|
|
var len = placeHoldersLen > 0 |
|
? validLen - 4 |
|
: validLen |
|
|
|
var i |
|
for (i = 0; i < len; i += 4) { |
|
tmp = |
|
(revLookup[b64.charCodeAt(i)] << 18) | |
|
(revLookup[b64.charCodeAt(i + 1)] << 12) | |
|
(revLookup[b64.charCodeAt(i + 2)] << 6) | |
|
revLookup[b64.charCodeAt(i + 3)] |
|
arr[curByte++] = (tmp >> 16) & 0xFF |
|
arr[curByte++] = (tmp >> 8) & 0xFF |
|
arr[curByte++] = tmp & 0xFF |
|
} |
|
|
|
if (placeHoldersLen === 2) { |
|
tmp = |
|
(revLookup[b64.charCodeAt(i)] << 2) | |
|
(revLookup[b64.charCodeAt(i + 1)] >> 4) |
|
arr[curByte++] = tmp & 0xFF |
|
} |
|
|
|
if (placeHoldersLen === 1) { |
|
tmp = |
|
(revLookup[b64.charCodeAt(i)] << 10) | |
|
(revLookup[b64.charCodeAt(i + 1)] << 4) | |
|
(revLookup[b64.charCodeAt(i + 2)] >> 2) |
|
arr[curByte++] = (tmp >> 8) & 0xFF |
|
arr[curByte++] = tmp & 0xFF |
|
} |
|
|
|
return arr |
|
} |
|
|
|
function tripletToBase64 (num) { |
|
return lookup[num >> 18 & 0x3F] + |
|
lookup[num >> 12 & 0x3F] + |
|
lookup[num >> 6 & 0x3F] + |
|
lookup[num & 0x3F] |
|
} |
|
|
|
function encodeChunk (uint8, start, end) { |
|
var tmp |
|
var output = [] |
|
for (var i = start; i < end; i += 3) { |
|
tmp = |
|
((uint8[i] << 16) & 0xFF0000) + |
|
((uint8[i + 1] << 8) & 0xFF00) + |
|
(uint8[i + 2] & 0xFF) |
|
output.push(tripletToBase64(tmp)) |
|
} |
|
return output.join('') |
|
} |
|
|
|
function fromByteArray (uint8) { |
|
var tmp |
|
var len = uint8.length |
|
var extraBytes = len % 3 |
|
var parts = [] |
|
var maxChunkLength = 16383 |
|
|
|
|
|
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { |
|
parts.push(encodeChunk( |
|
uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength) |
|
)) |
|
} |
|
|
|
|
|
if (extraBytes === 1) { |
|
tmp = uint8[len - 1] |
|
parts.push( |
|
lookup[tmp >> 2] + |
|
lookup[(tmp << 4) & 0x3F] + |
|
'==' |
|
) |
|
} else if (extraBytes === 2) { |
|
tmp = (uint8[len - 2] << 8) + uint8[len - 1] |
|
parts.push( |
|
lookup[tmp >> 10] + |
|
lookup[(tmp >> 4) & 0x3F] + |
|
lookup[(tmp << 2) & 0x3F] + |
|
'=' |
|
) |
|
} |
|
|
|
return parts.join('') |
|
} |
|
|
|
},{}],28:[function(require,module,exports){ |
|
(function (Buffer){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
'use strict' |
|
|
|
var base64 = require('base64-js') |
|
var ieee754 = require('ieee754') |
|
|
|
exports.Buffer = Buffer |
|
exports.SlowBuffer = SlowBuffer |
|
exports.INSPECT_MAX_BYTES = 50 |
|
|
|
var K_MAX_LENGTH = 0x7fffffff |
|
exports.kMaxLength = K_MAX_LENGTH |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() |
|
|
|
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && |
|
typeof console.error === 'function') { |
|
console.error( |
|
'This browser lacks typed array (Uint8Array) support which is required by ' + |
|
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' |
|
) |
|
} |
|
|
|
function typedArraySupport () { |
|
|
|
try { |
|
var arr = new Uint8Array(1) |
|
arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } } |
|
return arr.foo() === 42 |
|
} catch (e) { |
|
return false |
|
} |
|
} |
|
|
|
Object.defineProperty(Buffer.prototype, 'parent', { |
|
enumerable: true, |
|
get: function () { |
|
if (!Buffer.isBuffer(this)) return undefined |
|
return this.buffer |
|
} |
|
}) |
|
|
|
Object.defineProperty(Buffer.prototype, 'offset', { |
|
enumerable: true, |
|
get: function () { |
|
if (!Buffer.isBuffer(this)) return undefined |
|
return this.byteOffset |
|
} |
|
}) |
|
|
|
function createBuffer (length) { |
|
if (length > K_MAX_LENGTH) { |
|
throw new RangeError('The value "' + length + '" is invalid for option "size"') |
|
} |
|
|
|
var buf = new Uint8Array(length) |
|
buf.__proto__ = Buffer.prototype |
|
return buf |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Buffer (arg, encodingOrOffset, length) { |
|
|
|
if (typeof arg === 'number') { |
|
if (typeof encodingOrOffset === 'string') { |
|
throw new TypeError( |
|
'The "string" argument must be of type string. Received type number' |
|
) |
|
} |
|
return allocUnsafe(arg) |
|
} |
|
return from(arg, encodingOrOffset, length) |
|
} |
|
|
|
|
|
if (typeof Symbol !== 'undefined' && Symbol.species != null && |
|
Buffer[Symbol.species] === Buffer) { |
|
Object.defineProperty(Buffer, Symbol.species, { |
|
value: null, |
|
configurable: true, |
|
enumerable: false, |
|
writable: false |
|
}) |
|
} |
|
|
|
Buffer.poolSize = 8192 |
|
|
|
function from (value, encodingOrOffset, length) { |
|
if (typeof value === 'string') { |
|
return fromString(value, encodingOrOffset) |
|
} |
|
|
|
if (ArrayBuffer.isView(value)) { |
|
return fromArrayLike(value) |
|
} |
|
|
|
if (value == null) { |
|
throw TypeError( |
|
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + |
|
'or Array-like Object. Received type ' + (typeof value) |
|
) |
|
} |
|
|
|
if (isInstance(value, ArrayBuffer) || |
|
(value && isInstance(value.buffer, ArrayBuffer))) { |
|
return fromArrayBuffer(value, encodingOrOffset, length) |
|
} |
|
|
|
if (typeof value === 'number') { |
|
throw new TypeError( |
|
'The "value" argument must not be of type number. Received type number' |
|
) |
|
} |
|
|
|
var valueOf = value.valueOf && value.valueOf() |
|
if (valueOf != null && valueOf !== value) { |
|
return Buffer.from(valueOf, encodingOrOffset, length) |
|
} |
|
|
|
var b = fromObject(value) |
|
if (b) return b |
|
|
|
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && |
|
typeof value[Symbol.toPrimitive] === 'function') { |
|
return Buffer.from( |
|
value[Symbol.toPrimitive]('string'), encodingOrOffset, length |
|
) |
|
} |
|
|
|
throw new TypeError( |
|
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + |
|
'or Array-like Object. Received type ' + (typeof value) |
|
) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer.from = function (value, encodingOrOffset, length) { |
|
return from(value, encodingOrOffset, length) |
|
} |
|
|
|
|
|
|
|
Buffer.prototype.__proto__ = Uint8Array.prototype |
|
Buffer.__proto__ = Uint8Array |
|
|
|
function assertSize (size) { |
|
if (typeof size !== 'number') { |
|
throw new TypeError('"size" argument must be of type number') |
|
} else if (size < 0) { |
|
throw new RangeError('The value "' + size + '" is invalid for option "size"') |
|
} |
|
} |
|
|
|
function alloc (size, fill, encoding) { |
|
assertSize(size) |
|
if (size <= 0) { |
|
return createBuffer(size) |
|
} |
|
if (fill !== undefined) { |
|
|
|
|
|
|
|
return typeof encoding === 'string' |
|
? createBuffer(size).fill(fill, encoding) |
|
: createBuffer(size).fill(fill) |
|
} |
|
return createBuffer(size) |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Buffer.alloc = function (size, fill, encoding) { |
|
return alloc(size, fill, encoding) |
|
} |
|
|
|
function allocUnsafe (size) { |
|
assertSize(size) |
|
return createBuffer(size < 0 ? 0 : checked(size) | 0) |
|
} |
|
|
|
|
|
|
|
|
|
Buffer.allocUnsafe = function (size) { |
|
return allocUnsafe(size) |
|
} |
|
|
|
|
|
|
|
Buffer.allocUnsafeSlow = function (size) { |
|
return allocUnsafe(size) |
|
} |
|
|
|
function fromString (string, encoding) { |
|
if (typeof encoding !== 'string' || encoding === '') { |
|
encoding = 'utf8' |
|
} |
|
|
|
if (!Buffer.isEncoding(encoding)) { |
|
throw new TypeError('Unknown encoding: ' + encoding) |
|
} |
|
|
|
var length = byteLength(string, encoding) | 0 |
|
var buf = createBuffer(length) |
|
|
|
var actual = buf.write(string, encoding) |
|
|
|
if (actual !== length) { |
|
|
|
|
|
|
|
buf = buf.slice(0, actual) |
|
} |
|
|
|
return buf |
|
} |
|
|
|
function fromArrayLike (array) { |
|
var length = array.length < 0 ? 0 : checked(array.length) | 0 |
|
var buf = createBuffer(length) |
|
for (var i = 0; i < length; i += 1) { |
|
buf[i] = array[i] & 255 |
|
} |
|
return buf |
|
} |
|
|
|
function fromArrayBuffer (array, byteOffset, length) { |
|
if (byteOffset < 0 || array.byteLength < byteOffset) { |
|
throw new RangeError('"offset" is outside of buffer bounds') |
|
} |
|
|
|
if (array.byteLength < byteOffset + (length || 0)) { |
|
throw new RangeError('"length" is outside of buffer bounds') |
|
} |
|
|
|
var buf |
|
if (byteOffset === undefined && length === undefined) { |
|
buf = new Uint8Array(array) |
|
} else if (length === undefined) { |
|
buf = new Uint8Array(array, byteOffset) |
|
} else { |
|
buf = new Uint8Array(array, byteOffset, length) |
|
} |
|
|
|
|
|
buf.__proto__ = Buffer.prototype |
|
return buf |
|
} |
|
|
|
function fromObject (obj) { |
|
if (Buffer.isBuffer(obj)) { |
|
var len = checked(obj.length) | 0 |
|
var buf = createBuffer(len) |
|
|
|
if (buf.length === 0) { |
|
return buf |
|
} |
|
|
|
obj.copy(buf, 0, 0, len) |
|
return buf |
|
} |
|
|
|
if (obj.length !== undefined) { |
|
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { |
|
return createBuffer(0) |
|
} |
|
return fromArrayLike(obj) |
|
} |
|
|
|
if (obj.type === 'Buffer' && Array.isArray(obj.data)) { |
|
return fromArrayLike(obj.data) |
|
} |
|
} |
|
|
|
function checked (length) { |
|
|
|
|
|
if (length >= K_MAX_LENGTH) { |
|
throw new RangeError('Attempt to allocate Buffer larger than maximum ' + |
|
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') |
|
} |
|
return length | 0 |
|
} |
|
|
|
function SlowBuffer (length) { |
|
if (+length != length) { |
|
length = 0 |
|
} |
|
return Buffer.alloc(+length) |
|
} |
|
|
|
Buffer.isBuffer = function isBuffer (b) { |
|
return b != null && b._isBuffer === true && |
|
b !== Buffer.prototype |
|
} |
|
|
|
Buffer.compare = function compare (a, b) { |
|
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength) |
|
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength) |
|
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { |
|
throw new TypeError( |
|
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' |
|
) |
|
} |
|
|
|
if (a === b) return 0 |
|
|
|
var x = a.length |
|
var y = b.length |
|
|
|
for (var i = 0, len = Math.min(x, y); i < len; ++i) { |
|
if (a[i] !== b[i]) { |
|
x = a[i] |
|
y = b[i] |
|
break |
|
} |
|
} |
|
|
|
if (x < y) return -1 |
|
if (y < x) return 1 |
|
return 0 |
|
} |
|
|
|
Buffer.isEncoding = function isEncoding (encoding) { |
|
switch (String(encoding).toLowerCase()) { |
|
case 'hex': |
|
case 'utf8': |
|
case 'utf-8': |
|
case 'ascii': |
|
case 'latin1': |
|
case 'binary': |
|
case 'base64': |
|
case 'ucs2': |
|
case 'ucs-2': |
|
case 'utf16le': |
|
case 'utf-16le': |
|
return true |
|
default: |
|
return false |
|
} |
|
} |
|
|
|
Buffer.concat = function concat (list, length) { |
|
if (!Array.isArray(list)) { |
|
throw new TypeError('"list" argument must be an Array of Buffers') |
|
} |
|
|
|
if (list.length === 0) { |
|
return Buffer.alloc(0) |
|
} |
|
|
|
var i |
|
if (length === undefined) { |
|
length = 0 |
|
for (i = 0; i < list.length; ++i) { |
|
length += list[i].length |
|
} |
|
} |
|
|
|
var buffer = Buffer.allocUnsafe(length) |
|
var pos = 0 |
|
for (i = 0; i < list.length; ++i) { |
|
var buf = list[i] |
|
if (isInstance(buf, Uint8Array)) { |
|
buf = Buffer.from(buf) |
|
} |
|
if (!Buffer.isBuffer(buf)) { |
|
throw new TypeError('"list" argument must be an Array of Buffers') |
|
} |
|
buf.copy(buffer, pos) |
|
pos += buf.length |
|
} |
|
return buffer |
|
} |
|
|
|
function byteLength (string, encoding) { |
|
if (Buffer.isBuffer(string)) { |
|
return string.length |
|
} |
|
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { |
|
return string.byteLength |
|
} |
|
if (typeof string !== 'string') { |
|
throw new TypeError( |
|
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + |
|
'Received type ' + typeof string |
|
) |
|
} |
|
|
|
var len = string.length |
|
var mustMatch = (arguments.length > 2 && arguments[2] === true) |
|
if (!mustMatch && len === 0) return 0 |
|
|
|
|
|
var loweredCase = false |
|
for (;;) { |
|
switch (encoding) { |
|
case 'ascii': |
|
case 'latin1': |
|
case 'binary': |
|
return len |
|
case 'utf8': |
|
case 'utf-8': |
|
return utf8ToBytes(string).length |
|
case 'ucs2': |
|
case 'ucs-2': |
|
case 'utf16le': |
|
case 'utf-16le': |
|
return len * 2 |
|
case 'hex': |
|
return len >>> 1 |
|
case 'base64': |
|
return base64ToBytes(string).length |
|
default: |
|
if (loweredCase) { |
|
return mustMatch ? -1 : utf8ToBytes(string).length |
|
} |
|
encoding = ('' + encoding).toLowerCase() |
|
loweredCase = true |
|
} |
|
} |
|
} |
|
Buffer.byteLength = byteLength |
|
|
|
function slowToString (encoding, start, end) { |
|
var loweredCase = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (start === undefined || start < 0) { |
|
start = 0 |
|
} |
|
|
|
|
|
if (start > this.length) { |
|
return '' |
|
} |
|
|
|
if (end === undefined || end > this.length) { |
|
end = this.length |
|
} |
|
|
|
if (end <= 0) { |
|
return '' |
|
} |
|
|
|
|
|
end >>>= 0 |
|
start >>>= 0 |
|
|
|
if (end <= start) { |
|
return '' |
|
} |
|
|
|
if (!encoding) encoding = 'utf8' |
|
|
|
while (true) { |
|
switch (encoding) { |
|
case 'hex': |
|
return hexSlice(this, start, end) |
|
|
|
case 'utf8': |
|
case 'utf-8': |
|
return utf8Slice(this, start, end) |
|
|
|
case 'ascii': |
|
return asciiSlice(this, start, end) |
|
|
|
case 'latin1': |
|
case 'binary': |
|
return latin1Slice(this, start, end) |
|
|
|
case 'base64': |
|
return base64Slice(this, start, end) |
|
|
|
case 'ucs2': |
|
case 'ucs-2': |
|
case 'utf16le': |
|
case 'utf-16le': |
|
return utf16leSlice(this, start, end) |
|
|
|
default: |
|
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) |
|
encoding = (encoding + '').toLowerCase() |
|
loweredCase = true |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer.prototype._isBuffer = true |
|
|
|
function swap (b, n, m) { |
|
var i = b[n] |
|
b[n] = b[m] |
|
b[m] = i |
|
} |
|
|
|
Buffer.prototype.swap16 = function swap16 () { |
|
var len = this.length |
|
if (len % 2 !== 0) { |
|
throw new RangeError('Buffer size must be a multiple of 16-bits') |
|
} |
|
for (var i = 0; i < len; i += 2) { |
|
swap(this, i, i + 1) |
|
} |
|
return this |
|
} |
|
|
|
Buffer.prototype.swap32 = function swap32 () { |
|
var len = this.length |
|
if (len % 4 !== 0) { |
|
throw new RangeError('Buffer size must be a multiple of 32-bits') |
|
} |
|
for (var i = 0; i < len; i += 4) { |
|
swap(this, i, i + 3) |
|
swap(this, i + 1, i + 2) |
|
} |
|
return this |
|
} |
|
|
|
Buffer.prototype.swap64 = function swap64 () { |
|
var len = this.length |
|
if (len % 8 !== 0) { |
|
throw new RangeError('Buffer size must be a multiple of 64-bits') |
|
} |
|
for (var i = 0; i < len; i += 8) { |
|
swap(this, i, i + 7) |
|
swap(this, i + 1, i + 6) |
|
swap(this, i + 2, i + 5) |
|
swap(this, i + 3, i + 4) |
|
} |
|
return this |
|
} |
|
|
|
Buffer.prototype.toString = function toString () { |
|
var length = this.length |
|
if (length === 0) return '' |
|
if (arguments.length === 0) return utf8Slice(this, 0, length) |
|
return slowToString.apply(this, arguments) |
|
} |
|
|
|
Buffer.prototype.toLocaleString = Buffer.prototype.toString |
|
|
|
Buffer.prototype.equals = function equals (b) { |
|
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') |
|
if (this === b) return true |
|
return Buffer.compare(this, b) === 0 |
|
} |
|
|
|
Buffer.prototype.inspect = function inspect () { |
|
var str = '' |
|
var max = exports.INSPECT_MAX_BYTES |
|
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim() |
|
if (this.length > max) str += ' ... ' |
|
return '<Buffer ' + str + '>' |
|
} |
|
|
|
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { |
|
if (isInstance(target, Uint8Array)) { |
|
target = Buffer.from(target, target.offset, target.byteLength) |
|
} |
|
if (!Buffer.isBuffer(target)) { |
|
throw new TypeError( |
|
'The "target" argument must be one of type Buffer or Uint8Array. ' + |
|
'Received type ' + (typeof target) |
|
) |
|
} |
|
|
|
if (start === undefined) { |
|
start = 0 |
|
} |
|
if (end === undefined) { |
|
end = target ? target.length : 0 |
|
} |
|
if (thisStart === undefined) { |
|
thisStart = 0 |
|
} |
|
if (thisEnd === undefined) { |
|
thisEnd = this.length |
|
} |
|
|
|
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { |
|
throw new RangeError('out of range index') |
|
} |
|
|
|
if (thisStart >= thisEnd && start >= end) { |
|
return 0 |
|
} |
|
if (thisStart >= thisEnd) { |
|
return -1 |
|
} |
|
if (start >= end) { |
|
return 1 |
|
} |
|
|
|
start >>>= 0 |
|
end >>>= 0 |
|
thisStart >>>= 0 |
|
thisEnd >>>= 0 |
|
|
|
if (this === target) return 0 |
|
|
|
var x = thisEnd - thisStart |
|
var y = end - start |
|
var len = Math.min(x, y) |
|
|
|
var thisCopy = this.slice(thisStart, thisEnd) |
|
var targetCopy = target.slice(start, end) |
|
|
|
for (var i = 0; i < len; ++i) { |
|
if (thisCopy[i] !== targetCopy[i]) { |
|
x = thisCopy[i] |
|
y = targetCopy[i] |
|
break |
|
} |
|
} |
|
|
|
if (x < y) return -1 |
|
if (y < x) return 1 |
|
return 0 |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { |
|
|
|
if (buffer.length === 0) return -1 |
|
|
|
|
|
if (typeof byteOffset === 'string') { |
|
encoding = byteOffset |
|
byteOffset = 0 |
|
} else if (byteOffset > 0x7fffffff) { |
|
byteOffset = 0x7fffffff |
|
} else if (byteOffset < -0x80000000) { |
|
byteOffset = -0x80000000 |
|
} |
|
byteOffset = +byteOffset |
|
if (numberIsNaN(byteOffset)) { |
|
|
|
byteOffset = dir ? 0 : (buffer.length - 1) |
|
} |
|
|
|
|
|
if (byteOffset < 0) byteOffset = buffer.length + byteOffset |
|
if (byteOffset >= buffer.length) { |
|
if (dir) return -1 |
|
else byteOffset = buffer.length - 1 |
|
} else if (byteOffset < 0) { |
|
if (dir) byteOffset = 0 |
|
else return -1 |
|
} |
|
|
|
|
|
if (typeof val === 'string') { |
|
val = Buffer.from(val, encoding) |
|
} |
|
|
|
|
|
if (Buffer.isBuffer(val)) { |
|
|
|
if (val.length === 0) { |
|
return -1 |
|
} |
|
return arrayIndexOf(buffer, val, byteOffset, encoding, dir) |
|
} else if (typeof val === 'number') { |
|
val = val & 0xFF |
|
if (typeof Uint8Array.prototype.indexOf === 'function') { |
|
if (dir) { |
|
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) |
|
} else { |
|
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) |
|
} |
|
} |
|
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) |
|
} |
|
|
|
throw new TypeError('val must be string, number or Buffer') |
|
} |
|
|
|
function arrayIndexOf (arr, val, byteOffset, encoding, dir) { |
|
var indexSize = 1 |
|
var arrLength = arr.length |
|
var valLength = val.length |
|
|
|
if (encoding !== undefined) { |
|
encoding = String(encoding).toLowerCase() |
|
if (encoding === 'ucs2' || encoding === 'ucs-2' || |
|
encoding === 'utf16le' || encoding === 'utf-16le') { |
|
if (arr.length < 2 || val.length < 2) { |
|
return -1 |
|
} |
|
indexSize = 2 |
|
arrLength /= 2 |
|
valLength /= 2 |
|
byteOffset /= 2 |
|
} |
|
} |
|
|
|
function read (buf, i) { |
|
if (indexSize === 1) { |
|
return buf[i] |
|
} else { |
|
return buf.readUInt16BE(i * indexSize) |
|
} |
|
} |
|
|
|
var i |
|
if (dir) { |
|
var foundIndex = -1 |
|
for (i = byteOffset; i < arrLength; i++) { |
|
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { |
|
if (foundIndex === -1) foundIndex = i |
|
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize |
|
} else { |
|
if (foundIndex !== -1) i -= i - foundIndex |
|
foundIndex = -1 |
|
} |
|
} |
|
} else { |
|
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength |
|
for (i = byteOffset; i >= 0; i--) { |
|
var found = true |
|
for (var j = 0; j < valLength; j++) { |
|
if (read(arr, i + j) !== read(val, j)) { |
|
found = false |
|
break |
|
} |
|
} |
|
if (found) return i |
|
} |
|
} |
|
|
|
return -1 |
|
} |
|
|
|
Buffer.prototype.includes = function includes (val, byteOffset, encoding) { |
|
return this.indexOf(val, byteOffset, encoding) !== -1 |
|
} |
|
|
|
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { |
|
return bidirectionalIndexOf(this, val, byteOffset, encoding, true) |
|
} |
|
|
|
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { |
|
return bidirectionalIndexOf(this, val, byteOffset, encoding, false) |
|
} |
|
|
|
function hexWrite (buf, string, offset, length) { |
|
offset = Number(offset) || 0 |
|
var remaining = buf.length - offset |
|
if (!length) { |
|
length = remaining |
|
} else { |
|
length = Number(length) |
|
if (length > remaining) { |
|
length = remaining |
|
} |
|
} |
|
|
|
var strLen = string.length |
|
|
|
if (length > strLen / 2) { |
|
length = strLen / 2 |
|
} |
|
for (var i = 0; i < length; ++i) { |
|
var parsed = parseInt(string.substr(i * 2, 2), 16) |
|
if (numberIsNaN(parsed)) return i |
|
buf[offset + i] = parsed |
|
} |
|
return i |
|
} |
|
|
|
function utf8Write (buf, string, offset, length) { |
|
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) |
|
} |
|
|
|
function asciiWrite (buf, string, offset, length) { |
|
return blitBuffer(asciiToBytes(string), buf, offset, length) |
|
} |
|
|
|
function latin1Write (buf, string, offset, length) { |
|
return asciiWrite(buf, string, offset, length) |
|
} |
|
|
|
function base64Write (buf, string, offset, length) { |
|
return blitBuffer(base64ToBytes(string), buf, offset, length) |
|
} |
|
|
|
function ucs2Write (buf, string, offset, length) { |
|
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) |
|
} |
|
|
|
Buffer.prototype.write = function write (string, offset, length, encoding) { |
|
|
|
if (offset === undefined) { |
|
encoding = 'utf8' |
|
length = this.length |
|
offset = 0 |
|
|
|
} else if (length === undefined && typeof offset === 'string') { |
|
encoding = offset |
|
length = this.length |
|
offset = 0 |
|
|
|
} else if (isFinite(offset)) { |
|
offset = offset >>> 0 |
|
if (isFinite(length)) { |
|
length = length >>> 0 |
|
if (encoding === undefined) encoding = 'utf8' |
|
} else { |
|
encoding = length |
|
length = undefined |
|
} |
|
} else { |
|
throw new Error( |
|
'Buffer.write(string, encoding, offset[, length]) is no longer supported' |
|
) |
|
} |
|
|
|
var remaining = this.length - offset |
|
if (length === undefined || length > remaining) length = remaining |
|
|
|
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { |
|
throw new RangeError('Attempt to write outside buffer bounds') |
|
} |
|
|
|
if (!encoding) encoding = 'utf8' |
|
|
|
var loweredCase = false |
|
for (;;) { |
|
switch (encoding) { |
|
case 'hex': |
|
return hexWrite(this, string, offset, length) |
|
|
|
case 'utf8': |
|
case 'utf-8': |
|
return utf8Write(this, string, offset, length) |
|
|
|
case 'ascii': |
|
return asciiWrite(this, string, offset, length) |
|
|
|
case 'latin1': |
|
case 'binary': |
|
return latin1Write(this, string, offset, length) |
|
|
|
case 'base64': |
|
|
|
return base64Write(this, string, offset, length) |
|
|
|
case 'ucs2': |
|
case 'ucs-2': |
|
case 'utf16le': |
|
case 'utf-16le': |
|
return ucs2Write(this, string, offset, length) |
|
|
|
default: |
|
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) |
|
encoding = ('' + encoding).toLowerCase() |
|
loweredCase = true |
|
} |
|
} |
|
} |
|
|
|
Buffer.prototype.toJSON = function toJSON () { |
|
return { |
|
type: 'Buffer', |
|
data: Array.prototype.slice.call(this._arr || this, 0) |
|
} |
|
} |
|
|
|
function base64Slice (buf, start, end) { |
|
if (start === 0 && end === buf.length) { |
|
return base64.fromByteArray(buf) |
|
} else { |
|
return base64.fromByteArray(buf.slice(start, end)) |
|
} |
|
} |
|
|
|
function utf8Slice (buf, start, end) { |
|
end = Math.min(buf.length, end) |
|
var res = [] |
|
|
|
var i = start |
|
while (i < end) { |
|
var firstByte = buf[i] |
|
var codePoint = null |
|
var bytesPerSequence = (firstByte > 0xEF) ? 4 |
|
: (firstByte > 0xDF) ? 3 |
|
: (firstByte > 0xBF) ? 2 |
|
: 1 |
|
|
|
if (i + bytesPerSequence <= end) { |
|
var secondByte, thirdByte, fourthByte, tempCodePoint |
|
|
|
switch (bytesPerSequence) { |
|
case 1: |
|
if (firstByte < 0x80) { |
|
codePoint = firstByte |
|
} |
|
break |
|
case 2: |
|
secondByte = buf[i + 1] |
|
if ((secondByte & 0xC0) === 0x80) { |
|
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) |
|
if (tempCodePoint > 0x7F) { |
|
codePoint = tempCodePoint |
|
} |
|
} |
|
break |
|
case 3: |
|
secondByte = buf[i + 1] |
|
thirdByte = buf[i + 2] |
|
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { |
|
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) |
|
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { |
|
codePoint = tempCodePoint |
|
} |
|
} |
|
break |
|
case 4: |
|
secondByte = buf[i + 1] |
|
thirdByte = buf[i + 2] |
|
fourthByte = buf[i + 3] |
|
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { |
|
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) |
|
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { |
|
codePoint = tempCodePoint |
|
} |
|
} |
|
} |
|
} |
|
|
|
if (codePoint === null) { |
|
|
|
|
|
codePoint = 0xFFFD |
|
bytesPerSequence = 1 |
|
} else if (codePoint > 0xFFFF) { |
|
|
|
codePoint -= 0x10000 |
|
res.push(codePoint >>> 10 & 0x3FF | 0xD800) |
|
codePoint = 0xDC00 | codePoint & 0x3FF |
|
} |
|
|
|
res.push(codePoint) |
|
i += bytesPerSequence |
|
} |
|
|
|
return decodeCodePointsArray(res) |
|
} |
|
|
|
|
|
|
|
|
|
var MAX_ARGUMENTS_LENGTH = 0x1000 |
|
|
|
function decodeCodePointsArray (codePoints) { |
|
var len = codePoints.length |
|
if (len <= MAX_ARGUMENTS_LENGTH) { |
|
return String.fromCharCode.apply(String, codePoints) |
|
} |
|
|
|
|
|
var res = '' |
|
var i = 0 |
|
while (i < len) { |
|
res += String.fromCharCode.apply( |
|
String, |
|
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) |
|
) |
|
} |
|
return res |
|
} |
|
|
|
function asciiSlice (buf, start, end) { |
|
var ret = '' |
|
end = Math.min(buf.length, end) |
|
|
|
for (var i = start; i < end; ++i) { |
|
ret += String.fromCharCode(buf[i] & 0x7F) |
|
} |
|
return ret |
|
} |
|
|
|
function latin1Slice (buf, start, end) { |
|
var ret = '' |
|
end = Math.min(buf.length, end) |
|
|
|
for (var i = start; i < end; ++i) { |
|
ret += String.fromCharCode(buf[i]) |
|
} |
|
return ret |
|
} |
|
|
|
function hexSlice (buf, start, end) { |
|
var len = buf.length |
|
|
|
if (!start || start < 0) start = 0 |
|
if (!end || end < 0 || end > len) end = len |
|
|
|
var out = '' |
|
for (var i = start; i < end; ++i) { |
|
out += toHex(buf[i]) |
|
} |
|
return out |
|
} |
|
|
|
function utf16leSlice (buf, start, end) { |
|
var bytes = buf.slice(start, end) |
|
var res = '' |
|
for (var i = 0; i < bytes.length; i += 2) { |
|
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) |
|
} |
|
return res |
|
} |
|
|
|
Buffer.prototype.slice = function slice (start, end) { |
|
var len = this.length |
|
start = ~~start |
|
end = end === undefined ? len : ~~end |
|
|
|
if (start < 0) { |
|
start += len |
|
if (start < 0) start = 0 |
|
} else if (start > len) { |
|
start = len |
|
} |
|
|
|
if (end < 0) { |
|
end += len |
|
if (end < 0) end = 0 |
|
} else if (end > len) { |
|
end = len |
|
} |
|
|
|
if (end < start) end = start |
|
|
|
var newBuf = this.subarray(start, end) |
|
|
|
newBuf.__proto__ = Buffer.prototype |
|
return newBuf |
|
} |
|
|
|
|
|
|
|
|
|
function checkOffset (offset, ext, length) { |
|
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') |
|
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') |
|
} |
|
|
|
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { |
|
offset = offset >>> 0 |
|
byteLength = byteLength >>> 0 |
|
if (!noAssert) checkOffset(offset, byteLength, this.length) |
|
|
|
var val = this[offset] |
|
var mul = 1 |
|
var i = 0 |
|
while (++i < byteLength && (mul *= 0x100)) { |
|
val += this[offset + i] * mul |
|
} |
|
|
|
return val |
|
} |
|
|
|
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { |
|
offset = offset >>> 0 |
|
byteLength = byteLength >>> 0 |
|
if (!noAssert) { |
|
checkOffset(offset, byteLength, this.length) |
|
} |
|
|
|
var val = this[offset + --byteLength] |
|
var mul = 1 |
|
while (byteLength > 0 && (mul *= 0x100)) { |
|
val += this[offset + --byteLength] * mul |
|
} |
|
|
|
return val |
|
} |
|
|
|
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 1, this.length) |
|
return this[offset] |
|
} |
|
|
|
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 2, this.length) |
|
return this[offset] | (this[offset + 1] << 8) |
|
} |
|
|
|
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 2, this.length) |
|
return (this[offset] << 8) | this[offset + 1] |
|
} |
|
|
|
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 4, this.length) |
|
|
|
return ((this[offset]) | |
|
(this[offset + 1] << 8) | |
|
(this[offset + 2] << 16)) + |
|
(this[offset + 3] * 0x1000000) |
|
} |
|
|
|
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 4, this.length) |
|
|
|
return (this[offset] * 0x1000000) + |
|
((this[offset + 1] << 16) | |
|
(this[offset + 2] << 8) | |
|
this[offset + 3]) |
|
} |
|
|
|
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { |
|
offset = offset >>> 0 |
|
byteLength = byteLength >>> 0 |
|
if (!noAssert) checkOffset(offset, byteLength, this.length) |
|
|
|
var val = this[offset] |
|
var mul = 1 |
|
var i = 0 |
|
while (++i < byteLength && (mul *= 0x100)) { |
|
val += this[offset + i] * mul |
|
} |
|
mul *= 0x80 |
|
|
|
if (val >= mul) val -= Math.pow(2, 8 * byteLength) |
|
|
|
return val |
|
} |
|
|
|
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { |
|
offset = offset >>> 0 |
|
byteLength = byteLength >>> 0 |
|
if (!noAssert) checkOffset(offset, byteLength, this.length) |
|
|
|
var i = byteLength |
|
var mul = 1 |
|
var val = this[offset + --i] |
|
while (i > 0 && (mul *= 0x100)) { |
|
val += this[offset + --i] * mul |
|
} |
|
mul *= 0x80 |
|
|
|
if (val >= mul) val -= Math.pow(2, 8 * byteLength) |
|
|
|
return val |
|
} |
|
|
|
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 1, this.length) |
|
if (!(this[offset] & 0x80)) return (this[offset]) |
|
return ((0xff - this[offset] + 1) * -1) |
|
} |
|
|
|
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 2, this.length) |
|
var val = this[offset] | (this[offset + 1] << 8) |
|
return (val & 0x8000) ? val | 0xFFFF0000 : val |
|
} |
|
|
|
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 2, this.length) |
|
var val = this[offset + 1] | (this[offset] << 8) |
|
return (val & 0x8000) ? val | 0xFFFF0000 : val |
|
} |
|
|
|
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 4, this.length) |
|
|
|
return (this[offset]) | |
|
(this[offset + 1] << 8) | |
|
(this[offset + 2] << 16) | |
|
(this[offset + 3] << 24) |
|
} |
|
|
|
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 4, this.length) |
|
|
|
return (this[offset] << 24) | |
|
(this[offset + 1] << 16) | |
|
(this[offset + 2] << 8) | |
|
(this[offset + 3]) |
|
} |
|
|
|
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 4, this.length) |
|
return ieee754.read(this, offset, true, 23, 4) |
|
} |
|
|
|
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 4, this.length) |
|
return ieee754.read(this, offset, false, 23, 4) |
|
} |
|
|
|
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 8, this.length) |
|
return ieee754.read(this, offset, true, 52, 8) |
|
} |
|
|
|
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { |
|
offset = offset >>> 0 |
|
if (!noAssert) checkOffset(offset, 8, this.length) |
|
return ieee754.read(this, offset, false, 52, 8) |
|
} |
|
|
|
function checkInt (buf, value, offset, ext, max, min) { |
|
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') |
|
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') |
|
if (offset + ext > buf.length) throw new RangeError('Index out of range') |
|
} |
|
|
|
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
byteLength = byteLength >>> 0 |
|
if (!noAssert) { |
|
var maxBytes = Math.pow(2, 8 * byteLength) - 1 |
|
checkInt(this, value, offset, byteLength, maxBytes, 0) |
|
} |
|
|
|
var mul = 1 |
|
var i = 0 |
|
this[offset] = value & 0xFF |
|
while (++i < byteLength && (mul *= 0x100)) { |
|
this[offset + i] = (value / mul) & 0xFF |
|
} |
|
|
|
return offset + byteLength |
|
} |
|
|
|
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
byteLength = byteLength >>> 0 |
|
if (!noAssert) { |
|
var maxBytes = Math.pow(2, 8 * byteLength) - 1 |
|
checkInt(this, value, offset, byteLength, maxBytes, 0) |
|
} |
|
|
|
var i = byteLength - 1 |
|
var mul = 1 |
|
this[offset + i] = value & 0xFF |
|
while (--i >= 0 && (mul *= 0x100)) { |
|
this[offset + i] = (value / mul) & 0xFF |
|
} |
|
|
|
return offset + byteLength |
|
} |
|
|
|
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) |
|
this[offset] = (value & 0xff) |
|
return offset + 1 |
|
} |
|
|
|
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) |
|
this[offset] = (value & 0xff) |
|
this[offset + 1] = (value >>> 8) |
|
return offset + 2 |
|
} |
|
|
|
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) |
|
this[offset] = (value >>> 8) |
|
this[offset + 1] = (value & 0xff) |
|
return offset + 2 |
|
} |
|
|
|
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) |
|
this[offset + 3] = (value >>> 24) |
|
this[offset + 2] = (value >>> 16) |
|
this[offset + 1] = (value >>> 8) |
|
this[offset] = (value & 0xff) |
|
return offset + 4 |
|
} |
|
|
|
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) |
|
this[offset] = (value >>> 24) |
|
this[offset + 1] = (value >>> 16) |
|
this[offset + 2] = (value >>> 8) |
|
this[offset + 3] = (value & 0xff) |
|
return offset + 4 |
|
} |
|
|
|
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) { |
|
var limit = Math.pow(2, (8 * byteLength) - 1) |
|
|
|
checkInt(this, value, offset, byteLength, limit - 1, -limit) |
|
} |
|
|
|
var i = 0 |
|
var mul = 1 |
|
var sub = 0 |
|
this[offset] = value & 0xFF |
|
while (++i < byteLength && (mul *= 0x100)) { |
|
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { |
|
sub = 1 |
|
} |
|
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF |
|
} |
|
|
|
return offset + byteLength |
|
} |
|
|
|
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) { |
|
var limit = Math.pow(2, (8 * byteLength) - 1) |
|
|
|
checkInt(this, value, offset, byteLength, limit - 1, -limit) |
|
} |
|
|
|
var i = byteLength - 1 |
|
var mul = 1 |
|
var sub = 0 |
|
this[offset + i] = value & 0xFF |
|
while (--i >= 0 && (mul *= 0x100)) { |
|
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { |
|
sub = 1 |
|
} |
|
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF |
|
} |
|
|
|
return offset + byteLength |
|
} |
|
|
|
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) |
|
if (value < 0) value = 0xff + value + 1 |
|
this[offset] = (value & 0xff) |
|
return offset + 1 |
|
} |
|
|
|
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) |
|
this[offset] = (value & 0xff) |
|
this[offset + 1] = (value >>> 8) |
|
return offset + 2 |
|
} |
|
|
|
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) |
|
this[offset] = (value >>> 8) |
|
this[offset + 1] = (value & 0xff) |
|
return offset + 2 |
|
} |
|
|
|
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) |
|
this[offset] = (value & 0xff) |
|
this[offset + 1] = (value >>> 8) |
|
this[offset + 2] = (value >>> 16) |
|
this[offset + 3] = (value >>> 24) |
|
return offset + 4 |
|
} |
|
|
|
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) |
|
if (value < 0) value = 0xffffffff + value + 1 |
|
this[offset] = (value >>> 24) |
|
this[offset + 1] = (value >>> 16) |
|
this[offset + 2] = (value >>> 8) |
|
this[offset + 3] = (value & 0xff) |
|
return offset + 4 |
|
} |
|
|
|
function checkIEEE754 (buf, value, offset, ext, max, min) { |
|
if (offset + ext > buf.length) throw new RangeError('Index out of range') |
|
if (offset < 0) throw new RangeError('Index out of range') |
|
} |
|
|
|
function writeFloat (buf, value, offset, littleEndian, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) { |
|
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) |
|
} |
|
ieee754.write(buf, value, offset, littleEndian, 23, 4) |
|
return offset + 4 |
|
} |
|
|
|
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { |
|
return writeFloat(this, value, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { |
|
return writeFloat(this, value, offset, false, noAssert) |
|
} |
|
|
|
function writeDouble (buf, value, offset, littleEndian, noAssert) { |
|
value = +value |
|
offset = offset >>> 0 |
|
if (!noAssert) { |
|
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) |
|
} |
|
ieee754.write(buf, value, offset, littleEndian, 52, 8) |
|
return offset + 8 |
|
} |
|
|
|
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { |
|
return writeDouble(this, value, offset, true, noAssert) |
|
} |
|
|
|
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { |
|
return writeDouble(this, value, offset, false, noAssert) |
|
} |
|
|
|
|
|
Buffer.prototype.copy = function copy (target, targetStart, start, end) { |
|
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer') |
|
if (!start) start = 0 |
|
if (!end && end !== 0) end = this.length |
|
if (targetStart >= target.length) targetStart = target.length |
|
if (!targetStart) targetStart = 0 |
|
if (end > 0 && end < start) end = start |
|
|
|
|
|
if (end === start) return 0 |
|
if (target.length === 0 || this.length === 0) return 0 |
|
|
|
|
|
if (targetStart < 0) { |
|
throw new RangeError('targetStart out of bounds') |
|
} |
|
if (start < 0 || start >= this.length) throw new RangeError('Index out of range') |
|
if (end < 0) throw new RangeError('sourceEnd out of bounds') |
|
|
|
|
|
if (end > this.length) end = this.length |
|
if (target.length - targetStart < end - start) { |
|
end = target.length - targetStart + start |
|
} |
|
|
|
var len = end - start |
|
|
|
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { |
|
|
|
this.copyWithin(targetStart, start, end) |
|
} else if (this === target && start < targetStart && targetStart < end) { |
|
|
|
for (var i = len - 1; i >= 0; --i) { |
|
target[i + targetStart] = this[i + start] |
|
} |
|
} else { |
|
Uint8Array.prototype.set.call( |
|
target, |
|
this.subarray(start, end), |
|
targetStart |
|
) |
|
} |
|
|
|
return len |
|
} |
|
|
|
|
|
|
|
|
|
|
|
Buffer.prototype.fill = function fill (val, start, end, encoding) { |
|
|
|
if (typeof val === 'string') { |
|
if (typeof start === 'string') { |
|
encoding = start |
|
start = 0 |
|
end = this.length |
|
} else if (typeof end === 'string') { |
|
encoding = end |
|
end = this.length |
|
} |
|
if (encoding !== undefined && typeof encoding !== 'string') { |
|
throw new TypeError('encoding must be a string') |
|
} |
|
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { |
|
throw new TypeError('Unknown encoding: ' + encoding) |
|
} |
|
if (val.length === 1) { |
|
var code = val.charCodeAt(0) |
|
if ((encoding === 'utf8' && code < 128) || |
|
encoding === 'latin1') { |
|
|
|
val = code |
|
} |
|
} |
|
} else if (typeof val === 'number') { |
|
val = val & 255 |
|
} |
|
|
|
|
|
if (start < 0 || this.length < start || this.length < end) { |
|
throw new RangeError('Out of range index') |
|
} |
|
|
|
if (end <= start) { |
|
return this |
|
} |
|
|
|
start = start >>> 0 |
|
end = end === undefined ? this.length : end >>> 0 |
|
|
|
if (!val) val = 0 |
|
|
|
var i |
|
if (typeof val === 'number') { |
|
for (i = start; i < end; ++i) { |
|
this[i] = val |
|
} |
|
} else { |
|
var bytes = Buffer.isBuffer(val) |
|
? val |
|
: Buffer.from(val, encoding) |
|
var len = bytes.length |
|
if (len === 0) { |
|
throw new TypeError('The value "' + val + |
|
'" is invalid for argument "value"') |
|
} |
|
for (i = 0; i < end - start; ++i) { |
|
this[i + start] = bytes[i % len] |
|
} |
|
} |
|
|
|
return this |
|
} |
|
|
|
|
|
|
|
|
|
var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g |
|
|
|
function base64clean (str) { |
|
|
|
str = str.split('=')[0] |
|
|
|
str = str.trim().replace(INVALID_BASE64_RE, '') |
|
|
|
if (str.length < 2) return '' |
|
|
|
while (str.length % 4 !== 0) { |
|
str = str + '=' |
|
} |
|
return str |
|
} |
|
|
|
function toHex (n) { |
|
if (n < 16) return '0' + n.toString(16) |
|
return n.toString(16) |
|
} |
|
|
|
function utf8ToBytes (string, units) { |
|
units = units || Infinity |
|
var codePoint |
|
var length = string.length |
|
var leadSurrogate = null |
|
var bytes = [] |
|
|
|
for (var i = 0; i < length; ++i) { |
|
codePoint = string.charCodeAt(i) |
|
|
|
|
|
if (codePoint > 0xD7FF && codePoint < 0xE000) { |
|
|
|
if (!leadSurrogate) { |
|
|
|
if (codePoint > 0xDBFF) { |
|
|
|
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) |
|
continue |
|
} else if (i + 1 === length) { |
|
|
|
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) |
|
continue |
|
} |
|
|
|
|
|
leadSurrogate = codePoint |
|
|
|
continue |
|
} |
|
|
|
|
|
if (codePoint < 0xDC00) { |
|
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) |
|
leadSurrogate = codePoint |
|
continue |
|
} |
|
|
|
|
|
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 |
|
} else if (leadSurrogate) { |
|
|
|
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) |
|
} |
|
|
|
leadSurrogate = null |
|
|
|
|
|
if (codePoint < 0x80) { |
|
if ((units -= 1) < 0) break |
|
bytes.push(codePoint) |
|
} else if (codePoint < 0x800) { |
|
if ((units -= 2) < 0) break |
|
bytes.push( |
|
codePoint >> 0x6 | 0xC0, |
|
codePoint & 0x3F | 0x80 |
|
) |
|
} else if (codePoint < 0x10000) { |
|
if ((units -= 3) < 0) break |
|
bytes.push( |
|
codePoint >> 0xC | 0xE0, |
|
codePoint >> 0x6 & 0x3F | 0x80, |
|
codePoint & 0x3F | 0x80 |
|
) |
|
} else if (codePoint < 0x110000) { |
|
if ((units -= 4) < 0) break |
|
bytes.push( |
|
codePoint >> 0x12 | 0xF0, |
|
codePoint >> 0xC & 0x3F | 0x80, |
|
codePoint >> 0x6 & 0x3F | 0x80, |
|
codePoint & 0x3F | 0x80 |
|
) |
|
} else { |
|
throw new Error('Invalid code point') |
|
} |
|
} |
|
|
|
return bytes |
|
} |
|
|
|
function asciiToBytes (str) { |
|
var byteArray = [] |
|
for (var i = 0; i < str.length; ++i) { |
|
|
|
byteArray.push(str.charCodeAt(i) & 0xFF) |
|
} |
|
return byteArray |
|
} |
|
|
|
function utf16leToBytes (str, units) { |
|
var c, hi, lo |
|
var byteArray = [] |
|
for (var i = 0; i < str.length; ++i) { |
|
if ((units -= 2) < 0) break |
|
|
|
c = str.charCodeAt(i) |
|
hi = c >> 8 |
|
lo = c % 256 |
|
byteArray.push(lo) |
|
byteArray.push(hi) |
|
} |
|
|
|
return byteArray |
|
} |
|
|
|
function base64ToBytes (str) { |
|
return base64.toByteArray(base64clean(str)) |
|
} |
|
|
|
function blitBuffer (src, dst, offset, length) { |
|
for (var i = 0; i < length; ++i) { |
|
if ((i + offset >= dst.length) || (i >= src.length)) break |
|
dst[i + offset] = src[i] |
|
} |
|
return i |
|
} |
|
|
|
|
|
|
|
|
|
function isInstance (obj, type) { |
|
return obj instanceof type || |
|
(obj != null && obj.constructor != null && obj.constructor.name != null && |
|
obj.constructor.name === type.name) |
|
} |
|
function numberIsNaN (obj) { |
|
|
|
return obj !== obj |
|
} |
|
|
|
}).call(this,require("buffer").Buffer) |
|
},{"base64-js":27,"buffer":28,"ieee754":29}],29:[function(require,module,exports){ |
|
exports.read = function (buffer, offset, isLE, mLen, nBytes) { |
|
var e, m |
|
var eLen = (nBytes * 8) - mLen - 1 |
|
var eMax = (1 << eLen) - 1 |
|
var eBias = eMax >> 1 |
|
var nBits = -7 |
|
var i = isLE ? (nBytes - 1) : 0 |
|
var d = isLE ? -1 : 1 |
|
var s = buffer[offset + i] |
|
|
|
i += d |
|
|
|
e = s & ((1 << (-nBits)) - 1) |
|
s >>= (-nBits) |
|
nBits += eLen |
|
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {} |
|
|
|
m = e & ((1 << (-nBits)) - 1) |
|
e >>= (-nBits) |
|
nBits += mLen |
|
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {} |
|
|
|
if (e === 0) { |
|
e = 1 - eBias |
|
} else if (e === eMax) { |
|
return m ? NaN : ((s ? -1 : 1) * Infinity) |
|
} else { |
|
m = m + Math.pow(2, mLen) |
|
e = e - eBias |
|
} |
|
return (s ? -1 : 1) * m * Math.pow(2, e - mLen) |
|
} |
|
|
|
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { |
|
var e, m, c |
|
var eLen = (nBytes * 8) - mLen - 1 |
|
var eMax = (1 << eLen) - 1 |
|
var eBias = eMax >> 1 |
|
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) |
|
var i = isLE ? 0 : (nBytes - 1) |
|
var d = isLE ? 1 : -1 |
|
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 |
|
|
|
value = Math.abs(value) |
|
|
|
if (isNaN(value) || value === Infinity) { |
|
m = isNaN(value) ? 1 : 0 |
|
e = eMax |
|
} else { |
|
e = Math.floor(Math.log(value) / Math.LN2) |
|
if (value * (c = Math.pow(2, -e)) < 1) { |
|
e-- |
|
c *= 2 |
|
} |
|
if (e + eBias >= 1) { |
|
value += rt / c |
|
} else { |
|
value += rt * Math.pow(2, 1 - eBias) |
|
} |
|
if (value * c >= 2) { |
|
e++ |
|
c /= 2 |
|
} |
|
|
|
if (e + eBias >= eMax) { |
|
m = 0 |
|
e = eMax |
|
} else if (e + eBias >= 1) { |
|
m = ((value * c) - 1) * Math.pow(2, mLen) |
|
e = e + eBias |
|
} else { |
|
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) |
|
e = 0 |
|
} |
|
} |
|
|
|
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} |
|
|
|
e = (e << mLen) | m |
|
eLen += mLen |
|
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} |
|
|
|
buffer[offset + i - d] |= s * 128 |
|
} |
|
|
|
},{}]},{},[1])(1) |
|
}); |
|
|