-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
92 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './utils' | ||
export * from './libs' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { nanoid } from 'nanoid' | ||
|
||
export function isEmptyObject(obj: Object) { | ||
// because Object.keys(new Date()).length === 0; | ||
// we have to do some additional check | ||
return obj // 👈 null and undefined check | ||
&& Object.keys(obj).length === 0 | ||
&& Object.getPrototypeOf(obj) === Object.prototype | ||
} | ||
|
||
export function getRandomId() { | ||
return nanoid() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function atDevelopingPage() { | ||
return location.host.includes(':') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function throwError(type: string, message: string) { | ||
throw new Error(`[fdutil]: ${type} ${message}`) | ||
} | ||
|
||
export function throwWarning(type: string, message: string) { | ||
console.warn(`[fdutil]: ${type} ${message}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,3 @@ | ||
import { nanoid } from 'nanoid' | ||
|
||
/** | ||
* is developing runtime | ||
* @returns boolean | ||
*/ | ||
export function isDeveloping() { | ||
return location.host.includes(':') | ||
} | ||
|
||
/** 判断对象是否是空对象 */ | ||
export function isEmptyObject(obj: Object) { | ||
// because Object.keys(new Date()).length === 0; | ||
// we have to do some additional check | ||
return obj // 👈 null and undefined check | ||
&& Object.keys(obj).length === 0 | ||
&& Object.getPrototypeOf(obj) === Object.prototype | ||
} | ||
|
||
/** | ||
* generate random id | ||
* @returns string | ||
*/ | ||
export function getRandomId() { | ||
return nanoid() | ||
} | ||
|
||
/** | ||
* promise at dom env | ||
*/ | ||
export function promiseDomEnv() { | ||
if (!document) | ||
throw new Error('[fdutil error]: document is not defined, please use at browser, not node. dom is required') | ||
} | ||
|
||
/** get initStorageData */ | ||
export function initStorageData(key: string, defaultData: unknown, isSessionStorage = false) { | ||
const storage = isSessionStorage ? sessionStorage.getItem(key) : localStorage.getItem(key) | ||
return storage ? JSON.parse(storage) : defaultData | ||
} | ||
|
||
export function throwError(type: string, message: string) { | ||
throw new Error(`[fdutil]: ${type} ${message}`) | ||
} | ||
|
||
export function throwWarning(type: string, message: string) { | ||
console.warn(`[fdutil]: ${type} ${message}`) | ||
} | ||
export * from './dev' | ||
export * from './error' | ||
export * from './runtime' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function atDomEnv() { | ||
return Boolean(document) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { baseStorage, getStorageData, initLFInstance } from '../../packages/core' | ||
|
||
describe('core package', () => { | ||
test('error init lf', async () => { | ||
expect(() => baseStorage('test data', 'test key')).toThrowError('localforage please init localforage instance first') | ||
}) | ||
test('getInitStorageData', () => { | ||
expect(getStorageData('test', { a: 1 })).toEqual({ a: 1 }) | ||
}) | ||
}) | ||
test('inited if instance', () => { | ||
expect(initLFInstance('lfName')).toHaveProperty('INDEXEDDB') | ||
expect(initLFInstance('lfName')).toHaveProperty('WEBSQL') | ||
expect(initLFInstance('lfName')).toHaveProperty('LOCALSTORAGE') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters