@gateweb/react-utils 0.0.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -1
- package/dist/cjs/index.d.ts +24 -1
- package/dist/cjs/index.js +28 -0
- package/dist/es/index.d.mts +24 -1
- package/dist/es/index.mjs +27 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,74 @@
|
|
|
1
1
|
# react-utils
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
**_react-utils_** is a collection of utility functions for GateWeb's React projects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @gateweb/react-utils
|
|
9
|
+
# or
|
|
10
|
+
yarn add @gateweb/react-utils
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @gateweb/react-utils
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { formatAmount } from '@gateweb/react-utils';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## How to Release a New Version
|
|
22
|
+
|
|
23
|
+
### Manually Bump the Version
|
|
24
|
+
|
|
25
|
+
1. Update the version in `package.json`
|
|
26
|
+
|
|
27
|
+
```diff
|
|
28
|
+
# e.g. bump the version from 0.1.0 to 0.1.1
|
|
29
|
+
{
|
|
30
|
+
"name": "@gateweb/react-utils",
|
|
31
|
+
- "version": "0.1.0"
|
|
32
|
+
+ "version": "0.1.1"
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
2. Install the dependencies and build the package
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pnpm install
|
|
40
|
+
pnpm build
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
3. login to npm
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
# make sure you have an npm account
|
|
47
|
+
pnpm login
|
|
48
|
+
# npm notice Log in on https://registry.npmjs.org/
|
|
49
|
+
# Login at:
|
|
50
|
+
# https://www.npmjs.com/login?next=/login/cli/390e514d-7aa5-4ee7-a13a-b17e6dd64518
|
|
51
|
+
# Press ENTER to open in the browser...
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
4. Publish the package
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
pnpm publish --access public --no-git-checks
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
5. Check the published package on npmjs.com
|
|
61
|
+
|
|
62
|
+
[@gateweb/react-utils](https://www.npmjs.com/package/@gateweb/react-utils)
|
|
63
|
+
|
|
64
|
+
### Automatically Bump the Version
|
|
65
|
+
|
|
66
|
+
- When you merge a pull request to the `main` branch, the GitHub Action will automatically bump the version and publish the package to npm.
|
|
67
|
+
|
|
68
|
+
- The version will follow the [Semantic Versioning](https://semver.org/) rules.
|
|
69
|
+
|
|
70
|
+
## Notes
|
|
71
|
+
|
|
72
|
+
- You should use `pnpm` to develop this package.
|
|
73
|
+
- This package is written in TypeScript and supports TypeScript out of the box.
|
|
74
|
+
- This package is built with [bunchee](https://github.com/huozhi/bunchee) which is a zero-config build tool for TypeScript packages based on Rollup.
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -268,6 +268,23 @@ declare const createEnumLikeObject: <T extends Record<string, {
|
|
|
268
268
|
key: string;
|
|
269
269
|
}[] : (value: TExtractValueType<T, "value">) => string | TExtractValueType<T, "value">; };
|
|
270
270
|
|
|
271
|
+
/**
|
|
272
|
+
* simulate a fake api request
|
|
273
|
+
*
|
|
274
|
+
* @param returnValue the value to return
|
|
275
|
+
* @param result the result of the request
|
|
276
|
+
* @param time the time to wait before resolving
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
*
|
|
280
|
+
* const result = await fakeApi({ foo: 'bar' });
|
|
281
|
+
* console.log(result); // { result: true, data: { foo: 'bar' } }
|
|
282
|
+
*/
|
|
283
|
+
declare const fakeApi: <T>(returnValue: T, result?: boolean, time?: number) => Promise<{
|
|
284
|
+
result: boolean;
|
|
285
|
+
data: T;
|
|
286
|
+
}>;
|
|
287
|
+
|
|
271
288
|
/**
|
|
272
289
|
* 檢查檔案是否為合法的 MIME 類型
|
|
273
290
|
*
|
|
@@ -632,6 +649,12 @@ declare const validTaxId: (taxId: string) => boolean;
|
|
|
632
649
|
*/
|
|
633
650
|
declare const validateDateString: (dateString: string, format: string) => boolean;
|
|
634
651
|
|
|
652
|
+
/**
|
|
653
|
+
* Wait for a given amount of time
|
|
654
|
+
* @param ms time to wait in milliseconds
|
|
655
|
+
*/
|
|
656
|
+
declare const wait: (ms: number) => void;
|
|
657
|
+
|
|
635
658
|
/**
|
|
636
659
|
* Downloads a file from a given source.
|
|
637
660
|
*
|
|
@@ -665,4 +688,4 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
|
|
|
665
688
|
*/
|
|
666
689
|
declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
|
|
667
690
|
|
|
668
|
-
export { type TCountdownActions, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, createEnumLikeObject, debounce, downloadFile, extractEnumLikeObject, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, validTaxId, validateDateString, validateFileType };
|
|
691
|
+
export { type TCountdownActions, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, createEnumLikeObject, debounce, downloadFile, extractEnumLikeObject, fakeApi, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, validTaxId, validateDateString, validateFileType, wait };
|
package/dist/cjs/index.js
CHANGED
|
@@ -379,6 +379,26 @@ const transformObjectKey = (obj, transformFunName)=>{
|
|
|
379
379
|
};
|
|
380
380
|
};
|
|
381
381
|
|
|
382
|
+
/**
|
|
383
|
+
* simulate a fake api request
|
|
384
|
+
*
|
|
385
|
+
* @param returnValue the value to return
|
|
386
|
+
* @param result the result of the request
|
|
387
|
+
* @param time the time to wait before resolving
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
*
|
|
391
|
+
* const result = await fakeApi({ foo: 'bar' });
|
|
392
|
+
* console.log(result); // { result: true, data: { foo: 'bar' } }
|
|
393
|
+
*/ const fakeApi = (returnValue, result = true, time = 1000)=>new Promise((resolve)=>{
|
|
394
|
+
setTimeout(()=>{
|
|
395
|
+
resolve({
|
|
396
|
+
result,
|
|
397
|
+
data: returnValue
|
|
398
|
+
});
|
|
399
|
+
}, time);
|
|
400
|
+
});
|
|
401
|
+
|
|
382
402
|
/**
|
|
383
403
|
* 檢查檔案是否為合法的 MIME 類型
|
|
384
404
|
*
|
|
@@ -746,6 +766,12 @@ message) {
|
|
|
746
766
|
* formatString('123456', 1, 4) // '1****6'
|
|
747
767
|
*/ const formatStarMask = (str, n, m)=>str.slice(0, n) + '*'.repeat(m - n + 1) + str.slice(m + 1);
|
|
748
768
|
|
|
769
|
+
/**
|
|
770
|
+
* Wait for a given amount of time
|
|
771
|
+
* @param ms time to wait in milliseconds
|
|
772
|
+
*/ const wait = (ms)=>{
|
|
773
|
+
};
|
|
774
|
+
|
|
749
775
|
exports.useCountdown = useCountdownClient.useCountdown;
|
|
750
776
|
exports.downloadFile = downloadClient.downloadFile;
|
|
751
777
|
exports.getLocalStorage = webStorageClient.getLocalStorage;
|
|
@@ -758,6 +784,7 @@ exports.camelString2SnakeString = camelString2SnakeString;
|
|
|
758
784
|
exports.createEnumLikeObject = createEnumLikeObject;
|
|
759
785
|
exports.debounce = debounce;
|
|
760
786
|
exports.extractEnumLikeObject = extractEnumLikeObject;
|
|
787
|
+
exports.fakeApi = fakeApi;
|
|
761
788
|
exports.formatAmount = formatAmount;
|
|
762
789
|
exports.formatStarMask = formatStarMask;
|
|
763
790
|
exports.generatePeriodArray = generatePeriodArray;
|
|
@@ -793,3 +820,4 @@ exports.throttle = throttle;
|
|
|
793
820
|
exports.validTaxId = validTaxId;
|
|
794
821
|
exports.validateDateString = validateDateString;
|
|
795
822
|
exports.validateFileType = validateFileType;
|
|
823
|
+
exports.wait = wait;
|
package/dist/es/index.d.mts
CHANGED
|
@@ -268,6 +268,23 @@ declare const createEnumLikeObject: <T extends Record<string, {
|
|
|
268
268
|
key: string;
|
|
269
269
|
}[] : (value: TExtractValueType<T, "value">) => string | TExtractValueType<T, "value">; };
|
|
270
270
|
|
|
271
|
+
/**
|
|
272
|
+
* simulate a fake api request
|
|
273
|
+
*
|
|
274
|
+
* @param returnValue the value to return
|
|
275
|
+
* @param result the result of the request
|
|
276
|
+
* @param time the time to wait before resolving
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
*
|
|
280
|
+
* const result = await fakeApi({ foo: 'bar' });
|
|
281
|
+
* console.log(result); // { result: true, data: { foo: 'bar' } }
|
|
282
|
+
*/
|
|
283
|
+
declare const fakeApi: <T>(returnValue: T, result?: boolean, time?: number) => Promise<{
|
|
284
|
+
result: boolean;
|
|
285
|
+
data: T;
|
|
286
|
+
}>;
|
|
287
|
+
|
|
271
288
|
/**
|
|
272
289
|
* 檢查檔案是否為合法的 MIME 類型
|
|
273
290
|
*
|
|
@@ -632,6 +649,12 @@ declare const validTaxId: (taxId: string) => boolean;
|
|
|
632
649
|
*/
|
|
633
650
|
declare const validateDateString: (dateString: string, format: string) => boolean;
|
|
634
651
|
|
|
652
|
+
/**
|
|
653
|
+
* Wait for a given amount of time
|
|
654
|
+
* @param ms time to wait in milliseconds
|
|
655
|
+
*/
|
|
656
|
+
declare const wait: (ms: number) => void;
|
|
657
|
+
|
|
635
658
|
/**
|
|
636
659
|
* Downloads a file from a given source.
|
|
637
660
|
*
|
|
@@ -665,4 +688,4 @@ declare const getLocalStorage: <T>(key: string, deCode?: boolean) => T | undefin
|
|
|
665
688
|
*/
|
|
666
689
|
declare const setLocalStorage: (key: string, value: Record<string, any>, enCode?: boolean) => void;
|
|
667
690
|
|
|
668
|
-
export { type TCountdownActions, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, createEnumLikeObject, debounce, downloadFile, extractEnumLikeObject, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, validTaxId, validateDateString, validateFileType };
|
|
691
|
+
export { type TCountdownActions, adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, createEnumLikeObject, debounce, downloadFile, extractEnumLikeObject, fakeApi, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getLocalStorage, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, setLocalStorage, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, useCountdown, validTaxId, validateDateString, validateFileType, wait };
|
package/dist/es/index.mjs
CHANGED
|
@@ -373,6 +373,26 @@ const transformObjectKey = (obj, transformFunName)=>{
|
|
|
373
373
|
};
|
|
374
374
|
};
|
|
375
375
|
|
|
376
|
+
/**
|
|
377
|
+
* simulate a fake api request
|
|
378
|
+
*
|
|
379
|
+
* @param returnValue the value to return
|
|
380
|
+
* @param result the result of the request
|
|
381
|
+
* @param time the time to wait before resolving
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
*
|
|
385
|
+
* const result = await fakeApi({ foo: 'bar' });
|
|
386
|
+
* console.log(result); // { result: true, data: { foo: 'bar' } }
|
|
387
|
+
*/ const fakeApi = (returnValue, result = true, time = 1000)=>new Promise((resolve)=>{
|
|
388
|
+
setTimeout(()=>{
|
|
389
|
+
resolve({
|
|
390
|
+
result,
|
|
391
|
+
data: returnValue
|
|
392
|
+
});
|
|
393
|
+
}, time);
|
|
394
|
+
});
|
|
395
|
+
|
|
376
396
|
/**
|
|
377
397
|
* 檢查檔案是否為合法的 MIME 類型
|
|
378
398
|
*
|
|
@@ -740,4 +760,10 @@ message) {
|
|
|
740
760
|
* formatString('123456', 1, 4) // '1****6'
|
|
741
761
|
*/ const formatStarMask = (str, n, m)=>str.slice(0, n) + '*'.repeat(m - n + 1) + str.slice(m + 1);
|
|
742
762
|
|
|
743
|
-
|
|
763
|
+
/**
|
|
764
|
+
* Wait for a given amount of time
|
|
765
|
+
* @param ms time to wait in milliseconds
|
|
766
|
+
*/ const wait = (ms)=>{
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
export { adToRocEra, camelCase2PascalCase, camelCase2SnakeCase, camelString2PascalString, camelString2SnakeString, createEnumLikeObject, debounce, extractEnumLikeObject, fakeApi, formatAmount, formatStarMask, generatePeriodArray, getCurrentPeriod, getMimeType, invariant, isChinese, isDateString, isDateTimeString, isEmail, isEnglish, isNonZeroStart, isNumber, isNumberAtLeastN, isNumberN, isNumberNM, isServer, isTWMobile, isTWPhone, isTimeString, omit, omitByValue, pascalCase2CamelCase, pascalCase2SnakeCase, pascalString2CamelString, pascalString2SnakeString, rocEraToAd, snakeCase2CamelCase, snakeCase2PascalCase, snakeString2CamelString, snakeString2PascalString, throttle, validTaxId, validateDateString, validateFileType, wait };
|