@@ -16,26 +16,21 @@ export type PickData<T> = Omit<T, TypeKeys<T, Function>>;
1616
1717export type DataKeys < T > = Exclude < keyof T , TypeKeys < T , Function > > ;
1818
19- export function likeNull ( value ?: any ) {
20- return ! ( value != null ) || Number . isNaN ( value ) ;
21- }
19+ export const likeNull = ( value ?: any ) =>
20+ ! ( value != null ) || Number . isNaN ( value ) ;
2221
23- export function isEmpty ( value ?: any ) {
24- return (
25- likeNull ( value ) ||
26- ( typeof value === 'object' ? ! Object . keys ( value ) . length : value === '' )
27- ) ;
28- }
22+ export const isEmpty = ( value ?: any ) =>
23+ likeNull ( value ) ||
24+ ( typeof value === 'object' ? ! Object . keys ( value ) . length : value === '' ) ;
2925
3026/**
3127 * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag }
3228 */
3329export const classNameOf = ( data : any ) : string =>
3430 Object . prototype . toString . call ( data ) . slice ( 8 , - 1 ) ;
3531
36- export function assertInheritance ( Sub : Function , Super : Function ) {
37- return Sub . prototype instanceof Super ;
38- }
32+ export const assertInheritance = ( Sub : Function , Super : Function ) =>
33+ Sub . prototype instanceof Super ;
3934
4035export function proxyPrototype < T extends object > (
4136 target : T ,
@@ -62,29 +57,24 @@ export function proxyPrototype<T extends object>(
6257 Object . setPrototypeOf ( target , prototypeProxy ) ;
6358}
6459
65- export function isUnsafeNumeric ( raw : string ) {
66- return (
67- / ^ [ \d . ] + $ / . test ( raw ) &&
68- raw . localeCompare ( Number . MAX_SAFE_INTEGER + '' , undefined , {
69- numeric : true
70- } ) > 0
71- ) ;
72- }
60+ export const isUnsafeNumeric = ( raw : string ) =>
61+ / ^ [ \d . ] + $ / . test ( raw ) &&
62+ raw . localeCompare ( Number . MAX_SAFE_INTEGER + '' , undefined , {
63+ numeric : true
64+ } ) > 0 ;
7365
74- export function byteLength ( raw : string ) {
75- return raw . replace ( / [ ^ \u0021 - \u007e \uff61 - \uffef ] / g, 'xx' ) . length ;
76- }
66+ export const byteLength = ( raw : string ) =>
67+ raw . replace ( / [ ^ \u0021 - \u007e \uff61 - \uffef ] / g, 'xx' ) . length ;
7768
7869export type HyphenCase < T extends string > = T extends `${infer L } ${infer R } `
7970 ? `${L extends Uppercase < L > ? `-${Lowercase < L > } ` : L } ${HyphenCase < R > } `
8071 : T ;
81- export function toHyphenCase ( raw : string ) {
82- return raw . replace (
72+ export const toHyphenCase = ( raw : string ) =>
73+ raw . replace (
8374 / [ A - Z ] + | [ ^ A - Z a - z ] [ A - Z a - z ] / g,
8475 ( match , offset ) =>
8576 `${ offset ? '-' : '' } ${ ( match [ 1 ] || match [ 0 ] ) . toLowerCase ( ) } `
8677 ) ;
87- }
8878
8979export type CamelCase <
9080 Raw extends string ,
@@ -94,23 +84,40 @@ export type CamelCase<
9484 ? `${Capitalize < L > } ${Capitalize < CamelCase < R > > } `
9585 : `${Capitalize < Raw > } `
9686> ;
97- export function toCamelCase ( raw : string , large = false ) {
98- return raw . replace ( / ^ [ A - Z a - z ] | [ ^ A - Z a - z ] [ A - Z a - z ] / g, ( match , offset ) =>
87+ export const toCamelCase = ( raw : string , large = false ) =>
88+ raw . replace ( / ^ [ A - Z a - z ] | [ ^ A - Z a - z ] [ A - Z a - z ] / g, ( match , offset ) =>
9989 offset || large
10090 ? ( match [ 1 ] || match [ 0 ] ) . toUpperCase ( )
10191 : match . toLowerCase ( )
10292 ) ;
103- }
10493
105- export function uniqueID ( ) {
106- return ( Date . now ( ) + parseInt ( ( Math . random ( ) + '' ) . slice ( 2 ) ) ) . toString ( 36 ) ;
107- }
94+ export const uniqueID = ( ) =>
95+ ( Date . now ( ) + parseInt ( ( Math . random ( ) + '' ) . slice ( 2 ) ) ) . toString ( 36 ) ;
10896
109- export function objectFrom < V , K extends string > ( values : V [ ] , keys : K [ ] ) {
110- return Object . fromEntries (
97+ /**
98+ * Encode string to Base64 with Unicode support
99+ *
100+ * @param input - String to encode
101+ * @returns Base64 encoded string
102+ */
103+ export const encodeBase64 = ( input : string ) =>
104+ btoa ( String . fromCharCode ( ...new TextEncoder ( ) . encode ( input ) ) ) ;
105+
106+ /**
107+ * Decode Base64 string with Unicode support
108+ *
109+ * @param input - Base64 encoded string to decode
110+ * @returns Decoded Unicode string
111+ */
112+ export const decodeBase64 = ( input : string ) =>
113+ new TextDecoder ( ) . decode (
114+ Uint8Array . from ( atob ( input ) , char => char . charCodeAt ( 0 ) )
115+ ) ;
116+
117+ export const objectFrom = < V , K extends string > ( values : V [ ] , keys : K [ ] ) =>
118+ Object . fromEntries (
111119 values . map ( ( value , index ) => [ keys [ index ] , value ] )
112120 ) as Record < K , V > ;
113- }
114121
115122export enum DiffStatus {
116123 Old = - 1 ,
0 commit comments