mirror of
https://github.com/localForage/localForage.git
synced 2026-01-25 14:44:26 +00:00
commit
21e146c473
87
.eslintrc
Normal file
87
.eslintrc
Normal file
@ -0,0 +1,87 @@
|
||||
{
|
||||
"parser": "babel-eslint",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module",
|
||||
"ecmaFeatures": {
|
||||
"modules": true
|
||||
}
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"rules": {
|
||||
"semi": [
|
||||
2,
|
||||
"always"
|
||||
],
|
||||
"no-bitwise": 2,
|
||||
"curly": 2,
|
||||
"eqeqeq": 2,
|
||||
"no-eq-null": 2,
|
||||
"wrap-iife": [
|
||||
2,
|
||||
"inside"
|
||||
],
|
||||
"no-use-before-define": [
|
||||
2,
|
||||
{
|
||||
"functions": false
|
||||
}
|
||||
],
|
||||
"new-cap": 2,
|
||||
"no-caller": 2,
|
||||
"no-console": 0,
|
||||
"no-new": 2,
|
||||
"quotes": [
|
||||
2,
|
||||
"single",
|
||||
{
|
||||
"avoidEscape": true
|
||||
}
|
||||
],
|
||||
"space-before-function-paren": [
|
||||
2,
|
||||
"never"
|
||||
],
|
||||
"comma-dangle": [
|
||||
2,
|
||||
"never"
|
||||
],
|
||||
"eol-last": 2,
|
||||
"keyword-spacing": [
|
||||
2,
|
||||
{}
|
||||
],
|
||||
"space-before-blocks": [
|
||||
2,
|
||||
"always"
|
||||
],
|
||||
"consistent-this": [
|
||||
2,
|
||||
"self"
|
||||
],
|
||||
"indent": [
|
||||
2,
|
||||
4,
|
||||
{
|
||||
"CallExpression": {"arguments": "first"},
|
||||
"flatTernaryExpressions": true,
|
||||
"FunctionExpression": {"parameters": "first"},
|
||||
"MemberExpression": "off",
|
||||
"SwitchCase": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
"globals": {
|
||||
"define": true,
|
||||
"localforage": true,
|
||||
"module": true,
|
||||
"require": true,
|
||||
"self": true,
|
||||
"System": true
|
||||
}
|
||||
}
|
||||
31
.jscsrc
31
.jscsrc
@ -1,31 +0,0 @@
|
||||
{
|
||||
"esnext": true,
|
||||
"disallowSpacesInAnonymousFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"disallowTrailingComma": true,
|
||||
"requireBlocksOnNewline": true,
|
||||
"requireLineFeedAtFileEnd": true,
|
||||
"requireSpaceAfterKeywords": [
|
||||
"if",
|
||||
"else",
|
||||
"for",
|
||||
"while",
|
||||
"do",
|
||||
"switch",
|
||||
"return",
|
||||
"try",
|
||||
"catch"
|
||||
],
|
||||
"requireSpaceBeforeBlockStatements": true,
|
||||
"requireSpacesInConditionalExpression": true,
|
||||
"requireSpacesInFunctionExpression": {
|
||||
"beforeOpeningCurlyBrace": true
|
||||
},
|
||||
"safeContextKeyword": ["globalObject", "self"],
|
||||
"validateQuoteMarks": {
|
||||
"escape": true,
|
||||
"mark": "'"
|
||||
},
|
||||
"validateIndentation": 4
|
||||
}
|
||||
32
.jshintrc
32
.jshintrc
@ -1,32 +0,0 @@
|
||||
{
|
||||
"asi": false,
|
||||
"bitwise": true,
|
||||
"browser": true,
|
||||
"curly": true,
|
||||
"eqeqeq": true,
|
||||
"eqnull": true,
|
||||
"esnext": true,
|
||||
"immed": true,
|
||||
"latedef": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"nonew": true,
|
||||
"quotmark": false,
|
||||
"strict": false,
|
||||
"trailing": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
|
||||
"validthis": true,
|
||||
|
||||
"globals": {
|
||||
"console": true,
|
||||
"define": true,
|
||||
"localforage": true,
|
||||
"module": true,
|
||||
"Promise": true,
|
||||
"require": true,
|
||||
"self": true,
|
||||
"System": true
|
||||
}
|
||||
}
|
||||
18
Gruntfile.js
18
Gruntfile.js
@ -1,4 +1,3 @@
|
||||
/* jshint node:true */
|
||||
var path = require('path');
|
||||
var saucelabsBrowsers = require(path.resolve('test', 'saucelabs-browsers.js'));
|
||||
|
||||
@ -136,14 +135,8 @@ module.exports = exports = function(grunt) {
|
||||
}]
|
||||
}
|
||||
},
|
||||
jscs: {
|
||||
source: sourceFiles
|
||||
},
|
||||
jshint: {
|
||||
options: {
|
||||
jshintrc: '.jshintrc'
|
||||
},
|
||||
source: sourceFiles
|
||||
eslint: {
|
||||
target: sourceFiles
|
||||
},
|
||||
mocha: {
|
||||
unit: {
|
||||
@ -202,7 +195,6 @@ module.exports = exports = function(grunt) {
|
||||
files: ['src/*.js', 'src/**/*.js'],
|
||||
tasks: ['build']
|
||||
},
|
||||
/*jshint scripturl:true */
|
||||
'mocha:unit': {
|
||||
files: [
|
||||
'dist/localforage.js',
|
||||
@ -210,8 +202,7 @@ module.exports = exports = function(grunt) {
|
||||
'test/test.*.*'
|
||||
],
|
||||
tasks: [
|
||||
'jshint',
|
||||
'jscs',
|
||||
'eslint',
|
||||
'browserify:package_bundling_test',
|
||||
'webpack:package_bundling_test',
|
||||
'mocha:unit'
|
||||
@ -240,8 +231,7 @@ module.exports = exports = function(grunt) {
|
||||
var testTasks = [
|
||||
'build',
|
||||
'babel',
|
||||
'jshint',
|
||||
'jscs',
|
||||
'eslint',
|
||||
'ts:typing_tests',
|
||||
'browserify:package_bundling_test',
|
||||
'webpack:package_bundling_test',
|
||||
|
||||
7
dist/localforage.js
vendored
7
dist/localforage.js
vendored
@ -365,7 +365,9 @@ function getIDB() {
|
||||
if (typeof msIndexedDB !== 'undefined') {
|
||||
return msIndexedDB;
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var idb = getIDB();
|
||||
@ -1683,7 +1685,6 @@ function removeItem$1(key, callback) {
|
||||
t.executeSql('DELETE FROM ' + dbInfo.storeName + ' WHERE key = ?', [key], function () {
|
||||
resolve();
|
||||
}, function (t, error) {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@ -1731,7 +1732,6 @@ function length$1(callback) {
|
||||
|
||||
resolve(result);
|
||||
}, function (t, error) {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@ -1786,7 +1786,6 @@ function keys$1(callback) {
|
||||
|
||||
resolve(keys);
|
||||
}, function (t, error) {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
2
dist/localforage.min.js
vendored
2
dist/localforage.min.js
vendored
File diff suppressed because one or more lines are too long
7
dist/localforage.nopromises.js
vendored
7
dist/localforage.nopromises.js
vendored
@ -29,7 +29,9 @@ function getIDB() {
|
||||
if (typeof msIndexedDB !== 'undefined') {
|
||||
return msIndexedDB;
|
||||
}
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var idb = getIDB();
|
||||
@ -1347,7 +1349,6 @@ function removeItem$1(key, callback) {
|
||||
t.executeSql('DELETE FROM ' + dbInfo.storeName + ' WHERE key = ?', [key], function () {
|
||||
resolve();
|
||||
}, function (t, error) {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@ -1395,7 +1396,6 @@ function length$1(callback) {
|
||||
|
||||
resolve(result);
|
||||
}, function (t, error) {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@ -1450,7 +1450,6 @@ function keys$1(callback) {
|
||||
|
||||
resolve(keys);
|
||||
}, function (t, error) {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
2
dist/localforage.nopromises.min.js
vendored
2
dist/localforage.nopromises.min.js
vendored
File diff suppressed because one or more lines are too long
@ -23,6 +23,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.5.1",
|
||||
"babel-eslint": "^7.2.3",
|
||||
"babel-loader": "^6.2.2",
|
||||
"babel-plugin-add-module-exports": "^0.1.2",
|
||||
"babel-plugin-transform-es2015-modules-umd": "^6.5.0",
|
||||
@ -37,11 +38,10 @@
|
||||
"grunt-browserify": "^3.8.0",
|
||||
"grunt-contrib-concat": "^0.3.0",
|
||||
"grunt-contrib-connect": "^0.8.0",
|
||||
"grunt-contrib-jshint": "^1.0.0",
|
||||
"grunt-contrib-uglify": "^0.4.0",
|
||||
"grunt-contrib-watch": "^0.5.0",
|
||||
"grunt-es3-safe-recast": "^0.1.0",
|
||||
"grunt-jscs": "^1.5.0",
|
||||
"grunt-eslint": "^20.0.0",
|
||||
"grunt-mocha": "^0.4.10",
|
||||
"grunt-rollup": "^0.6.2",
|
||||
"grunt-run": "^0.5.2",
|
||||
|
||||
@ -488,7 +488,7 @@ function iterate(iterator, callback) {
|
||||
value = _decodeBlob(value);
|
||||
}
|
||||
var result = iterator(value, cursor.key,
|
||||
iterationNumber++);
|
||||
iterationNumber++);
|
||||
|
||||
// when the iterator callback retuns any
|
||||
// (non-`undefined`) value, then we stop
|
||||
|
||||
@ -111,7 +111,7 @@ function iterate(iterator, callback) {
|
||||
}
|
||||
|
||||
value = iterator(value, key.substring(keyPrefixLength),
|
||||
iterationNumber++);
|
||||
iterationNumber++);
|
||||
|
||||
if (value !== void(0)) {
|
||||
return value;
|
||||
|
||||
@ -23,7 +23,7 @@ function _initStorage(options) {
|
||||
if (options) {
|
||||
for (var i in options) {
|
||||
dbInfo[i] = typeof(options[i]) !== 'string' ?
|
||||
options[i].toString() : options[i];
|
||||
options[i].toString() : options[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,14 +39,15 @@ function _initStorage(options) {
|
||||
|
||||
// Create our key/value table if it doesn't exist.
|
||||
dbInfo.db.transaction(function(t) {
|
||||
t.executeSql('CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName +
|
||||
' (id INTEGER PRIMARY KEY, key unique, value)', [],
|
||||
function() {
|
||||
self._dbInfo = dbInfo;
|
||||
resolve();
|
||||
}, function(t, error) {
|
||||
reject(error);
|
||||
});
|
||||
t.executeSql(
|
||||
'CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName +
|
||||
' (id INTEGER PRIMARY KEY, key unique, value)', [],
|
||||
function() {
|
||||
self._dbInfo = dbInfo;
|
||||
resolve();
|
||||
}, function(t, error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -63,23 +64,24 @@ function getItem(key, callback) {
|
||||
self.ready().then(function() {
|
||||
var dbInfo = self._dbInfo;
|
||||
dbInfo.db.transaction(function(t) {
|
||||
t.executeSql('SELECT * FROM ' + dbInfo.storeName +
|
||||
' WHERE key = ? LIMIT 1', [key],
|
||||
function(t, results) {
|
||||
var result = results.rows.length ?
|
||||
results.rows.item(0).value : null;
|
||||
t.executeSql(
|
||||
'SELECT * FROM ' + dbInfo.storeName +
|
||||
' WHERE key = ? LIMIT 1', [key],
|
||||
function(t, results) {
|
||||
var result = results.rows.length ?
|
||||
results.rows.item(0).value : null;
|
||||
|
||||
// Check to see if this is serialized content we need to
|
||||
// unpack.
|
||||
if (result) {
|
||||
result = dbInfo.serializer.deserialize(result);
|
||||
}
|
||||
// Check to see if this is serialized content we need to
|
||||
// unpack.
|
||||
if (result) {
|
||||
result = dbInfo.serializer.deserialize(result);
|
||||
}
|
||||
|
||||
resolve(result);
|
||||
}, function(t, error) {
|
||||
resolve(result);
|
||||
}, function(t, error) {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}).catch(reject);
|
||||
});
|
||||
@ -96,7 +98,8 @@ function iterate(iterator, callback) {
|
||||
var dbInfo = self._dbInfo;
|
||||
|
||||
dbInfo.db.transaction(function(t) {
|
||||
t.executeSql('SELECT * FROM ' + dbInfo.storeName, [],
|
||||
t.executeSql(
|
||||
'SELECT * FROM ' + dbInfo.storeName, [],
|
||||
function(t, results) {
|
||||
var rows = results.rows;
|
||||
var length = rows.length;
|
||||
@ -156,14 +159,16 @@ function _setItem(key, value, callback, retriesLeft) {
|
||||
reject(error);
|
||||
} else {
|
||||
dbInfo.db.transaction(function(t) {
|
||||
t.executeSql('INSERT OR REPLACE INTO ' +
|
||||
dbInfo.storeName +
|
||||
' (key, value) VALUES (?, ?)',
|
||||
[key, value], function() {
|
||||
resolve(originalValue);
|
||||
}, function(t, error) {
|
||||
reject(error);
|
||||
});
|
||||
t.executeSql(
|
||||
'INSERT OR REPLACE INTO ' +
|
||||
dbInfo.storeName +
|
||||
' (key, value) VALUES (?, ?)',
|
||||
[key, value],
|
||||
function() {
|
||||
resolve(originalValue);
|
||||
}, function(t, error) {
|
||||
reject(error);
|
||||
});
|
||||
}, function(sqlError) {
|
||||
// The transaction failed; check
|
||||
// to see if it's a quota error.
|
||||
@ -204,14 +209,14 @@ function removeItem(key, callback) {
|
||||
self.ready().then(function() {
|
||||
var dbInfo = self._dbInfo;
|
||||
dbInfo.db.transaction(function(t) {
|
||||
t.executeSql('DELETE FROM ' + dbInfo.storeName +
|
||||
' WHERE key = ?', [key],
|
||||
function() {
|
||||
resolve();
|
||||
}, function(t, error) {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
t.executeSql(
|
||||
'DELETE FROM ' + dbInfo.storeName +
|
||||
' WHERE key = ?', [key],
|
||||
function() {
|
||||
resolve();
|
||||
}, function(t, error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}).catch(reject);
|
||||
});
|
||||
@ -229,12 +234,13 @@ function clear(callback) {
|
||||
self.ready().then(function() {
|
||||
var dbInfo = self._dbInfo;
|
||||
dbInfo.db.transaction(function(t) {
|
||||
t.executeSql('DELETE FROM ' + dbInfo.storeName, [],
|
||||
function() {
|
||||
resolve();
|
||||
}, function(t, error) {
|
||||
reject(error);
|
||||
});
|
||||
t.executeSql(
|
||||
'DELETE FROM ' + dbInfo.storeName, [],
|
||||
function() {
|
||||
resolve();
|
||||
}, function(t, error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}).catch(reject);
|
||||
});
|
||||
@ -253,15 +259,16 @@ function length(callback) {
|
||||
var dbInfo = self._dbInfo;
|
||||
dbInfo.db.transaction(function(t) {
|
||||
// Ahhh, SQL makes this one soooooo easy.
|
||||
t.executeSql('SELECT COUNT(key) as c FROM ' +
|
||||
dbInfo.storeName, [], function(t, results) {
|
||||
var result = results.rows.item(0).c;
|
||||
t.executeSql(
|
||||
'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);
|
||||
});
|
||||
resolve(result);
|
||||
}, function(t, error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}).catch(reject);
|
||||
});
|
||||
@ -284,15 +291,16 @@ function key(n, callback) {
|
||||
self.ready().then(function() {
|
||||
var dbInfo = self._dbInfo;
|
||||
dbInfo.db.transaction(function(t) {
|
||||
t.executeSql('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);
|
||||
});
|
||||
t.executeSql(
|
||||
'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);
|
||||
});
|
||||
@ -308,19 +316,19 @@ function keys(callback) {
|
||||
self.ready().then(function() {
|
||||
var dbInfo = self._dbInfo;
|
||||
dbInfo.db.transaction(function(t) {
|
||||
t.executeSql('SELECT key FROM ' + dbInfo.storeName, [],
|
||||
function(t, results) {
|
||||
var keys = [];
|
||||
t.executeSql(
|
||||
'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);
|
||||
}
|
||||
for (var i = 0; i < results.rows.length; i++) {
|
||||
keys.push(results.rows.item(i).key);
|
||||
}
|
||||
|
||||
resolve(keys);
|
||||
}, function(t, error) {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
resolve(keys);
|
||||
}, function(t, error) {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}).catch(reject);
|
||||
});
|
||||
|
||||
@ -59,8 +59,8 @@ driverSupport[DriverType.WEBSQL] = isWebSQLValid();
|
||||
driverSupport[DriverType.LOCALSTORAGE] = isLocalStorageValid();
|
||||
|
||||
var isArray = Array.isArray || function(arg) {
|
||||
return Object.prototype.toString.call(arg) === '[object Array]';
|
||||
};
|
||||
return Object.prototype.toString.call(arg) === '[object Array]';
|
||||
};
|
||||
|
||||
function callWhenReady(localForageInstance, libraryMethod) {
|
||||
localForageInstance[libraryMethod] = function() {
|
||||
|
||||
@ -16,7 +16,9 @@ function getIDB() {
|
||||
if (typeof msIndexedDB !== 'undefined') {
|
||||
return msIndexedDB;
|
||||
}
|
||||
} catch (e) { }
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var idb = getIDB();
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-bitwise */
|
||||
import createBlob from './createBlob';
|
||||
|
||||
// Sadly, the best way to save binary data in WebSQL/localStorage is serializing
|
||||
@ -154,7 +155,7 @@ function serialize(value, callback) {
|
||||
callback(JSON.stringify(value));
|
||||
} catch (e) {
|
||||
console.error("Couldn't convert value into a JSON string: ",
|
||||
value);
|
||||
value);
|
||||
|
||||
callback(null, e);
|
||||
}
|
||||
@ -173,8 +174,7 @@ function deserialize(value) {
|
||||
// If we haven't marked this string as being specially serialized (i.e.
|
||||
// something other than serialized JSON), we can just return it and be
|
||||
// done with it.
|
||||
if (value.substring(0,
|
||||
SERIALIZED_MARKER_LENGTH) !== SERIALIZED_MARKER) {
|
||||
if (value.substring(0, SERIALIZED_MARKER_LENGTH) !== SERIALIZED_MARKER) {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ function deserialize(value) {
|
||||
// with from the data itself.
|
||||
var serializedString = value.substring(TYPE_SERIALIZED_MARKER_LENGTH);
|
||||
var type = value.substring(SERIALIZED_MARKER_LENGTH,
|
||||
TYPE_SERIALIZED_MARKER_LENGTH);
|
||||
TYPE_SERIALIZED_MARKER_LENGTH);
|
||||
|
||||
var blobType;
|
||||
// Backwards-compatible blob type serialization strategy.
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* global requirejs:true */
|
||||
// Run before window.onload to make sure the specs have access to describe()
|
||||
// and other mocha methods. All feels very hacky though :-/
|
||||
this.mocha.setup('bdd');
|
||||
@ -7,7 +8,7 @@ function runTests() {
|
||||
|
||||
var failedTests = [];
|
||||
|
||||
runner.on('end', function(){
|
||||
runner.on('end', function() {
|
||||
window.mochaResults = runner.stats;
|
||||
window.mochaResults.reports = failedTests;
|
||||
});
|
||||
@ -38,8 +39,8 @@ function runTests() {
|
||||
|
||||
if (!Array.prototype.forEach) {
|
||||
Array.prototype.forEach = function(callback, thisArg) {
|
||||
if (typeof(callback) !== "function") {
|
||||
throw new TypeError(callback + " is not a function!");
|
||||
if (typeof(callback) !== 'function') {
|
||||
throw new TypeError(callback + ' is not a function!');
|
||||
}
|
||||
var len = this.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
|
||||
@ -402,8 +402,7 @@ DRIVERS.forEach(function(driverName) {
|
||||
localforage.getItem('officeX', function(err, value) {
|
||||
expect(value).to.be(setValue);
|
||||
|
||||
localforage.setItem('officeY', 'InitechY',
|
||||
function(err, setValue) {
|
||||
localforage.setItem('officeY', 'InitechY', function(err, setValue) {
|
||||
expect(setValue).to.be('InitechY');
|
||||
|
||||
localforage.getItem('officeY', function(err, value) {
|
||||
@ -461,8 +460,7 @@ DRIVERS.forEach(function(driverName) {
|
||||
});
|
||||
});
|
||||
|
||||
it('should break iteration with defined return value [callback]',
|
||||
function(done) {
|
||||
it('should break iteration with defined return value [callback]', function(done) {
|
||||
var breakCondition = 'Some value!';
|
||||
|
||||
localforage.setItem('officeX', 'InitechX', function(err, setValue) {
|
||||
@ -471,8 +469,7 @@ DRIVERS.forEach(function(driverName) {
|
||||
localforage.getItem('officeX', function(err, value) {
|
||||
expect(value).to.be(setValue);
|
||||
|
||||
localforage.setItem('officeY', 'InitechY',
|
||||
function(err, setValue) {
|
||||
localforage.setItem('officeY', 'InitechY', function(err, setValue) {
|
||||
expect(setValue).to.be('InitechY');
|
||||
|
||||
localforage.getItem('officeY', function(err, value) {
|
||||
@ -495,8 +492,7 @@ DRIVERS.forEach(function(driverName) {
|
||||
});
|
||||
});
|
||||
|
||||
it('should break iteration with defined return value [promise]',
|
||||
function(done) {
|
||||
it('should break iteration with defined return value [promise]', function(done) {
|
||||
var breakCondition = 'Some value!';
|
||||
|
||||
localforage.setItem('officeX', 'InitechX').then(function(setValue) {
|
||||
@ -615,12 +611,10 @@ DRIVERS.forEach(function(driverName) {
|
||||
});
|
||||
|
||||
it('saves an item over an existing key [callback]', function(done) {
|
||||
localforage.setItem('4th floor', 'Mozilla',
|
||||
function(err, setValue) {
|
||||
localforage.setItem('4th floor', 'Mozilla', function(err, setValue) {
|
||||
expect(setValue).to.be('Mozilla');
|
||||
|
||||
localforage.setItem('4th floor', 'Quora',
|
||||
function(err, newValue) {
|
||||
localforage.setItem('4th floor', 'Quora', function(err, newValue) {
|
||||
expect(newValue).to.not.be(setValue);
|
||||
expect(newValue).to.be('Quora');
|
||||
|
||||
@ -727,12 +721,10 @@ DRIVERS.forEach(function(driverName) {
|
||||
localforage.setItem('office', 'Initech', function() {
|
||||
localforage.setItem('otherOffice', 'Initrode', function() {
|
||||
localforage.removeItem('office', function() {
|
||||
localforage.getItem('office',
|
||||
function(err, emptyValue) {
|
||||
localforage.getItem('office', function(err, emptyValue) {
|
||||
expect(emptyValue).to.be(null);
|
||||
|
||||
localforage.getItem('otherOffice',
|
||||
function(err, value) {
|
||||
localforage.getItem('otherOffice', function(err, value) {
|
||||
expect(value).to.be('Initrode');
|
||||
|
||||
done();
|
||||
@ -965,6 +957,7 @@ DRIVERS.forEach(function(driverName) {
|
||||
// Refers to issue #492 - https://github.com/mozilla/localForage/issues/492
|
||||
if (driverName === localforage.INDEXEDDB) {
|
||||
return new Promise(function(resolve) {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
var indexedDB = (indexedDB || window.indexedDB ||
|
||||
window.webkitIndexedDB ||
|
||||
window.mozIndexedDB || window.OIndexedDB ||
|
||||
|
||||
@ -200,8 +200,7 @@ describe('Config API', function() {
|
||||
window.openDatabase('My Cool App', String(2.0), '',
|
||||
4980736).transaction(function(t) {
|
||||
t.executeSql('SELECT * FROM myStoreName WHERE key = ? ' +
|
||||
'LIMIT 1', ['some key'],
|
||||
function(t, results) {
|
||||
'LIMIT 1', ['some key'], function(t, results) {
|
||||
var dbValue = JSON.parse(results.rows.item(0).value);
|
||||
|
||||
expect(dbValue).to.be(value);
|
||||
@ -210,7 +209,7 @@ describe('Config API', function() {
|
||||
});
|
||||
} else if (localforage.driver() === localforage.LOCALSTORAGE) {
|
||||
var dbValue = JSON.parse(
|
||||
localStorage['My Cool App/myStoreName/some key']);
|
||||
localStorage['My Cool App/myStoreName/some key']);
|
||||
|
||||
expect(dbValue).to.be(value);
|
||||
done();
|
||||
|
||||
@ -43,8 +43,7 @@ describe('When Custom Drivers are used', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('fails to define a custom driver with overlapping driver name',
|
||||
function(done) {
|
||||
it('fails to define a custom driver with overlapping driver name', function(done) {
|
||||
localforage.defineDriver({
|
||||
_driver: localforage.INDEXEDDB,
|
||||
_initStorage: function() {},
|
||||
@ -63,8 +62,7 @@ describe('When Custom Drivers are used', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('fails to define a custom driver with overlapping driver name [promise]',
|
||||
function(done) {
|
||||
it('fails to define a custom driver with overlapping driver name [promise]', function(done) {
|
||||
localforage.defineDriver({
|
||||
_driver: localforage.INDEXEDDB,
|
||||
_initStorage: function() {},
|
||||
@ -99,8 +97,7 @@ describe('When Custom Drivers are used', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('fails to define a custom driver with missing methods [promise]',
|
||||
function(done) {
|
||||
it('fails to define a custom driver with missing methods [promise]', function(done) {
|
||||
localforage.defineDriver({
|
||||
_driver: 'missingMethodsDriver',
|
||||
_initStorage: function() {},
|
||||
@ -219,11 +216,9 @@ describe('When Custom Drivers are used', function() {
|
||||
localforage.defineDriver(dummyStorageDriver, function() {
|
||||
localforage.setDriver(dummyStorageDriver._driver, function(err) {
|
||||
expect(err).to.be(undefined);
|
||||
localforage.setItem('testCallbackKey', 'testCallbackValue',
|
||||
function(err) {
|
||||
localforage.setItem('testCallbackKey', 'testCallbackValue', function(err) {
|
||||
expect(err).to.be(null);
|
||||
localforage.getItem('testCallbackKey',
|
||||
function(err, value) {
|
||||
localforage.getItem('testCallbackKey', function(err, value) {
|
||||
expect(err).to.be(null);
|
||||
expect(value).to.be('testCallbackValue');
|
||||
done();
|
||||
|
||||
@ -13,8 +13,8 @@ function createBlob(parts, properties) {
|
||||
}
|
||||
var Builder = typeof BlobBuilder !== 'undefined' ? BlobBuilder :
|
||||
typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder :
|
||||
typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder :
|
||||
WebKitBlobBuilder;
|
||||
typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder :
|
||||
WebKitBlobBuilder;
|
||||
var builder = new Builder();
|
||||
for (var i = 0; i < parts.length; i += 1) {
|
||||
builder.append(parts[i]);
|
||||
@ -332,8 +332,8 @@ DRIVERS.forEach(function(driverName) {
|
||||
// Skip binary(Blob) data tests if Blob isn't supported.
|
||||
if (typeof Blob === 'function') {
|
||||
it('saves binary (Blob) data', function(done) {
|
||||
var fileParts = ['<a id=\"a\"><b id=\"b\">hey!<\/b><\/a>'];
|
||||
var mimeString = 'text\/html';
|
||||
var fileParts = ['<a id="a"><b id="b">hey!</b></a>'];
|
||||
var mimeString = 'text/html';
|
||||
|
||||
var testBlob = createBlob(fileParts, { 'type' : mimeString });
|
||||
|
||||
@ -364,8 +364,8 @@ DRIVERS.forEach(function(driverName) {
|
||||
|
||||
if (typeof Blob === 'function') {
|
||||
it('saves binary (Blob) data, iterate back', function(done) {
|
||||
var fileParts = ['<a id=\"a\"><b id=\"b\">hey!<\/b><\/a>'];
|
||||
var mimeString = 'text\/html';
|
||||
var fileParts = ['<a id="a"><b id="b">hey!</b></a>'];
|
||||
var mimeString = 'text/html';
|
||||
|
||||
var testBlob = createBlob(fileParts, { 'type' : mimeString });
|
||||
|
||||
|
||||
@ -60,8 +60,8 @@ describe('Driver API', function() {
|
||||
|
||||
// These should be rejected in component builds but aren't.
|
||||
// TODO: Look into why.
|
||||
localforage.setDriver(localforage.INDEXEDDB).then(null,
|
||||
function() {
|
||||
localforage.setDriver(localforage.INDEXEDDB)
|
||||
.then(null, function() {
|
||||
expect(localforage.driver()).to.be(previousDriver);
|
||||
done();
|
||||
});
|
||||
@ -101,8 +101,8 @@ describe('Driver API', function() {
|
||||
var previousDriver = localforage.driver();
|
||||
expect(previousDriver).to.not.be(localforage.LOCALSTORAGE);
|
||||
|
||||
localforage.setDriver(localforage.LOCALSTORAGE).then(null,
|
||||
function() {
|
||||
localforage.setDriver(localforage.LOCALSTORAGE)
|
||||
.then(null, function() {
|
||||
expect(localforage.driver()).to.be(previousDriver);
|
||||
done();
|
||||
});
|
||||
@ -143,8 +143,8 @@ describe('Driver API', function() {
|
||||
var previousDriver = localforage.driver();
|
||||
expect(previousDriver).to.not.be(localforage.WEBSQL);
|
||||
|
||||
localforage.setDriver(localforage.WEBSQL).then(null,
|
||||
function() {
|
||||
localforage.setDriver(localforage.WEBSQL)
|
||||
.then(null, function() {
|
||||
expect(localforage.driver()).to.be(previousDriver);
|
||||
done();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user