@ribbon-studios/js-utils 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +29 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +29 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -43,7 +43,7 @@ async function retry(fn, n) {
|
|
|
43
43
|
}
|
|
44
44
|
class RibbonFetchError extends Error {
|
|
45
45
|
constructor({ status, content }) {
|
|
46
|
-
super(content);
|
|
46
|
+
super(content?.toString());
|
|
47
47
|
this.status = status;
|
|
48
48
|
this.content = content;
|
|
49
49
|
}
|
|
@@ -202,8 +202,36 @@ rfetch.delete = (url, options) => {
|
|
|
202
202
|
is2.error = error;
|
|
203
203
|
})(rfetch2.is || (rfetch2.is = {}));
|
|
204
204
|
})(rfetch || (rfetch = {}));
|
|
205
|
+
const _RibbonStorage = class _RibbonStorage {
|
|
206
|
+
static get(storage, key, defaultValue = null) {
|
|
207
|
+
try {
|
|
208
|
+
const value = storage.getItem(key);
|
|
209
|
+
if (!value) return defaultValue;
|
|
210
|
+
return JSON.parse(value);
|
|
211
|
+
} catch {
|
|
212
|
+
return defaultValue;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
static set(storage, key, value) {
|
|
216
|
+
if (value === void 0 || value === null) {
|
|
217
|
+
storage.removeItem(key);
|
|
218
|
+
} else {
|
|
219
|
+
storage.setItem(key, JSON.stringify(value));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
_RibbonStorage.local = {
|
|
224
|
+
get: _RibbonStorage.get.bind(Storage, localStorage),
|
|
225
|
+
set: _RibbonStorage.set.bind(Storage, localStorage)
|
|
226
|
+
};
|
|
227
|
+
_RibbonStorage.session = {
|
|
228
|
+
get: _RibbonStorage.get.bind(Storage, sessionStorage),
|
|
229
|
+
set: _RibbonStorage.set.bind(Storage, sessionStorage)
|
|
230
|
+
};
|
|
231
|
+
let RibbonStorage = _RibbonStorage;
|
|
205
232
|
exports.DelimiterType = DelimiterType;
|
|
206
233
|
exports.RibbonFetchError = RibbonFetchError;
|
|
234
|
+
exports.RibbonStorage = RibbonStorage;
|
|
207
235
|
exports.assert = assert;
|
|
208
236
|
exports.delay = delay;
|
|
209
237
|
exports.never = never;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -41,7 +41,7 @@ async function retry(fn, n) {
|
|
|
41
41
|
}
|
|
42
42
|
class RibbonFetchError extends Error {
|
|
43
43
|
constructor({ status, content }) {
|
|
44
|
-
super(content);
|
|
44
|
+
super(content?.toString());
|
|
45
45
|
this.status = status;
|
|
46
46
|
this.content = content;
|
|
47
47
|
}
|
|
@@ -200,9 +200,37 @@ rfetch.delete = (url, options) => {
|
|
|
200
200
|
is2.error = error;
|
|
201
201
|
})(rfetch2.is || (rfetch2.is = {}));
|
|
202
202
|
})(rfetch || (rfetch = {}));
|
|
203
|
+
const _RibbonStorage = class _RibbonStorage {
|
|
204
|
+
static get(storage, key, defaultValue = null) {
|
|
205
|
+
try {
|
|
206
|
+
const value = storage.getItem(key);
|
|
207
|
+
if (!value) return defaultValue;
|
|
208
|
+
return JSON.parse(value);
|
|
209
|
+
} catch {
|
|
210
|
+
return defaultValue;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
static set(storage, key, value) {
|
|
214
|
+
if (value === void 0 || value === null) {
|
|
215
|
+
storage.removeItem(key);
|
|
216
|
+
} else {
|
|
217
|
+
storage.setItem(key, JSON.stringify(value));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
_RibbonStorage.local = {
|
|
222
|
+
get: _RibbonStorage.get.bind(Storage, localStorage),
|
|
223
|
+
set: _RibbonStorage.set.bind(Storage, localStorage)
|
|
224
|
+
};
|
|
225
|
+
_RibbonStorage.session = {
|
|
226
|
+
get: _RibbonStorage.get.bind(Storage, sessionStorage),
|
|
227
|
+
set: _RibbonStorage.set.bind(Storage, sessionStorage)
|
|
228
|
+
};
|
|
229
|
+
let RibbonStorage = _RibbonStorage;
|
|
203
230
|
export {
|
|
204
231
|
DelimiterType,
|
|
205
232
|
RibbonFetchError,
|
|
233
|
+
RibbonStorage,
|
|
206
234
|
assert,
|
|
207
235
|
delay,
|
|
208
236
|
never,
|