测试版
This commit is contained in:
12
node_modules/store/plugins/all.js
generated
vendored
Normal file
12
node_modules/store/plugins/all.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
module.exports = [
|
||||
require('./compression'),
|
||||
require('./defaults'),
|
||||
require('./dump'),
|
||||
require('./events'),
|
||||
require('./observe'),
|
||||
require('./expire'),
|
||||
require('./json2'),
|
||||
require('./operations'),
|
||||
require('./update'),
|
||||
require('./v1-backcompat'),
|
||||
]
|
||||
12
node_modules/store/plugins/all_tests.js
generated
vendored
Normal file
12
node_modules/store/plugins/all_tests.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
module.exports = {
|
||||
"compression": require('./compression_test'),
|
||||
"defaults": require('./defaults_test'),
|
||||
"dump": require('./dump_test'),
|
||||
"events": require('./events_test'),
|
||||
"observe": require('./observe_test'),
|
||||
"expire": require('./expire_test'),
|
||||
"json2": require('./json2_test'),
|
||||
"operations": require('./operations_test'),
|
||||
"update": require('./update_test'),
|
||||
"v1-backcompat": require('./v1-backcompat_test'),
|
||||
}
|
||||
23
node_modules/store/plugins/compression.js
generated
vendored
Normal file
23
node_modules/store/plugins/compression.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
const LZString = require('./lib/lz-string')
|
||||
|
||||
module.exports = compressionPlugin
|
||||
|
||||
function compressionPlugin() {
|
||||
return {
|
||||
get: get,
|
||||
set: set,
|
||||
}
|
||||
|
||||
function get(super_fn, key) {
|
||||
var val = super_fn(key)
|
||||
if (!val) { return val }
|
||||
var decompressed = LZString.decompress(val)
|
||||
// fallback to existing values that are not compressed
|
||||
return (decompressed == null) ? val : this._deserialize(decompressed)
|
||||
}
|
||||
|
||||
function set(super_fn, key, val) {
|
||||
var compressed = LZString.compress(this._serialize(val))
|
||||
super_fn(key, compressed)
|
||||
}
|
||||
}
|
||||
37
node_modules/store/plugins/compression_test.js
generated
vendored
Normal file
37
node_modules/store/plugins/compression_test.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
var { deepEqual } = require('../tests/util')
|
||||
|
||||
module.exports = {
|
||||
plugin: require('./compression'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
test('string compression size', function() {
|
||||
var str = 'foo'
|
||||
var serialized = store._serialize(str)
|
||||
store.set('foo', str)
|
||||
assert(store.raw.get('foo').length < serialized.length, 'compressed string should be smaller than uncompressed')
|
||||
assert(deepEqual(store.get('foo'), str), 'value should be equal')
|
||||
})
|
||||
|
||||
test('object compression', function () {
|
||||
var obj = { one: { two: 3 }}
|
||||
var serialized = store._serialize(obj)
|
||||
store.set('foo', obj)
|
||||
assert(store.raw.get('foo').length < serialized.length, 'compressed object should be smaller than uncompressed')
|
||||
assert(deepEqual(store.get('foo'), obj), 'should deep equal original object')
|
||||
store.remove('foo')
|
||||
})
|
||||
|
||||
test('decompress uncopmressed data', function () {
|
||||
store.raw.set('foo', 'baz')
|
||||
assert(store.get('foo') == 'baz', 'value should be baz')
|
||||
store.remove('foo')
|
||||
})
|
||||
|
||||
test('decompress non-existing data', function () {
|
||||
assert(store.get('bar') == undefined, 'value should be undefined')
|
||||
store.remove('bar')
|
||||
})
|
||||
|
||||
}
|
||||
19
node_modules/store/plugins/defaults.js
generated
vendored
Normal file
19
node_modules/store/plugins/defaults.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
module.exports = defaultsPlugin
|
||||
|
||||
function defaultsPlugin() {
|
||||
var defaultValues = {}
|
||||
|
||||
return {
|
||||
defaults: defaults,
|
||||
get: get
|
||||
}
|
||||
|
||||
function defaults(_, values) {
|
||||
defaultValues = values
|
||||
}
|
||||
|
||||
function get(super_fn, key) {
|
||||
var val = super_fn()
|
||||
return (val !== undefined ? val : defaultValues[key])
|
||||
}
|
||||
}
|
||||
17
node_modules/store/plugins/defaults_test.js
generated
vendored
Normal file
17
node_modules/store/plugins/defaults_test.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
module.exports = {
|
||||
plugin: require('./defaults'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
|
||||
test('defaults', function() {
|
||||
store.defaults({ foo: 'bar' })
|
||||
assert(store.get('foo') == 'bar')
|
||||
store.set('foo', 'bar2')
|
||||
assert(store.get('foo') == 'bar2')
|
||||
store.remove('foo')
|
||||
assert(store.get('foo') == 'bar')
|
||||
})
|
||||
|
||||
}
|
||||
15
node_modules/store/plugins/dump.js
generated
vendored
Normal file
15
node_modules/store/plugins/dump.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
module.exports = dumpPlugin
|
||||
|
||||
function dumpPlugin() {
|
||||
return {
|
||||
dump: dump
|
||||
}
|
||||
|
||||
function dump(_) {
|
||||
var res = {}
|
||||
this.each(function(val, key) {
|
||||
res[key] = val
|
||||
})
|
||||
return res
|
||||
}
|
||||
}
|
||||
25
node_modules/store/plugins/dump_test.js
generated
vendored
Normal file
25
node_modules/store/plugins/dump_test.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var { each } = require('../src/util')
|
||||
var { deepEqual } = require('../tests/util')
|
||||
|
||||
module.exports = {
|
||||
plugin: require('./dump'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
|
||||
test('dump', function() {
|
||||
var allValues = {
|
||||
'foo': 'bar',
|
||||
'cat': { mat:true },
|
||||
'hat': 'bat'
|
||||
}
|
||||
each(allValues, function(val, key) {
|
||||
store.set(key, val)
|
||||
})
|
||||
|
||||
assert(deepEqual(store.dump(), allValues))
|
||||
store.clearAll()
|
||||
assert(deepEqual(store.dump(), {}))
|
||||
})
|
||||
}
|
||||
95
node_modules/store/plugins/events.js
generated
vendored
Normal file
95
node_modules/store/plugins/events.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
var util = require('../src/util')
|
||||
var bind = util.bind
|
||||
var each = util.each
|
||||
var create = util.create
|
||||
var slice = util.slice
|
||||
|
||||
module.exports = eventsPlugin
|
||||
|
||||
function eventsPlugin() {
|
||||
var pubsub = _newPubSub()
|
||||
|
||||
return {
|
||||
watch: watch,
|
||||
unwatch: unwatch,
|
||||
once: once,
|
||||
|
||||
set: set,
|
||||
remove: remove,
|
||||
clearAll: clearAll
|
||||
}
|
||||
|
||||
// new pubsub functions
|
||||
function watch(_, key, listener) {
|
||||
return pubsub.on(key, bind(this, listener))
|
||||
}
|
||||
function unwatch(_, subId) {
|
||||
pubsub.off(subId)
|
||||
}
|
||||
function once(_, key, listener) {
|
||||
pubsub.once(key, bind(this, listener))
|
||||
}
|
||||
|
||||
// overwrite function to fire when appropriate
|
||||
function set(super_fn, key, val) {
|
||||
var oldVal = this.get(key)
|
||||
super_fn()
|
||||
pubsub.fire(key, val, oldVal)
|
||||
}
|
||||
function remove(super_fn, key) {
|
||||
var oldVal = this.get(key)
|
||||
super_fn()
|
||||
pubsub.fire(key, undefined, oldVal)
|
||||
}
|
||||
function clearAll(super_fn) {
|
||||
var oldVals = {}
|
||||
this.each(function(val, key) {
|
||||
oldVals[key] = val
|
||||
})
|
||||
super_fn()
|
||||
each(oldVals, function(oldVal, key) {
|
||||
pubsub.fire(key, undefined, oldVal)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function _newPubSub() {
|
||||
return create(_pubSubBase, {
|
||||
_id: 0,
|
||||
_subSignals: {},
|
||||
_subCallbacks: {}
|
||||
})
|
||||
}
|
||||
|
||||
var _pubSubBase = {
|
||||
_id: null,
|
||||
_subCallbacks: null,
|
||||
_subSignals: null,
|
||||
on: function(signal, callback) {
|
||||
if (!this._subCallbacks[signal]) {
|
||||
this._subCallbacks[signal] = {}
|
||||
}
|
||||
this._id += 1
|
||||
this._subCallbacks[signal][this._id] = callback
|
||||
this._subSignals[this._id] = signal
|
||||
return this._id
|
||||
},
|
||||
off: function(subId) {
|
||||
var signal = this._subSignals[subId]
|
||||
delete this._subCallbacks[signal][subId]
|
||||
delete this._subSignals[subId]
|
||||
},
|
||||
once: function(signal, callback) {
|
||||
var subId = this.on(signal, bind(this, function() {
|
||||
callback.apply(this, arguments)
|
||||
this.off(subId)
|
||||
}))
|
||||
},
|
||||
fire: function(signal) {
|
||||
var args = slice(arguments, 1)
|
||||
each(this._subCallbacks[signal], function(callback) {
|
||||
callback.apply(this, args)
|
||||
})
|
||||
}
|
||||
}
|
||||
71
node_modules/store/plugins/events_test.js
generated
vendored
Normal file
71
node_modules/store/plugins/events_test.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
module.exports = {
|
||||
plugin: require('./events'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
|
||||
test('events', function() {
|
||||
store.set('foo', 'bar')
|
||||
|
||||
var expectationNone = _createExpectation('expectNone', undefined)
|
||||
store.watch('foo', function(){})
|
||||
var expectation1 = _createExpectation('foo', 'bar')
|
||||
var expectationOnce = _createExpectation('foo', 'bar', true)
|
||||
store.watch('foo', function(){})
|
||||
|
||||
expectation1.add('bar2')
|
||||
expectationOnce.add('bar2')
|
||||
store.set('foo', 'bar2')
|
||||
|
||||
expectation1.add(undefined)
|
||||
store.remove('foo')
|
||||
|
||||
expectation1.add('bar3')
|
||||
store.set('foo', 'bar3')
|
||||
|
||||
var expectation2 = _createExpectation('foo', 'bar3')
|
||||
expectation1.add(undefined)
|
||||
expectation2.add(undefined)
|
||||
store.clearAll() // Should fire for foo
|
||||
store.clearAll() // Should not fire anything
|
||||
|
||||
expectation1.unwatch()
|
||||
expectation2.add('bar4')
|
||||
store.set('foo', 'bar4') // Should only fire for expectation2
|
||||
|
||||
expectation1.check()
|
||||
expectationOnce.check()
|
||||
expectation2.check()
|
||||
expectationNone.check()
|
||||
expectation2.unwatch()
|
||||
})
|
||||
|
||||
function _createExpectation(key, firstOldVal, useOnce) {
|
||||
var expectation = {
|
||||
values: [firstOldVal],
|
||||
count: 0,
|
||||
add: function(value) {
|
||||
this.values.push(value)
|
||||
},
|
||||
check: function() {
|
||||
assert(expectation.count + 1 == expectation.values.length)
|
||||
},
|
||||
unwatch: function() {
|
||||
store.unwatch(watchId)
|
||||
}
|
||||
}
|
||||
|
||||
var watchId = (useOnce
|
||||
? store.once(key, callback)
|
||||
: store.watch(key, callback)
|
||||
)
|
||||
function callback(val, oldVal) {
|
||||
expectation.count += 1
|
||||
assert(expectation.values[expectation.count] == val)
|
||||
assert(expectation.values[expectation.count - 1] == oldVal)
|
||||
}
|
||||
|
||||
return expectation
|
||||
}
|
||||
}
|
||||
59
node_modules/store/plugins/expire.js
generated
vendored
Normal file
59
node_modules/store/plugins/expire.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
var namespace = 'expire_mixin'
|
||||
|
||||
module.exports = expirePlugin
|
||||
|
||||
function expirePlugin() {
|
||||
var expirations = this.createStore(this.storage, null, this._namespacePrefix+namespace)
|
||||
|
||||
return {
|
||||
set: expire_set,
|
||||
get: expire_get,
|
||||
remove: expire_remove,
|
||||
getExpiration: getExpiration,
|
||||
removeExpiredKeys: removeExpiredKeys
|
||||
}
|
||||
|
||||
function expire_set(super_fn, key, val, expiration) {
|
||||
if (!this.hasNamespace(namespace)) {
|
||||
expirations.set(key, expiration)
|
||||
}
|
||||
return super_fn()
|
||||
}
|
||||
|
||||
function expire_get(super_fn, key) {
|
||||
if (!this.hasNamespace(namespace)) {
|
||||
_checkExpiration.call(this, key)
|
||||
}
|
||||
return super_fn()
|
||||
}
|
||||
|
||||
function expire_remove(super_fn, key) {
|
||||
if (!this.hasNamespace(namespace)) {
|
||||
expirations.remove(key)
|
||||
}
|
||||
return super_fn()
|
||||
}
|
||||
|
||||
function getExpiration(_, key) {
|
||||
return expirations.get(key)
|
||||
}
|
||||
|
||||
function removeExpiredKeys(_) {
|
||||
var keys = []
|
||||
this.each(function(val, key) {
|
||||
keys.push(key)
|
||||
})
|
||||
for (var i=0; i<keys.length; i++) {
|
||||
_checkExpiration.call(this, keys[i])
|
||||
}
|
||||
}
|
||||
|
||||
function _checkExpiration(key) {
|
||||
var expiration = expirations.get(key, Number.MAX_VALUE)
|
||||
if (expiration <= new Date().getTime()) {
|
||||
this.raw.remove(key)
|
||||
expirations.remove(key)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
59
node_modules/store/plugins/expire_test.js
generated
vendored
Normal file
59
node_modules/store/plugins/expire_test.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
module.exports = {
|
||||
plugin: require('./expire'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
|
||||
test('expire', function(done) {
|
||||
// Ive observed multiple times when legacy browsers in various
|
||||
// environments (saucelabs, VMs, etc) have executed a scheduled
|
||||
// timeout function too soon. The solution is to run a longer,
|
||||
// timeout, but this substantially slows down the test suite.
|
||||
// Instead, we allow multiple attempts with increasing durations.
|
||||
attempt(5, 10)
|
||||
|
||||
function attempt(remaining, duration) {
|
||||
runTests(duration, function check(ok) {
|
||||
if (ok) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (remaining > 0) {
|
||||
setTimeout(function() {
|
||||
attempt(remaining - 1, duration * 2)
|
||||
}, 0)
|
||||
return false
|
||||
}
|
||||
|
||||
return assert(false)
|
||||
})
|
||||
}
|
||||
|
||||
function runTests(duration, check) {
|
||||
var expiration = new Date().getTime() + duration
|
||||
store.set('foo', 'bar', expiration)
|
||||
if (!check(store.get('foo') == 'bar')) { return }
|
||||
|
||||
setTimeout(function() {
|
||||
if (!check(new Date().getTime() > expiration)) { return }
|
||||
if (!check(store.get('foo') == undefined)) { return }
|
||||
|
||||
store.set('foo', 'bar')
|
||||
setTimeout(function() {
|
||||
if (!check(store.get('foo') == 'bar')) { return }
|
||||
|
||||
done()
|
||||
}, 5)
|
||||
}, duration)
|
||||
}
|
||||
})
|
||||
|
||||
test('remove expired keys', function() {
|
||||
var key = 'expired'
|
||||
store.set(key, 'bar', new Date().getTime() - 1000)
|
||||
assert(store.getExpiration(key) > 0)
|
||||
store.removeExpiredKeys()
|
||||
assert(!store.getExpiration(key))
|
||||
})
|
||||
}
|
||||
6
node_modules/store/plugins/json2.js
generated
vendored
Normal file
6
node_modules/store/plugins/json2.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = json2Plugin
|
||||
|
||||
function json2Plugin() {
|
||||
require('./lib/json2')
|
||||
return {}
|
||||
}
|
||||
12
node_modules/store/plugins/json2_test.js
generated
vendored
Normal file
12
node_modules/store/plugins/json2_test.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
module.exports = {
|
||||
plugin: require('./json2'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
|
||||
test('serialization with json2', function() {
|
||||
store.set('foo', { bar:'cat' })
|
||||
assert(store.get('foo').bar === 'cat')
|
||||
})
|
||||
}
|
||||
508
node_modules/store/plugins/lib/json2.js
generated
vendored
Normal file
508
node_modules/store/plugins/lib/json2.js
generated
vendored
Normal file
@@ -0,0 +1,508 @@
|
||||
/* eslint-disable */
|
||||
|
||||
// json2.js
|
||||
// 2016-10-28
|
||||
// Public Domain.
|
||||
// NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
// See http://www.JSON.org/js.html
|
||||
// This code should be minified before deployment.
|
||||
// See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
// USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
// NOT CONTROL.
|
||||
|
||||
// This file creates a global JSON object containing two methods: stringify
|
||||
// and parse. This file provides the ES5 JSON capability to ES3 systems.
|
||||
// If a project might run on IE8 or earlier, then this file should be included.
|
||||
// This file does nothing on ES5 systems.
|
||||
|
||||
// JSON.stringify(value, replacer, space)
|
||||
// value any JavaScript value, usually an object or array.
|
||||
// replacer an optional parameter that determines how object
|
||||
// values are stringified for objects. It can be a
|
||||
// function or an array of strings.
|
||||
// space an optional parameter that specifies the indentation
|
||||
// of nested structures. If it is omitted, the text will
|
||||
// be packed without extra whitespace. If it is a number,
|
||||
// it will specify the number of spaces to indent at each
|
||||
// level. If it is a string (such as "\t" or " "),
|
||||
// it contains the characters used to indent at each level.
|
||||
// This method produces a JSON text from a JavaScript value.
|
||||
// When an object value is found, if the object contains a toJSON
|
||||
// method, its toJSON method will be called and the result will be
|
||||
// stringified. A toJSON method does not serialize: it returns the
|
||||
// value represented by the name/value pair that should be serialized,
|
||||
// or undefined if nothing should be serialized. The toJSON method
|
||||
// will be passed the key associated with the value, and this will be
|
||||
// bound to the value.
|
||||
|
||||
// For example, this would serialize Dates as ISO strings.
|
||||
|
||||
// Date.prototype.toJSON = function (key) {
|
||||
// function f(n) {
|
||||
// // Format integers to have at least two digits.
|
||||
// return (n < 10)
|
||||
// ? "0" + n
|
||||
// : n;
|
||||
// }
|
||||
// return this.getUTCFullYear() + "-" +
|
||||
// f(this.getUTCMonth() + 1) + "-" +
|
||||
// f(this.getUTCDate()) + "T" +
|
||||
// f(this.getUTCHours()) + ":" +
|
||||
// f(this.getUTCMinutes()) + ":" +
|
||||
// f(this.getUTCSeconds()) + "Z";
|
||||
// };
|
||||
|
||||
// You can provide an optional replacer method. It will be passed the
|
||||
// key and value of each member, with this bound to the containing
|
||||
// object. The value that is returned from your method will be
|
||||
// serialized. If your method returns undefined, then the member will
|
||||
// be excluded from the serialization.
|
||||
|
||||
// If the replacer parameter is an array of strings, then it will be
|
||||
// used to select the members to be serialized. It filters the results
|
||||
// such that only members with keys listed in the replacer array are
|
||||
// stringified.
|
||||
|
||||
// Values that do not have JSON representations, such as undefined or
|
||||
// functions, will not be serialized. Such values in objects will be
|
||||
// dropped; in arrays they will be replaced with null. You can use
|
||||
// a replacer function to replace those with JSON values.
|
||||
|
||||
// JSON.stringify(undefined) returns undefined.
|
||||
|
||||
// The optional space parameter produces a stringification of the
|
||||
// value that is filled with line breaks and indentation to make it
|
||||
// easier to read.
|
||||
|
||||
// If the space parameter is a non-empty string, then that string will
|
||||
// be used for indentation. If the space parameter is a number, then
|
||||
// the indentation will be that many spaces.
|
||||
|
||||
// Example:
|
||||
|
||||
// text = JSON.stringify(["e", {pluribus: "unum"}]);
|
||||
// // text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
// text = JSON.stringify(["e", {pluribus: "unum"}], null, "\t");
|
||||
// // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
// text = JSON.stringify([new Date()], function (key, value) {
|
||||
// return this[key] instanceof Date
|
||||
// ? "Date(" + this[key] + ")"
|
||||
// : value;
|
||||
// });
|
||||
// // text is '["Date(---current time---)"]'
|
||||
|
||||
// JSON.parse(text, reviver)
|
||||
// This method parses a JSON text to produce an object or array.
|
||||
// It can throw a SyntaxError exception.
|
||||
|
||||
// The optional reviver parameter is a function that can filter and
|
||||
// transform the results. It receives each of the keys and values,
|
||||
// and its return value is used instead of the original value.
|
||||
// If it returns what it received, then the structure is not modified.
|
||||
// If it returns undefined then the member is deleted.
|
||||
|
||||
// Example:
|
||||
|
||||
// // Parse the text. Values that look like ISO date strings will
|
||||
// // be converted to Date objects.
|
||||
|
||||
// myData = JSON.parse(text, function (key, value) {
|
||||
// var a;
|
||||
// if (typeof value === "string") {
|
||||
// a =
|
||||
// /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
// if (a) {
|
||||
// return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
// +a[5], +a[6]));
|
||||
// }
|
||||
// }
|
||||
// return value;
|
||||
// });
|
||||
|
||||
// myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
// var d;
|
||||
// if (typeof value === "string" &&
|
||||
// value.slice(0, 5) === "Date(" &&
|
||||
// value.slice(-1) === ")") {
|
||||
// d = new Date(value.slice(5, -1));
|
||||
// if (d) {
|
||||
// return d;
|
||||
// }
|
||||
// }
|
||||
// return value;
|
||||
// });
|
||||
|
||||
// This is a reference implementation. You are free to copy, modify, or
|
||||
// redistribute.
|
||||
|
||||
/*jslint
|
||||
eval, for, this
|
||||
*/
|
||||
|
||||
/*property
|
||||
JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
*/
|
||||
|
||||
|
||||
// Create a JSON object only if one does not already exist. We create the
|
||||
// methods in a closure to avoid creating global variables.
|
||||
|
||||
if (typeof JSON !== "object") {
|
||||
JSON = {};
|
||||
}
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
var rx_one = /^[\],:{}\s]*$/;
|
||||
var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
|
||||
var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
|
||||
var rx_four = /(?:^|:|,)(?:\s*\[)+/g;
|
||||
var rx_escapable = /[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||
var rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10
|
||||
? "0" + n
|
||||
: n;
|
||||
}
|
||||
|
||||
function this_value() {
|
||||
return this.valueOf();
|
||||
}
|
||||
|
||||
if (typeof Date.prototype.toJSON !== "function") {
|
||||
|
||||
Date.prototype.toJSON = function () {
|
||||
|
||||
return isFinite(this.valueOf())
|
||||
? this.getUTCFullYear() + "-" +
|
||||
f(this.getUTCMonth() + 1) + "-" +
|
||||
f(this.getUTCDate()) + "T" +
|
||||
f(this.getUTCHours()) + ":" +
|
||||
f(this.getUTCMinutes()) + ":" +
|
||||
f(this.getUTCSeconds()) + "Z"
|
||||
: null;
|
||||
};
|
||||
|
||||
Boolean.prototype.toJSON = this_value;
|
||||
Number.prototype.toJSON = this_value;
|
||||
String.prototype.toJSON = this_value;
|
||||
}
|
||||
|
||||
var gap;
|
||||
var indent;
|
||||
var meta;
|
||||
var rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
rx_escapable.lastIndex = 0;
|
||||
return rx_escapable.test(string)
|
||||
? "\"" + string.replace(rx_escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === "string"
|
||||
? c
|
||||
: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + "\""
|
||||
: "\"" + string + "\"";
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i; // The loop counter.
|
||||
var k; // The member key.
|
||||
var v; // The member value.
|
||||
var length;
|
||||
var mind = gap;
|
||||
var partial;
|
||||
var value = holder[key];
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === "object" &&
|
||||
typeof value.toJSON === "function") {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === "function") {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case "string":
|
||||
return quote(value);
|
||||
|
||||
case "number":
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value)
|
||||
? String(value)
|
||||
: "null";
|
||||
|
||||
case "boolean":
|
||||
case "null":
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce "null". The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
|
||||
// If the type is "object", we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case "object":
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is "object",
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === "[object Array]") {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || "null";
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0
|
||||
? "[]"
|
||||
: gap
|
||||
? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]"
|
||||
: "[" + partial.join(",") + "]";
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === "object") {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
if (typeof rep[i] === "string") {
|
||||
k = rep[i];
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (
|
||||
gap
|
||||
? ": "
|
||||
: ":"
|
||||
) + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (
|
||||
gap
|
||||
? ": "
|
||||
: ":"
|
||||
) + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0
|
||||
? "{}"
|
||||
: gap
|
||||
? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}"
|
||||
: "{" + partial.join(",") + "}";
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof JSON.stringify !== "function") {
|
||||
meta = { // table of character substitutions
|
||||
"\b": "\\b",
|
||||
"\t": "\\t",
|
||||
"\n": "\\n",
|
||||
"\f": "\\f",
|
||||
"\r": "\\r",
|
||||
"\"": "\\\"",
|
||||
"\\": "\\\\"
|
||||
};
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
// that can replace values, or an array of strings that will select the keys.
|
||||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = "";
|
||||
indent = "";
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === "number") {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += " ";
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === "string") {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== "function" &&
|
||||
(typeof replacer !== "object" ||
|
||||
typeof replacer.length !== "number")) {
|
||||
throw new Error("JSON.stringify");
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of "".
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str("", {"": value});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// If the JSON object does not yet have a parse method, give it one.
|
||||
|
||||
if (typeof JSON.parse !== "function") {
|
||||
JSON.parse = function (text, reviver) {
|
||||
|
||||
// The parse method takes a text and an optional reviver function, and returns
|
||||
// a JavaScript value if the text is a valid JSON text.
|
||||
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
|
||||
// The walk method is used to recursively walk the resulting structure so
|
||||
// that modifications can be made.
|
||||
|
||||
var k;
|
||||
var v;
|
||||
var value = holder[key];
|
||||
if (value && typeof value === "object") {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
|
||||
|
||||
// Parsing happens in four stages. In the first stage, we replace certain
|
||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||
|
||||
text = String(text);
|
||||
rx_dangerous.lastIndex = 0;
|
||||
if (rx_dangerous.test(text)) {
|
||||
text = text.replace(rx_dangerous, function (a) {
|
||||
return "\\u" +
|
||||
("0000" + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
// In the second stage, we run the text against regular expressions that look
|
||||
// for non-JSON patterns. We are especially concerned with "()" and "new"
|
||||
// because they can cause invocation, and "=" because it can cause mutation.
|
||||
// But just to be safe, we want to reject all unexpected forms.
|
||||
|
||||
// We split the second stage into 4 regexp operations in order to work around
|
||||
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
||||
// replace the JSON backslash pairs with "@" (a non-JSON character). Second, we
|
||||
// replace all simple value tokens with "]" characters. Third, we delete all
|
||||
// open brackets that follow a colon or comma or that begin the text. Finally,
|
||||
// we look to see that the remaining characters are only whitespace or "]" or
|
||||
// "," or ":" or "{" or "}". If that is so, then the text is safe for eval.
|
||||
|
||||
if (
|
||||
rx_one.test(
|
||||
text
|
||||
.replace(rx_two, "@")
|
||||
.replace(rx_three, "]")
|
||||
.replace(rx_four, "")
|
||||
)
|
||||
) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
// JavaScript structure. The "{" operator is subject to a syntactic ambiguity
|
||||
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
||||
// in parens to eliminate the ambiguity.
|
||||
|
||||
j = eval("(" + text + ")");
|
||||
|
||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||
// each name/value pair to a reviver function for possible transformation.
|
||||
|
||||
return (typeof reviver === "function")
|
||||
? walk({"": j}, "")
|
||||
: j;
|
||||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
|
||||
throw new SyntaxError("JSON.parse");
|
||||
};
|
||||
}
|
||||
}());
|
||||
502
node_modules/store/plugins/lib/lz-string.js
generated
vendored
Normal file
502
node_modules/store/plugins/lib/lz-string.js
generated
vendored
Normal file
@@ -0,0 +1,502 @@
|
||||
/* eslint-disable */
|
||||
// Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net>
|
||||
// This work is free. You can redistribute it and/or modify it
|
||||
// under the terms of the WTFPL, Version 2
|
||||
// For more information see LICENSE.txt or http://www.wtfpl.net/
|
||||
//
|
||||
// For more information, the home page:
|
||||
// http://pieroxy.net/blog/pages/lz-string/testing.html
|
||||
//
|
||||
// LZ-based compression algorithm, version 1.4.4
|
||||
var LZString = (function() {
|
||||
|
||||
// private property
|
||||
var f = String.fromCharCode;
|
||||
var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
|
||||
var baseReverseDic = {};
|
||||
|
||||
function getBaseValue(alphabet, character) {
|
||||
if (!baseReverseDic[alphabet]) {
|
||||
baseReverseDic[alphabet] = {};
|
||||
for (var i=0 ; i<alphabet.length ; i++) {
|
||||
baseReverseDic[alphabet][alphabet.charAt(i)] = i;
|
||||
}
|
||||
}
|
||||
return baseReverseDic[alphabet][character];
|
||||
}
|
||||
|
||||
var LZString = {
|
||||
compressToBase64 : function (input) {
|
||||
if (input == null) return "";
|
||||
var res = LZString._compress(input, 6, function(a){return keyStrBase64.charAt(a);});
|
||||
switch (res.length % 4) { // To produce valid Base64
|
||||
default: // When could this happen ?
|
||||
case 0 : return res;
|
||||
case 1 : return res+"===";
|
||||
case 2 : return res+"==";
|
||||
case 3 : return res+"=";
|
||||
}
|
||||
},
|
||||
|
||||
decompressFromBase64 : function (input) {
|
||||
if (input == null) return "";
|
||||
if (input == "") return null;
|
||||
return LZString._decompress(input.length, 32, function(index) { return getBaseValue(keyStrBase64, input.charAt(index)); });
|
||||
},
|
||||
|
||||
compressToUTF16 : function (input) {
|
||||
if (input == null) return "";
|
||||
return LZString._compress(input, 15, function(a){return f(a+32);}) + " ";
|
||||
},
|
||||
|
||||
decompressFromUTF16: function (compressed) {
|
||||
if (compressed == null) return "";
|
||||
if (compressed == "") return null;
|
||||
return LZString._decompress(compressed.length, 16384, function(index) { return compressed.charCodeAt(index) - 32; });
|
||||
},
|
||||
|
||||
//compress into uint8array (UCS-2 big endian format)
|
||||
compressToUint8Array: function (uncompressed) {
|
||||
var compressed = LZString.compress(uncompressed);
|
||||
var buf=new Uint8Array(compressed.length*2); // 2 bytes per character
|
||||
|
||||
for (var i=0, TotalLen=compressed.length; i<TotalLen; i++) {
|
||||
var current_value = compressed.charCodeAt(i);
|
||||
buf[i*2] = current_value >>> 8;
|
||||
buf[i*2+1] = current_value % 256;
|
||||
}
|
||||
return buf;
|
||||
},
|
||||
|
||||
//decompress from uint8array (UCS-2 big endian format)
|
||||
decompressFromUint8Array:function (compressed) {
|
||||
if (compressed===null || compressed===undefined){
|
||||
return LZString.decompress(compressed);
|
||||
} else {
|
||||
var buf=new Array(compressed.length/2); // 2 bytes per character
|
||||
for (var i=0, TotalLen=buf.length; i<TotalLen; i++) {
|
||||
buf[i]=compressed[i*2]*256+compressed[i*2+1];
|
||||
}
|
||||
|
||||
var result = [];
|
||||
buf.forEach(function (c) {
|
||||
result.push(f(c));
|
||||
});
|
||||
return LZString.decompress(result.join(''));
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
//compress into a string that is already URI encoded
|
||||
compressToEncodedURIComponent: function (input) {
|
||||
if (input == null) return "";
|
||||
return LZString._compress(input, 6, function(a){return keyStrUriSafe.charAt(a);});
|
||||
},
|
||||
|
||||
//decompress from an output of compressToEncodedURIComponent
|
||||
decompressFromEncodedURIComponent:function (input) {
|
||||
if (input == null) return "";
|
||||
if (input == "") return null;
|
||||
input = input.replace(/ /g, "+");
|
||||
return LZString._decompress(input.length, 32, function(index) { return getBaseValue(keyStrUriSafe, input.charAt(index)); });
|
||||
},
|
||||
|
||||
compress: function (uncompressed) {
|
||||
return LZString._compress(uncompressed, 16, function(a){return f(a);});
|
||||
},
|
||||
_compress: function (uncompressed, bitsPerChar, getCharFromInt) {
|
||||
if (uncompressed == null) return "";
|
||||
var i, value,
|
||||
context_dictionary= {},
|
||||
context_dictionaryToCreate= {},
|
||||
context_c="",
|
||||
context_wc="",
|
||||
context_w="",
|
||||
context_enlargeIn= 2, // Compensate for the first entry which should not count
|
||||
context_dictSize= 3,
|
||||
context_numBits= 2,
|
||||
context_data=[],
|
||||
context_data_val=0,
|
||||
context_data_position=0,
|
||||
ii;
|
||||
|
||||
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
||||
context_c = uncompressed.charAt(ii);
|
||||
if (!Object.prototype.hasOwnProperty.call(context_dictionary,context_c)) {
|
||||
context_dictionary[context_c] = context_dictSize++;
|
||||
context_dictionaryToCreate[context_c] = true;
|
||||
}
|
||||
|
||||
context_wc = context_w + context_c;
|
||||
if (Object.prototype.hasOwnProperty.call(context_dictionary,context_wc)) {
|
||||
context_w = context_wc;
|
||||
} else {
|
||||
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) {
|
||||
if (context_w.charCodeAt(0)<256) {
|
||||
for (i=0 ; i<context_numBits ; i++) {
|
||||
context_data_val = (context_data_val << 1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
}
|
||||
value = context_w.charCodeAt(0);
|
||||
for (i=0 ; i<8 ; i++) {
|
||||
context_data_val = (context_data_val << 1) | (value&1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
value = value >> 1;
|
||||
}
|
||||
} else {
|
||||
value = 1;
|
||||
for (i=0 ; i<context_numBits ; i++) {
|
||||
context_data_val = (context_data_val << 1) | value;
|
||||
if (context_data_position ==bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
value = context_w.charCodeAt(0);
|
||||
for (i=0 ; i<16 ; i++) {
|
||||
context_data_val = (context_data_val << 1) | (value&1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
value = value >> 1;
|
||||
}
|
||||
}
|
||||
context_enlargeIn--;
|
||||
if (context_enlargeIn == 0) {
|
||||
context_enlargeIn = Math.pow(2, context_numBits);
|
||||
context_numBits++;
|
||||
}
|
||||
delete context_dictionaryToCreate[context_w];
|
||||
} else {
|
||||
value = context_dictionary[context_w];
|
||||
for (i=0 ; i<context_numBits ; i++) {
|
||||
context_data_val = (context_data_val << 1) | (value&1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
value = value >> 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
context_enlargeIn--;
|
||||
if (context_enlargeIn == 0) {
|
||||
context_enlargeIn = Math.pow(2, context_numBits);
|
||||
context_numBits++;
|
||||
}
|
||||
// Add wc to the dictionary.
|
||||
context_dictionary[context_wc] = context_dictSize++;
|
||||
context_w = String(context_c);
|
||||
}
|
||||
}
|
||||
|
||||
// Output the code for w.
|
||||
if (context_w !== "") {
|
||||
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate,context_w)) {
|
||||
if (context_w.charCodeAt(0)<256) {
|
||||
for (i=0 ; i<context_numBits ; i++) {
|
||||
context_data_val = (context_data_val << 1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
}
|
||||
value = context_w.charCodeAt(0);
|
||||
for (i=0 ; i<8 ; i++) {
|
||||
context_data_val = (context_data_val << 1) | (value&1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
value = value >> 1;
|
||||
}
|
||||
} else {
|
||||
value = 1;
|
||||
for (i=0 ; i<context_numBits ; i++) {
|
||||
context_data_val = (context_data_val << 1) | value;
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
value = 0;
|
||||
}
|
||||
value = context_w.charCodeAt(0);
|
||||
for (i=0 ; i<16 ; i++) {
|
||||
context_data_val = (context_data_val << 1) | (value&1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
value = value >> 1;
|
||||
}
|
||||
}
|
||||
context_enlargeIn--;
|
||||
if (context_enlargeIn == 0) {
|
||||
context_enlargeIn = Math.pow(2, context_numBits);
|
||||
context_numBits++;
|
||||
}
|
||||
delete context_dictionaryToCreate[context_w];
|
||||
} else {
|
||||
value = context_dictionary[context_w];
|
||||
for (i=0 ; i<context_numBits ; i++) {
|
||||
context_data_val = (context_data_val << 1) | (value&1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
value = value >> 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
context_enlargeIn--;
|
||||
if (context_enlargeIn == 0) {
|
||||
context_enlargeIn = Math.pow(2, context_numBits);
|
||||
context_numBits++;
|
||||
}
|
||||
}
|
||||
|
||||
// Mark the end of the stream
|
||||
value = 2;
|
||||
for (i=0 ; i<context_numBits ; i++) {
|
||||
context_data_val = (context_data_val << 1) | (value&1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data_position = 0;
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
context_data_val = 0;
|
||||
} else {
|
||||
context_data_position++;
|
||||
}
|
||||
value = value >> 1;
|
||||
}
|
||||
|
||||
// Flush the last char
|
||||
while (true) {
|
||||
context_data_val = (context_data_val << 1);
|
||||
if (context_data_position == bitsPerChar-1) {
|
||||
context_data.push(getCharFromInt(context_data_val));
|
||||
break;
|
||||
}
|
||||
else context_data_position++;
|
||||
}
|
||||
return context_data.join('');
|
||||
},
|
||||
|
||||
decompress: function (compressed) {
|
||||
if (compressed == null) return "";
|
||||
if (compressed == "") return null;
|
||||
return LZString._decompress(compressed.length, 32768, function(index) { return compressed.charCodeAt(index); });
|
||||
},
|
||||
|
||||
_decompress: function (length, resetValue, getNextValue) {
|
||||
var dictionary = [],
|
||||
next,
|
||||
enlargeIn = 4,
|
||||
dictSize = 4,
|
||||
numBits = 3,
|
||||
entry = "",
|
||||
result = [],
|
||||
i,
|
||||
w,
|
||||
bits, resb, maxpower, power,
|
||||
c,
|
||||
data = {val:getNextValue(0), position:resetValue, index:1};
|
||||
|
||||
for (i = 0; i < 3; i += 1) {
|
||||
dictionary[i] = i;
|
||||
}
|
||||
|
||||
bits = 0;
|
||||
maxpower = Math.pow(2,2);
|
||||
power=1;
|
||||
while (power!=maxpower) {
|
||||
resb = data.val & data.position;
|
||||
data.position >>= 1;
|
||||
if (data.position == 0) {
|
||||
data.position = resetValue;
|
||||
data.val = getNextValue(data.index++);
|
||||
}
|
||||
bits |= (resb>0 ? 1 : 0) * power;
|
||||
power <<= 1;
|
||||
}
|
||||
|
||||
switch (next = bits) {
|
||||
case 0:
|
||||
bits = 0;
|
||||
maxpower = Math.pow(2,8);
|
||||
power=1;
|
||||
while (power!=maxpower) {
|
||||
resb = data.val & data.position;
|
||||
data.position >>= 1;
|
||||
if (data.position == 0) {
|
||||
data.position = resetValue;
|
||||
data.val = getNextValue(data.index++);
|
||||
}
|
||||
bits |= (resb>0 ? 1 : 0) * power;
|
||||
power <<= 1;
|
||||
}
|
||||
c = f(bits);
|
||||
break;
|
||||
case 1:
|
||||
bits = 0;
|
||||
maxpower = Math.pow(2,16);
|
||||
power=1;
|
||||
while (power!=maxpower) {
|
||||
resb = data.val & data.position;
|
||||
data.position >>= 1;
|
||||
if (data.position == 0) {
|
||||
data.position = resetValue;
|
||||
data.val = getNextValue(data.index++);
|
||||
}
|
||||
bits |= (resb>0 ? 1 : 0) * power;
|
||||
power <<= 1;
|
||||
}
|
||||
c = f(bits);
|
||||
break;
|
||||
case 2:
|
||||
return "";
|
||||
}
|
||||
dictionary[3] = c;
|
||||
w = c;
|
||||
result.push(c);
|
||||
while (true) {
|
||||
if (data.index > length) {
|
||||
return "";
|
||||
}
|
||||
|
||||
bits = 0;
|
||||
maxpower = Math.pow(2,numBits);
|
||||
power=1;
|
||||
while (power!=maxpower) {
|
||||
resb = data.val & data.position;
|
||||
data.position >>= 1;
|
||||
if (data.position == 0) {
|
||||
data.position = resetValue;
|
||||
data.val = getNextValue(data.index++);
|
||||
}
|
||||
bits |= (resb>0 ? 1 : 0) * power;
|
||||
power <<= 1;
|
||||
}
|
||||
|
||||
switch (c = bits) {
|
||||
case 0:
|
||||
bits = 0;
|
||||
maxpower = Math.pow(2,8);
|
||||
power=1;
|
||||
while (power!=maxpower) {
|
||||
resb = data.val & data.position;
|
||||
data.position >>= 1;
|
||||
if (data.position == 0) {
|
||||
data.position = resetValue;
|
||||
data.val = getNextValue(data.index++);
|
||||
}
|
||||
bits |= (resb>0 ? 1 : 0) * power;
|
||||
power <<= 1;
|
||||
}
|
||||
|
||||
dictionary[dictSize++] = f(bits);
|
||||
c = dictSize-1;
|
||||
enlargeIn--;
|
||||
break;
|
||||
case 1:
|
||||
bits = 0;
|
||||
maxpower = Math.pow(2,16);
|
||||
power=1;
|
||||
while (power!=maxpower) {
|
||||
resb = data.val & data.position;
|
||||
data.position >>= 1;
|
||||
if (data.position == 0) {
|
||||
data.position = resetValue;
|
||||
data.val = getNextValue(data.index++);
|
||||
}
|
||||
bits |= (resb>0 ? 1 : 0) * power;
|
||||
power <<= 1;
|
||||
}
|
||||
dictionary[dictSize++] = f(bits);
|
||||
c = dictSize-1;
|
||||
enlargeIn--;
|
||||
break;
|
||||
case 2:
|
||||
return result.join('');
|
||||
}
|
||||
|
||||
if (enlargeIn == 0) {
|
||||
enlargeIn = Math.pow(2, numBits);
|
||||
numBits++;
|
||||
}
|
||||
|
||||
if (dictionary[c]) {
|
||||
entry = dictionary[c];
|
||||
} else {
|
||||
if (c === dictSize) {
|
||||
entry = w + w.charAt(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
result.push(entry);
|
||||
|
||||
// Add w+entry[0] to the dictionary.
|
||||
dictionary[dictSize++] = w + entry.charAt(0);
|
||||
enlargeIn--;
|
||||
|
||||
w = entry;
|
||||
|
||||
if (enlargeIn == 0) {
|
||||
enlargeIn = Math.pow(2, numBits);
|
||||
numBits++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
return LZString;
|
||||
})();
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(function () { return LZString; });
|
||||
} else if( typeof module !== 'undefined' && module != null ) {
|
||||
module.exports = LZString
|
||||
}
|
||||
19
node_modules/store/plugins/observe.js
generated
vendored
Normal file
19
node_modules/store/plugins/observe.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var eventsPlugin = require('./events')
|
||||
|
||||
module.exports = [eventsPlugin, observePlugin]
|
||||
|
||||
function observePlugin() {
|
||||
return {
|
||||
observe: observe,
|
||||
unobserve: unobserve
|
||||
}
|
||||
|
||||
function observe(_, key, callback) {
|
||||
var subId = this.watch(key, callback)
|
||||
callback(this.get(key))
|
||||
return subId
|
||||
}
|
||||
function unobserve(_, subId) {
|
||||
this.unwatch(subId)
|
||||
}
|
||||
}
|
||||
31
node_modules/store/plugins/observe_test.js
generated
vendored
Normal file
31
node_modules/store/plugins/observe_test.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
module.exports = {
|
||||
plugin: require('./observe'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
|
||||
test('observe', function() {
|
||||
store.clearAll()
|
||||
var count = -1
|
||||
var expect = [undefined]
|
||||
var obsId = store.observe('foo', function(val, oldVal) {
|
||||
count += 1
|
||||
assert(expect[count] == val)
|
||||
assert(expect[count - 1] == oldVal)
|
||||
}) // count == 1
|
||||
store.unobserve(obsId)
|
||||
|
||||
expect.push('bar')
|
||||
store.set('foo', 'bar')
|
||||
store.observe('foo', function(val, oldVal) {
|
||||
count += 1
|
||||
assert(expect[count] == val)
|
||||
assert(expect[count - 1] == oldVal)
|
||||
}) // count == 2
|
||||
|
||||
expect.push('bar2')
|
||||
store.set('foo', 'bar2') // count == 3
|
||||
assert(count + 1 == expect.length)
|
||||
})
|
||||
}
|
||||
58
node_modules/store/plugins/operations.js
generated
vendored
Normal file
58
node_modules/store/plugins/operations.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
var util = require('../src/util')
|
||||
var slice = util.slice
|
||||
var assign = util.assign
|
||||
|
||||
var updatePlugin = require('./update')
|
||||
|
||||
module.exports = [updatePlugin, operationsPlugin]
|
||||
|
||||
function operationsPlugin() {
|
||||
return {
|
||||
// array
|
||||
push: push,
|
||||
pop: pop,
|
||||
shift: shift,
|
||||
unshift: unshift,
|
||||
|
||||
// obj
|
||||
assign: assign_,
|
||||
}
|
||||
|
||||
// array
|
||||
function push(_, key, val1, val2, val3, etc) {
|
||||
return _arrayOp.call(this, 'push', arguments)
|
||||
}
|
||||
function pop(_, key) {
|
||||
return _arrayOp.call(this, 'pop', arguments)
|
||||
}
|
||||
function shift(_, key) {
|
||||
return _arrayOp.call(this, 'shift', arguments)
|
||||
}
|
||||
function unshift(_, key, val1, val2, val3, etc) {
|
||||
return _arrayOp.call(this, 'unshift', arguments)
|
||||
}
|
||||
|
||||
// obj
|
||||
function assign_(_, key, props1, props2, props3, etc) {
|
||||
var varArgs = slice(arguments, 2)
|
||||
return this.update(key, {}, function(val) {
|
||||
if (typeof val != 'object') {
|
||||
throw new Error('store.assign called for non-object value with key "'+key+'"')
|
||||
}
|
||||
varArgs.unshift(val)
|
||||
return assign.apply(Object, varArgs)
|
||||
})
|
||||
}
|
||||
|
||||
// internal
|
||||
///////////
|
||||
function _arrayOp(arrayFn, opArgs) {
|
||||
var res
|
||||
var key = opArgs[1]
|
||||
var rest = slice(opArgs, 2)
|
||||
this.update(key, [], function(arrVal) {
|
||||
res = Array.prototype[arrayFn].apply(arrVal, rest)
|
||||
})
|
||||
return res
|
||||
}
|
||||
}
|
||||
72
node_modules/store/plugins/operations_test.js
generated
vendored
Normal file
72
node_modules/store/plugins/operations_test.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
var { each, map } = require('../src/util')
|
||||
var { deepEqual } = require('../tests/util')
|
||||
|
||||
module.exports = {
|
||||
plugin: require('./operations'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
|
||||
test('push', function() {
|
||||
_testArrayOp('push', [], [
|
||||
[],
|
||||
['a'],
|
||||
['b','c'],
|
||||
[null],
|
||||
[[], {}]
|
||||
])
|
||||
})
|
||||
|
||||
test('unshift', function() {
|
||||
_testArrayOp('unshift', undefined, [
|
||||
[],
|
||||
['a'],
|
||||
['b','c'],
|
||||
[null],
|
||||
[[], {}]
|
||||
])
|
||||
})
|
||||
|
||||
test('pop', function() {
|
||||
var arr = ['a', 'b', 'c', null, [[], {}]]
|
||||
// Call pop arr.length + 1 times. No args each time
|
||||
var argsList = map(arr, function() { return [] }).concat([])
|
||||
_testArrayOp('pop', arr, argsList)
|
||||
})
|
||||
|
||||
test('shift', function() {
|
||||
var arr = ['a', 'b', 'c', null, [[], {}]]
|
||||
// Call shift arr.length + 1 times. No args each time
|
||||
var argsList = map(arr, function() { return [] }).concat([])
|
||||
_testArrayOp('shift', arr, argsList)
|
||||
})
|
||||
|
||||
test('assign', function() {
|
||||
store.clearAll()
|
||||
var expect = { bar:'cat', mat:{ hat:'bat', arr:[1,2,3] }}
|
||||
store.assign('foo', expect)
|
||||
assert(deepEqual(store.get('foo'), expect))
|
||||
var add = { bar:'cat2', mat:{ hat:'bat2' }, newProp:'newProp'}
|
||||
store.assign('foo', add)
|
||||
each(add, function(val, key) {
|
||||
expect[key] = val
|
||||
})
|
||||
assert(deepEqual(store.get('foo'), expect))
|
||||
})
|
||||
|
||||
function _testArrayOp(fnName, arr, argLists) {
|
||||
var key = 'test-'+fnName
|
||||
store.set(key, arr)
|
||||
arr = (arr || [])
|
||||
var arrFn = arr[fnName]
|
||||
var storeFn = store[fnName]
|
||||
each(argLists, function(args) {
|
||||
var expectedFnResult = arrFn.apply(arr, args)
|
||||
var actualFnResult = storeFn.apply(store, [key].concat(args))
|
||||
assert(deepEqual(expectedFnResult, actualFnResult))
|
||||
var actual = store.get(key)
|
||||
assert(deepEqual(arr, actual))
|
||||
})
|
||||
}
|
||||
}
|
||||
17
node_modules/store/plugins/update.js
generated
vendored
Normal file
17
node_modules/store/plugins/update.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
module.exports = updatePlugin
|
||||
|
||||
function updatePlugin() {
|
||||
return {
|
||||
update: update
|
||||
}
|
||||
|
||||
function update(_, key, optDefaultVal, updateFn) {
|
||||
if (arguments.length == 3) {
|
||||
updateFn = optDefaultVal
|
||||
optDefaultVal = undefined
|
||||
}
|
||||
var val = this.get(key, optDefaultVal)
|
||||
var retVal = updateFn(val)
|
||||
this.set(key, retVal != undefined ? retVal : val)
|
||||
}
|
||||
}
|
||||
43
node_modules/store/plugins/update_test.js
generated
vendored
Normal file
43
node_modules/store/plugins/update_test.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
module.exports = {
|
||||
plugin: require('./update'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
|
||||
test('update', function() {
|
||||
store.set('foo', { cat:'mat' })
|
||||
assert(store.get('foo').cat == 'mat')
|
||||
store.update('foo', function(foo) {
|
||||
foo.cat = 'mat2'
|
||||
})
|
||||
assert(store.get('foo').cat == 'mat2')
|
||||
})
|
||||
|
||||
test('update return value', function() {
|
||||
store.clearAll()
|
||||
store.update('foo', function(foo) {
|
||||
assert(foo == undefined)
|
||||
return { cat:'mat4' }
|
||||
})
|
||||
assert(store.get('foo').cat == 'mat4')
|
||||
})
|
||||
|
||||
test('update default value', function() {
|
||||
store.clearAll()
|
||||
store.update('foo2', {}, function(foo2) {
|
||||
foo2.bar = 'cat'
|
||||
})
|
||||
assert(store.get('foo2').bar == 'cat')
|
||||
})
|
||||
|
||||
test('update default value + return', function() {
|
||||
store.clearAll()
|
||||
store.update('foo2', [], function(foor2) {
|
||||
return { bar2:'cat2' }
|
||||
})
|
||||
assert(typeof store.get('foo2') == 'object')
|
||||
assert(store.get('foo2').bar == undefined)
|
||||
assert(store.get('foo2').bar2 == 'cat2')
|
||||
})
|
||||
}
|
||||
52
node_modules/store/plugins/v1-backcompat.js
generated
vendored
Normal file
52
node_modules/store/plugins/v1-backcompat.js
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
var dumpPlugin = require('./dump')
|
||||
var json2Plugin = require('./json2')
|
||||
|
||||
module.exports = [dumpPlugin, json2Plugin, v1BackcompatPlugin]
|
||||
|
||||
function v1BackcompatPlugin() {
|
||||
this.disabled = !this.enabled
|
||||
return {
|
||||
has: backcompat_has,
|
||||
transact: backcompat_transact,
|
||||
clear: backcompat_clear,
|
||||
forEach: backcompat_forEach,
|
||||
getAll: backcompat_getAll,
|
||||
serialize: backcompat_serialize,
|
||||
deserialize: backcompat_deserialize,
|
||||
}
|
||||
}
|
||||
|
||||
function backcompat_has(_, key) {
|
||||
return this.get(key) !== undefined
|
||||
}
|
||||
function backcompat_transact(_, key, defaultVal, transactionFn) {
|
||||
if (transactionFn == null) {
|
||||
transactionFn = defaultVal
|
||||
defaultVal = null
|
||||
}
|
||||
if (defaultVal == null) {
|
||||
defaultVal = {}
|
||||
}
|
||||
var val = this.get(key, defaultVal)
|
||||
var ret = transactionFn(val)
|
||||
this.set(key, ret === undefined ? val : ret)
|
||||
}
|
||||
function backcompat_clear(_) {
|
||||
return this.clearAll.call(this)
|
||||
}
|
||||
function backcompat_forEach(_, fn) {
|
||||
return this.each.call(this, function(val, key) {
|
||||
fn(key, val)
|
||||
})
|
||||
}
|
||||
function backcompat_getAll(_) {
|
||||
return this.dump.call(this)
|
||||
}
|
||||
function backcompat_serialize(_, value) {
|
||||
return JSON.stringify(value)
|
||||
}
|
||||
function backcompat_deserialize(_, value) {
|
||||
if (typeof value != 'string') { return undefined }
|
||||
try { return JSON.parse(value) }
|
||||
catch(e) { return value || undefined }
|
||||
}
|
||||
44
node_modules/store/plugins/v1-backcompat_test.js
generated
vendored
Normal file
44
node_modules/store/plugins/v1-backcompat_test.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
module.exports = {
|
||||
plugin: require('./v1-backcompat'),
|
||||
setup: setup,
|
||||
}
|
||||
|
||||
function setup(store) {
|
||||
|
||||
test('backwards compatability with v1', function() {
|
||||
store.clear()
|
||||
|
||||
assert(typeof store.disabled == 'boolean')
|
||||
assert(typeof store.enabled == 'boolean')
|
||||
assert(typeof store.version == 'string')
|
||||
assert(typeof store.set == 'function')
|
||||
assert(typeof store.get == 'function')
|
||||
assert(typeof store.has == 'function')
|
||||
assert(typeof store.remove == 'function')
|
||||
assert(typeof store.clear == 'function')
|
||||
assert(typeof store.transact == 'function')
|
||||
assert(typeof store.getAll == 'function')
|
||||
assert(typeof store.forEach == 'function')
|
||||
assert(typeof store.serialize == 'function')
|
||||
assert(typeof store.deserialize == 'function')
|
||||
|
||||
store.transact('foosact', function(val) {
|
||||
assert(typeof val == 'object', "new key is not an object at beginning of transaction")
|
||||
val.foo = 'foo'
|
||||
})
|
||||
store.transact('foosact', function(val) {
|
||||
assert(val.foo == 'foo', "first transaction did not register")
|
||||
val.bar = 'bar'
|
||||
})
|
||||
assert(store.getAll().foosact.foo == 'foo')
|
||||
var wasCalled = false
|
||||
store.forEach(function(key, val) {
|
||||
wasCalled = true
|
||||
assert(key == 'foosact')
|
||||
assert(val.foo == 'foo')
|
||||
})
|
||||
assert(wasCalled)
|
||||
assert(store.serialize({}) == '{}')
|
||||
assert(store.get('foosact').bar == 'bar', "second transaction did not register")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user