23 lines
673 B
TypeScript
23 lines
673 B
TypeScript
/*
|
|
* This file is part of the kernelstudio package.
|
|
*
|
|
* (c) 2014-2025 zlin <admin@kernelstudio.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE file
|
|
* that was distributed with this source code.
|
|
*/
|
|
|
|
import type { NullableString } from '@/types';
|
|
|
|
export const generateKey = (type: string | null = ''): string => {
|
|
return `${type ? (type + '_') : ''}${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`
|
|
.replace('-', '_').toLowerCase();
|
|
};
|
|
|
|
export const substring = (s: NullableString, n: number = 10, p: string = '...') => {
|
|
if (s) {
|
|
return s.length > n ? (s.substring(0, n) + p) : s;
|
|
}
|
|
return s;
|
|
};
|