Skip to content

Commit

Permalink
Merge pull request #8 from bchainhub/update/functions-04
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
rastislavcore authored Jan 22, 2025
2 parents a72c70d + c202514 commit ec41f3b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"private": false,
"sideEffects": false,
"scripts": {
"test": "npm run build && node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' ./node_modules/uvu/bin.js test",
"build": "tsc",
"test": "npm run build && node --no-deprecation --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' ./node_modules/uvu/bin.js test",
"build": "tsc --declaration --declarationDir ./dist",
"dev": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' --inspect src/index.ts"
},
"repository": {
Expand Down
23 changes: 17 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
type JSONObject = {
[key: string]: any;
[key: number]: never;
};

class Payto {
private static readonly BIC_REGEX = /^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/i;
private static readonly ROUTING_NUMBER_REGEX = /^(\d{9})$/;
Expand Down Expand Up @@ -108,8 +113,12 @@ class Payto {
return this.currency[0];
}

set asset(value: string | undefined) {
this.currency = [value];
set asset(value: string | null) {
if (value === null) {
this.currency = [null, null, null];
} else {
this.currency = [value, null, null];
}
}

get barcode(): string | null {
Expand Down Expand Up @@ -176,7 +185,7 @@ class Payto {
return result;
}

set currency(value: [string?, string?, number?]) {
set currency(value: Array<string | number | null | undefined>) {
const [token, fiat, amount] = value;
const amountValue = this.searchParams.get('amount');
let oldToken, oldValue;
Expand All @@ -189,7 +198,9 @@ class Payto {
oldValue = amountArray[0];
}
}
if (fiat) this.fiat = fiat.toLowerCase();
if (fiat && typeof fiat === 'string') {
this.fiat = fiat.toLowerCase();
}
if (token) {
this.amount = `${token}:${amount || (oldValue || '')}`;
} else if (amount) {
Expand Down Expand Up @@ -634,8 +645,8 @@ class Payto {
return this.url.toJSON();
}

toJSONObject(): object {
const obj: { [key: string]: any } = {};
toJSONObject(): JSONObject {
const obj: JSONObject = {};

// URL properties
if (this.port) obj.port = this.port;
Expand Down
16 changes: 13 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "Node16",
"target": "ESNext",
"module": "NodeNext",
"outDir": "./dist",
"strict": true,
"forceConsistentCasingInFileNames": true,
"removeComments": true,
"declaration": true,
"declarationDir": "./dist"
"declarationDir": "./dist",
"preserveConstEnums": true,
"useDefineForClassFields": true,
"stripInternal": true,
"verbatimModuleSyntax": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"exactOptionalPropertyTypes": true,
"noUncheckedIndexedAccess": false
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "test"]
Expand Down
11 changes: 8 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export type JSONObject = {
[key: string]: any;
[key: number]: never;
};

declare class Payto {
private url: URL;

Expand Down Expand Up @@ -33,8 +38,8 @@ declare class Payto {
get colorForeground(): string | null;
set colorForeground(value: string | null);

get currency(): [string, string?, string?];
set currency(value: [string, string?, string?]);
get currency(): [string | null, string | null];
set currency(value: Array<string | number | null | undefined>);

get deadline(): number | null;
set deadline(value: number | null);
Expand Down Expand Up @@ -120,7 +125,7 @@ declare class Payto {

toString(): string;
toJSON(): string;
toJSONObject(): Record<string, any>;
toJSONObject(): JSONObject;
}

export default Payto;

0 comments on commit ec41f3b

Please sign in to comment.