File tree 4 files changed +71
-1
lines changed 4 files changed +71
-1
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * cookie 相关处理工具方法
3
+ */
4
+
5
+ export function cookieParse ( cookie = '' ) {
6
+ const obj : Record < string , string > = { } ;
7
+ if ( ! cookie && typeof document !== 'undefined' ) cookie = document . cookie ;
8
+
9
+ if ( typeof cookie === 'string' && cookie . length > 0 ) {
10
+ for ( const d of cookie . split ( ';' ) ) {
11
+ const [ key , value ] = d . split ( '=' ) . map ( d => d . trim ( ) ) ;
12
+ try {
13
+ if ( value != null ) obj [ key ] = decodeURIComponent ( value ) ;
14
+ } catch {
15
+ try {
16
+ obj [ key ] = unescape ( value ) ;
17
+ } catch {
18
+ obj [ key ] = value || '' ;
19
+ }
20
+ }
21
+ }
22
+ }
23
+ return obj ;
24
+ }
25
+
26
+ export function cookieStringfiy (
27
+ cookieObj : Record < string , string | number | boolean > ,
28
+ options : { filterKeys ?: string [ ] ; onlyKeys ?: string [ ] ; removeNil ?: boolean } = { }
29
+ ) {
30
+ return Object . keys ( cookieObj )
31
+ . filter ( key => {
32
+ if ( options . filterKeys ?. length && options . filterKeys . includes ( key ) ) return false ;
33
+ if ( options . onlyKeys ?. length && ! options . onlyKeys . includes ( key ) ) return false ;
34
+ if ( options . removeNil && ( cookieObj [ key ] == null || cookieObj [ key ] === '' ) ) return false ;
35
+ return true ;
36
+ } )
37
+ . map ( key => `${ key } =${ cookieObj [ key ] ? encodeURIComponent ( cookieObj [ key ] ) : '' } ` )
38
+ . join ( '; ' ) ;
39
+ }
Original file line number Diff line number Diff line change 1
1
export * from './async' ;
2
+ export * from './cookie' ;
2
3
export * from './date' ;
3
4
export * from './helper' ;
4
5
export * from './is' ;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * @Author : renxia
3
+ * @Date : 2023-03-23 23:05:16
4
+ * @LastEditors : renxia
5
+ * @LastEditTime : 2024-01-11 10:58:35
6
+ * @Description :
7
+ */
1
8
/**
2
- *
9
+ * url 格式化,返回一个 URL 对象
3
10
* @param url
4
11
* @param params 参数
5
12
* @param isRepalce 是否替换已存在于 url 中的参数
Original file line number Diff line number Diff line change
1
+ import { fs } from './fs-system' ;
2
+
1
3
/**
2
4
* 清除指定模块的 require 缓存(内存清理或实现热更新)
3
5
* @example
@@ -30,3 +32,24 @@ export function clearRequireCache(filePath: string) {
30
32
for ( const id of children ) clearRequireCache ( id ) ;
31
33
return true ;
32
34
}
35
+
36
+ const hotLoadCache = new Map < string , number > ( ) ;
37
+ // cache.delete(cache.keys().next().value);
38
+
39
+ /** require 热加载指定的文件 */
40
+ export function requireHotLoad ( filePath : string , force = false ) {
41
+ let needClearCache = force ;
42
+ let lastModified = 0 ;
43
+
44
+ if ( ! needClearCache ) {
45
+ lastModified = fs . statSync ( filePath ) . mtimeMs ;
46
+ needClearCache = hotLoadCache . get ( filePath ) !== lastModified ;
47
+ }
48
+
49
+ if ( needClearCache ) {
50
+ clearRequireCache ( filePath ) ;
51
+ hotLoadCache . set ( filePath , lastModified || fs . statSync ( filePath ) . mtimeMs ) ;
52
+ }
53
+
54
+ return require ( filePath ) ;
55
+ }
You can’t perform that action at this time.
0 commit comments