@8ms/helpers 2.3.29 → 2.3.31

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.
@@ -2,13 +2,13 @@
2
2
  /**
3
3
  * Decrypt an encoding string using a salt.
4
4
  */
5
- declare const getDecrypt: (appSalt: string, input: string, salt: string) => Promise<string>;
5
+ declare const getDecrypt: (appSalt: string, input: string, salt: string) => string;
6
6
  //#endregion
7
7
  //#region src/crypto/getEncrypt.d.ts
8
8
  /**
9
9
  * Encrypt an encoding string using a salt.
10
10
  */
11
- declare const getEncrypt: (appSalt: string, input: string, salt: string) => Promise<string>;
11
+ declare const getEncrypt: (appSalt: string, input: string, salt: string) => string;
12
12
  //#endregion
13
13
  //#region src/crypto/getRandom.d.ts
14
14
  /**
@@ -20,6 +20,6 @@ declare const getRandom: (length: number) => string;
20
20
  /**
21
21
  * Encrypt a string using sha256.
22
22
  */
23
- declare const getSha256: (input: any) => Promise<string>;
23
+ declare const getSha256: (input: any) => string;
24
24
  //#endregion
25
25
  export { getDecrypt, getEncrypt, getRandom, getSha256 };
@@ -5,7 +5,7 @@ import { getString } from "../string/index.mjs";
5
5
  /**
6
6
  * Decrypt an encoding string using a salt.
7
7
  */
8
- const getDecrypt = async (appSalt, input, salt) => {
8
+ const getDecrypt = (appSalt, input, salt) => {
9
9
  const crypto = __require("crypto");
10
10
  const ALGORITHM = "aes-256-cbc";
11
11
  const customSalt = `${appSalt}-${salt}`;
@@ -22,7 +22,7 @@ const getDecrypt = async (appSalt, input, salt) => {
22
22
  /**
23
23
  * Encrypt an encoding string using a salt.
24
24
  */
25
- const getEncrypt = async (appSalt, input, salt) => {
25
+ const getEncrypt = (appSalt, input, salt) => {
26
26
  const crypto = __require("crypto");
27
27
  const ALGORITHM = "aes-256-cbc";
28
28
  const customSalt = `${appSalt}-${salt}`;
@@ -47,7 +47,7 @@ const getRandom = (length) => {
47
47
  /**
48
48
  * Encrypt a string using sha256.
49
49
  */
50
- const getSha256 = async (input) => {
50
+ const getSha256 = (input) => {
51
51
  const crypto = __require("crypto");
52
52
  const inputString = getString(input);
53
53
  return crypto.createHash("sha256").update(inputString).digest("hex");
@@ -1,22 +1,15 @@
1
- //#region src/number/format.d.ts
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 format: (props: FormatProps) => string;
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, locale?: string, currency?: string) => string;
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 { format, formatCurrency, getDecimal, getNumber, getPercent, getPercentIncrease, getSafeDivide };
47
+ export { formatCurrency, formatStandard, getDecimal, getNumber, getPercent, getPercentIncrease, getSafeDivide };
@@ -1,18 +1,17 @@
1
1
  import { n as getNumber, t as getDecimal } from "../getDecimal-CafxtLhH.mjs";
2
2
 
3
- //#region src/number/format.ts
3
+ //#region src/number/formatStandard.ts
4
4
  /**
5
5
  * Take a given number and format it.
6
6
  */
7
- const format = (props) => {
8
- const minDp = props?.minDp ?? 0;
9
- const maxDp = props?.maxDp ?? 2;
10
- const compact = props?.compact || false;
11
- const inputValue = getNumber(props.input);
12
- return Intl.NumberFormat(props?.locale || "en-GB", {
13
- minimumFractionDigits: minDp,
14
- maximumFractionDigits: maxDp,
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, locale = "en-GB", currency = "GBP") => {
24
+ const formatCurrency = (input, currency = "GBP", maxDp, minDp) => {
26
25
  const value = Number(input);
27
26
  const currencyClean = currency.toUpperCase().trim();
28
- let formatted = new Intl.NumberFormat(locale, {
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 { format, formatCurrency, getDecimal, getNumber, getPercent, getPercentIncrease, getSafeDivide };
78
+ export { formatCurrency, formatStandard, getDecimal, getNumber, getPercent, getPercentIncrease, getSafeDivide };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.3.29",
4
+ "version": "2.3.31",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"