@8ms/helpers 2.3.30 → 2.3.32
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/dist/aws/s3/server/index.mjs +2 -2
- package/dist/axios/index.mjs +4 -4
- package/dist/number/index.d.mts +4 -11
- package/dist/number/index.mjs +17 -14
- package/dist/swr/client/index.d.mts +15 -15
- package/dist/swr/client/index.mjs +1 -1
- package/dist/url/server/index.mjs +2 -2
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { getFolder, getStringFromStream } from "../../../string/index.mjs";
|
|
|
4
4
|
import { n as isResponse200, t as getConfig } from "../../../server-Bwy4JI8Z.mjs";
|
|
5
5
|
import { getBrotliCompressed, getBrotliDecompressed, getGzipCompressed, getGzipDecompressed } from "../../../util/server/index.mjs";
|
|
6
6
|
import { z } from "zod/v4";
|
|
7
|
-
import
|
|
7
|
+
import axios from "axios";
|
|
8
8
|
|
|
9
9
|
//#region src/aws/s3/server/AwsS3Namespace.ts
|
|
10
10
|
var AwsS3Namespace = class extends BaseNamespace {
|
|
@@ -293,7 +293,7 @@ var AwsS3Namespace = class extends BaseNamespace {
|
|
|
293
293
|
*/
|
|
294
294
|
urlContents = async (bucket, key, url) => {
|
|
295
295
|
await this.ensureInit();
|
|
296
|
-
return
|
|
296
|
+
return axios(url, {
|
|
297
297
|
responseType: "arraybuffer",
|
|
298
298
|
responseEncoding: "binary"
|
|
299
299
|
}).then(async (response) => {
|
package/dist/axios/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as ApiResponseClass } from "../api-DGKJDAfb.mjs";
|
|
2
|
-
import
|
|
2
|
+
import axios from "axios";
|
|
3
3
|
|
|
4
4
|
//#region src/axios/deleteRequest.ts
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@ import get$1 from "axios";
|
|
|
7
7
|
* Can't use the function name delete as it's reserved
|
|
8
8
|
*/
|
|
9
9
|
const deleteRequest = async (url, config = {}) => {
|
|
10
|
-
return await
|
|
10
|
+
return await axios.delete(url, config).then(async (response) => {
|
|
11
11
|
if (void 0 !== response.data.body && void 0 !== response.data.error && void 0 !== response.data.state) return new ApiResponseClass(response.data);
|
|
12
12
|
else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(response.data);
|
|
13
13
|
return new ApiResponseClass().setToError(response.data, response.statusText);
|
|
@@ -22,7 +22,7 @@ const deleteRequest = async (url, config = {}) => {
|
|
|
22
22
|
* Make a GET request.
|
|
23
23
|
*/
|
|
24
24
|
const get = async (url, config = {}) => {
|
|
25
|
-
return await
|
|
25
|
+
return await axios.get(url, config).then(async (response) => {
|
|
26
26
|
if (void 0 !== response.data.body && void 0 !== response.data.error && void 0 !== response.data.state) return new ApiResponseClass(response.data);
|
|
27
27
|
else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(response.data);
|
|
28
28
|
return new ApiResponseClass().setToError(response.data, response.statusText);
|
|
@@ -37,7 +37,7 @@ const get = async (url, config = {}) => {
|
|
|
37
37
|
* Make a POST request.
|
|
38
38
|
*/
|
|
39
39
|
const post = async (url, data = {}, config = {}) => {
|
|
40
|
-
return await
|
|
40
|
+
return await axios.post(url, data, config).then(async (response) => {
|
|
41
41
|
if (void 0 !== response.data.body && void 0 !== response.data.error && void 0 !== response.data.state) return new ApiResponseClass(response.data);
|
|
42
42
|
else if (response.status >= 200 && response.status <= 299) return new ApiResponseClass().setToSuccess(response.data);
|
|
43
43
|
return new ApiResponseClass().setToError(response.data, response.statusText);
|
package/dist/number/index.d.mts
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
//#region src/number/
|
|
2
|
-
type FormatProps = {
|
|
3
|
-
compact?: boolean;
|
|
4
|
-
input: any;
|
|
5
|
-
locale?: string;
|
|
6
|
-
minDp?: number;
|
|
7
|
-
maxDp?: number;
|
|
8
|
-
};
|
|
1
|
+
//#region src/number/formatStandard.d.ts
|
|
9
2
|
/**
|
|
10
3
|
* Take a given number and format it.
|
|
11
4
|
*/
|
|
12
|
-
declare const
|
|
5
|
+
declare const formatStandard: (input: any, maxDp?: number, minDp?: number) => string;
|
|
13
6
|
//#endregion
|
|
14
7
|
//#region src/number/formatCurrency.d.ts
|
|
15
8
|
/**
|
|
16
9
|
* Use the International number formatting to return the currency value.
|
|
17
10
|
* https://www.freecodecamp.org/news/how-to-format-number-as-currency-in-javascript-one-line-of-code/
|
|
18
11
|
*/
|
|
19
|
-
declare const formatCurrency: (input: any,
|
|
12
|
+
declare const formatCurrency: (input: any, currency?: string, maxDp?: number, minDp?: number) => string;
|
|
20
13
|
//#endregion
|
|
21
14
|
//#region src/number/getDecimal.d.ts
|
|
22
15
|
/**
|
|
@@ -51,4 +44,4 @@ declare const getNumber: (input: any, defaultValue?: number) => number;
|
|
|
51
44
|
*/
|
|
52
45
|
declare const getPercentIncrease: (current: any, comparison: any, defaultValue: number) => number;
|
|
53
46
|
//#endregion
|
|
54
|
-
export {
|
|
47
|
+
export { formatCurrency, formatStandard, getDecimal, getNumber, getPercent, getPercentIncrease, getSafeDivide };
|
package/dist/number/index.mjs
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { n as getNumber, t as getDecimal } from "../getDecimal-CafxtLhH.mjs";
|
|
2
2
|
|
|
3
|
-
//#region src/number/
|
|
3
|
+
//#region src/number/formatStandard.ts
|
|
4
4
|
/**
|
|
5
5
|
* Take a given number and format it.
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
notation: compact ? "compact" : "standard"
|
|
7
|
+
const formatStandard = (input, maxDp, minDp) => {
|
|
8
|
+
const inputValue = getNumber(input);
|
|
9
|
+
const maximumDp = maxDp ?? 0;
|
|
10
|
+
const minimumDp = minDp ?? maxDp;
|
|
11
|
+
return Intl.NumberFormat(void 0, {
|
|
12
|
+
minimumFractionDigits: maximumDp,
|
|
13
|
+
maximumFractionDigits: minimumDp,
|
|
14
|
+
notation: "standard"
|
|
16
15
|
}).format(inputValue);
|
|
17
16
|
};
|
|
18
17
|
|
|
@@ -22,12 +21,16 @@ const format = (props) => {
|
|
|
22
21
|
* Use the International number formatting to return the currency value.
|
|
23
22
|
* https://www.freecodecamp.org/news/how-to-format-number-as-currency-in-javascript-one-line-of-code/
|
|
24
23
|
*/
|
|
25
|
-
const formatCurrency = (input,
|
|
24
|
+
const formatCurrency = (input, currency = "GBP", maxDp, minDp) => {
|
|
26
25
|
const value = Number(input);
|
|
27
26
|
const currencyClean = currency.toUpperCase().trim();
|
|
28
|
-
|
|
27
|
+
const maximumDp = maxDp ?? 2;
|
|
28
|
+
const minimumDp = minDp ?? maxDp;
|
|
29
|
+
let formatted = new Intl.NumberFormat(void 0, {
|
|
29
30
|
style: "currency",
|
|
30
|
-
currency: currencyClean
|
|
31
|
+
currency: currencyClean,
|
|
32
|
+
minimumFractionDigits: maximumDp,
|
|
33
|
+
maximumFractionDigits: minimumDp
|
|
31
34
|
}).format(value);
|
|
32
35
|
if ("USD" === currencyClean) formatted = formatted.replace("US$", "$");
|
|
33
36
|
return formatted;
|
|
@@ -72,4 +75,4 @@ const getPercentIncrease = (current, comparison, defaultValue) => {
|
|
|
72
75
|
};
|
|
73
76
|
|
|
74
77
|
//#endregion
|
|
75
|
-
export {
|
|
78
|
+
export { formatCurrency, formatStandard, getDecimal, getNumber, getPercent, getPercentIncrease, getSafeDivide };
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { c as ApiState } from "../../index-DW9yJLtI.mjs";
|
|
2
|
-
|
|
3
1
|
//#region src/swr/client/swr.d.ts
|
|
4
2
|
type Swr = {
|
|
5
3
|
data: any;
|
|
@@ -7,40 +5,42 @@ type Swr = {
|
|
|
7
5
|
skipFetch?: boolean;
|
|
8
6
|
url: string;
|
|
9
7
|
};
|
|
10
|
-
type SwrResponse = {
|
|
11
|
-
data
|
|
12
|
-
error: any;
|
|
8
|
+
type SwrResponse<TData = unknown> = {
|
|
9
|
+
data?: TData;
|
|
13
10
|
fetcher: Function;
|
|
11
|
+
error?: unknown;
|
|
14
12
|
mutate: {
|
|
15
|
-
data:
|
|
13
|
+
data: object;
|
|
16
14
|
url: string;
|
|
17
15
|
};
|
|
18
|
-
state?:
|
|
19
|
-
swrMutate:
|
|
16
|
+
state?: unknown;
|
|
17
|
+
swrMutate: unknown;
|
|
20
18
|
};
|
|
21
19
|
/**
|
|
22
|
-
* Check to see if a single SWR has
|
|
20
|
+
* Check to see if a single SWR has data and no error.
|
|
23
21
|
*/
|
|
24
|
-
declare const isData: (swr: SwrResponse) =>
|
|
22
|
+
declare const isData: <TData>(swr: SwrResponse<TData>) => swr is SwrResponse<TData> & {
|
|
23
|
+
data: TData;
|
|
24
|
+
};
|
|
25
25
|
/**
|
|
26
26
|
* Check to see if a single SWR is loading.
|
|
27
27
|
*/
|
|
28
|
-
declare const isLoading: (swr: SwrResponse) => boolean;
|
|
28
|
+
declare const isLoading: <TData>(swr: SwrResponse<TData>) => boolean;
|
|
29
29
|
/**
|
|
30
30
|
* Check to see if a single SWR has an error.
|
|
31
31
|
*/
|
|
32
|
-
declare const isError: (swr: SwrResponse) => boolean;
|
|
32
|
+
declare const isError: <TData>(swr: SwrResponse<TData>) => boolean;
|
|
33
33
|
/**
|
|
34
34
|
* Are any of SWRs loading
|
|
35
35
|
*/
|
|
36
|
-
declare const isAnyLoading: (swrs: SwrResponse[]) => boolean;
|
|
36
|
+
declare const isAnyLoading: <TData>(swrs: SwrResponse<TData>[]) => boolean;
|
|
37
37
|
/**
|
|
38
38
|
* Are any of the SWRs marked as an error.
|
|
39
39
|
*/
|
|
40
|
-
declare const isAnyError: (swrs: SwrResponse[]) => boolean;
|
|
40
|
+
declare const isAnyError: <TData>(swrs: SwrResponse<TData>[]) => boolean;
|
|
41
41
|
/**
|
|
42
42
|
* Are all SWRs data ready.
|
|
43
43
|
*/
|
|
44
|
-
declare const isAllData: (swrs: SwrResponse[]) => boolean;
|
|
44
|
+
declare const isAllData: <TData>(swrs: SwrResponse<TData>[]) => boolean;
|
|
45
45
|
//#endregion
|
|
46
46
|
export { Swr, SwrResponse, isAllData, isAnyError, isAnyLoading, isData, isError, isLoading };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/swr/client/swr.ts
|
|
2
2
|
/**
|
|
3
|
-
* Check to see if a single SWR has
|
|
3
|
+
* Check to see if a single SWR has data and no error.
|
|
4
4
|
*/
|
|
5
5
|
const isData = (swr) => (void 0 === swr.error || null === swr.error) && "undefined" !== typeof swr.data && "undefined" !== swr.data;
|
|
6
6
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDirectory } from "../../file/server/index.mjs";
|
|
2
|
-
import
|
|
2
|
+
import axios from "axios";
|
|
3
3
|
|
|
4
4
|
//#region src/url/server/writeUrlContents.ts
|
|
5
5
|
/**
|
|
@@ -11,7 +11,7 @@ const writeUrlContents = async (filePath, url) => {
|
|
|
11
11
|
const fs = await import("fs-extra");
|
|
12
12
|
await createDirectory(filePath);
|
|
13
13
|
const writer = fs.createWriteStream(filePath);
|
|
14
|
-
await
|
|
14
|
+
await axios({
|
|
15
15
|
method: "get",
|
|
16
16
|
url,
|
|
17
17
|
responseType: "stream"
|