MCPcopy
hub / github.com/localForage/localForage / LocalForage

Class LocalForage

src/localforage.js:85–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85class LocalForage {
86 constructor(options) {
87 for (let driverTypeKey in DefaultDrivers) {
88 if (DefaultDrivers.hasOwnProperty(driverTypeKey)) {
89 const driver = DefaultDrivers[driverTypeKey];
90 const driverName = driver._driver;
91 this[driverTypeKey] = driverName;
92
93 if (!DefinedDrivers[driverName]) {
94 // we don't need to wait for the promise,
95 // since the default drivers can be defined
96 // in a blocking manner
97 this.defineDriver(driver);
98 }
99 }
100 }
101
102 this._defaultConfig = extend({}, DefaultConfig);
103 this._config = extend({}, this._defaultConfig, options);
104 this._driverSet = null;
105 this._initDriver = null;
106 this._ready = false;
107 this._dbInfo = null;
108
109 this._wrapLibraryMethodsWithReady();
110 this.setDriver(this._config.driver).catch(() => {});
111 }
112
113 // Set any config values for localForage; can be called anytime before
114 // the first API call (e.g. `getItem`, `setItem`).
115 // We loop through options so we don't overwrite existing config
116 // values.
117 config(options) {
118 // If the options argument is an object, we use it to set values.
119 // Otherwise, we return either a specified config value or all
120 // config values.
121 if (typeof options === 'object') {
122 // If localforage is ready and fully initialized, we can't set
123 // any new configuration values. Instead, we return an error.
124 if (this._ready) {
125 return new Error(
126 "Can't call config() after localforage " + 'has been used.'
127 );
128 }
129
130 for (let i in options) {
131 if (i === 'storeName') {
132 options[i] = options[i].replace(/\W/g, '_');
133 }
134
135 if (i === 'version' && typeof options[i] !== 'number') {
136 return new Error('Database version must be a number.');
137 }
138
139 this._config[i] = options[i];
140 }
141
142 // after all config options are set and

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…