Skip to content

Commit

Permalink
feat: 增加guid工具
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan Heng committed Aug 2, 2023
1 parent 8dea264 commit 67cfd9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export * from './async-queue';

export * from './string';

export * from './uid';

export const toLine = (name: string = '') => name.replace(/\B([A-Z])/g, '-$1').toLowerCase();

export function replacePropertyWithValue(obj: Record<string | number | symbol, any>, value: any, newValue: any) {
Expand Down
9 changes: 9 additions & 0 deletions packages/utils/src/uid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const DIGIT: number = 12;

export const guid = (digit: number = DIGIT): string => {
return 'x'.repeat(digit).replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
};

0 comments on commit 67cfd9c

Please sign in to comment.