Skip to content

Commit

Permalink
added ESM support
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Jul 31, 2022
1 parent fa63e18 commit e917b18
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"format": "npx prettier --arrow-parens=avoid --print-width=160 --trailing-comma=none --write *.js *.ts",
"perf": "node perf.js",
"prepublishOnly": "npx pkg-ok",
"test": "node test.js"
"test": "npm run test:js && npm run test:ts",
"test:js": "node test.js",
"test:ts": "npx ts-node ./test.ts"
},
"repository": {
"type": "git",
Expand Down
19 changes: 18 additions & 1 deletion preciso.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export function absolute(n: string): string;
export function add(a: string, b: string): string;
export function ceil(n: string): string;
export function compare(a: string, b: string): "<" | ">" | "=";
export function ceil(n: string): string;
export function divide(dividend: string, divisor: string, options?: { max_decimal_digits: number; ellipsis: boolean }): string;
export function floor(n: string): string;

Expand All @@ -18,3 +17,21 @@ export function remainder(dividend: string, divisor: string): string;
export function sign(n: string): string;
export function subtract(a: string, b: string): string;
export function truncate(n: string);

declare const preciso: {
absolute: typeof absolute;
add: typeof add;
ceil: typeof ceil;
compare: typeof compare;
divide: typeof divide;
floor: typeof floor;
max: typeof max;
min: typeof min;
multiply: typeof multiply;
pow: typeof pow;
remainder: typeof remainder;
sign: typeof sign;
subtract: typeof subtract;
truncate: typeof truncate;
};
export default preciso;
5 changes: 4 additions & 1 deletion preciso.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ if (typeof define === "function" && define.amd)
define(function () {
return module_exports;
});
if (typeof module === "object") module.exports = module_exports;
if (typeof module === "object") {
module.exports = module_exports;
module.exports.default = module_exports;
}
if (typeof window === "object") window.preciso = module_exports;
if (typeof self === "object") self.preciso = module_exports;
12 changes: 12 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import test from "flug";

import preciso from "./preciso";
import { divide } from "./preciso";

test("import preciso", ({ eq }) => {
eq(preciso.add("1", "2"), "3");
});

test("import { divide } from ", ({ eq }) => {
eq(divide("1", "2"), "0.5");
});

0 comments on commit e917b18

Please sign in to comment.