smartunique/ts/index.ts

28 lines
745 B
TypeScript
Raw Permalink Normal View History

2018-10-06 13:38:55 +00:00
import * as plugins from './smartunique.plugins';
2017-07-14 16:53:10 +00:00
/**
* returns short strings that are unique to very high degree od certainty
*/
2020-03-05 20:39:44 +00:00
export const shortId = (): string => {
2018-10-06 13:38:55 +00:00
return plugins.shortid.generate();
};
2017-07-14 16:53:10 +00:00
/**
* returns strings that are unique to a very high degree of certainty
*/
2020-03-05 20:39:44 +00:00
export const uuid4 = (): string => {
return plugins.uuid.v4();
2018-10-06 13:38:55 +00:00
};
2017-07-14 16:53:10 +00:00
2020-03-05 20:39:44 +00:00
export const uuid5 = (customStringArg: string, namespaceArg = plugins.uuid.v5.DNS): string => {
return plugins.uuid.v5(customStringArg, namespaceArg);
};
2020-03-05 20:41:15 +00:00
export const uni = (prefix: string = 'uni') => {
return `${prefix}xxxxxxxxxxx`.replace(/[xy]/g, c => {
2020-03-05 20:39:44 +00:00
const r = (Math.random() * 16) | 0;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
2018-10-06 13:38:55 +00:00
};