diff --git a/packages/react/package.json b/packages/react/package.json new file mode 100644 index 0000000..70e1641 --- /dev/null +++ b/packages/react/package.json @@ -0,0 +1,12 @@ +{ + "name": "react", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/packages/ui/src/utils/extra.ts b/packages/ui/src/utils/extra.ts new file mode 100644 index 0000000..70727c0 --- /dev/null +++ b/packages/ui/src/utils/extra.ts @@ -0,0 +1,11 @@ +export function extractKeysFromBraces(text: string) { + const regex = /\{\{\s*(.*?)\s*\}\}/g; + const keys: string[] = []; + let matches: RegExpExecArray | null; + + while ((matches = regex.exec(text)) !== null) { + keys.push(matches[1]); // 获取{{}}中间的key + } + + return keys; +} diff --git a/packages/ui/src/utils/history.ts b/packages/ui/src/utils/history.ts new file mode 100644 index 0000000..d5edef5 --- /dev/null +++ b/packages/ui/src/utils/history.ts @@ -0,0 +1,22 @@ +type To = string | Location; +type State = { + [key: string]: any; +} & T; +export const push = (to: To, state?: State, refresh = true) => { + const _history = window.history; + if (typeof to === 'string') { + // must key is default, so react navigate can work + _history.pushState({ key: 'default', usr: state }, '', to); + } else { + // const path = to.pathname; + _history.pushState({ key: 'default', usr: state }, '', to.pathname); + } + // must dispatch popstate event, so react navigate can work + refresh && window.dispatchEvent(new Event('popstate')); +}; +export const history = { + push, +}; + +// import { createBrowserHistory } from 'history'; +// export const history = createBrowserHistory(); \ No newline at end of file diff --git a/packages/ui/src/utils/is-null.ts b/packages/ui/src/utils/is-null.ts new file mode 100644 index 0000000..39d63f5 --- /dev/null +++ b/packages/ui/src/utils/is-null.ts @@ -0,0 +1,9 @@ +export const isObjectNull = (value: any) => { + if (value === null || value === undefined) { + return true; + } + if (JSON.stringify(value) === '{}') { + return true; + } + return false; +}; diff --git a/packages/ui/src/utils/nanoid.ts b/packages/ui/src/utils/nanoid.ts index bbd9f6e..28b3002 100644 --- a/packages/ui/src/utils/nanoid.ts +++ b/packages/ui/src/utils/nanoid.ts @@ -2,7 +2,13 @@ import { customAlphabet } from 'nanoid'; // 全小写的字母和数字 const alphabetLetter = 'abcdefghijklmnopqrstuvwxyz'; const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz'; +export const alphabetLetterAll = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + export const generateId6 = customAlphabet(alphabet, 6); +export const customNanoid = customAlphabet(alphabetLetterAll, 12); export const generateId = (size = 6) => { return 'b-' + generateId6(size); }; +export const generate = (size = 6) => { + return customNanoid(size); +};