money-ts
Version:
TypeScript library for type-safe and lossless encoding and manipulation of world currencies and precious metals
61 lines • 1.6 kB
JavaScript
;
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var newtype_ts_1 = require("newtype-ts");
var Option_1 = require("fp-ts/lib/Option");
var bigInteger = require("big-integer");
function wrap(x) {
try {
return Option_1.some(bigInteger(newtype_ts_1.unsafeCoerce(x)));
}
catch (e) {
return Option_1.none;
}
}
exports.wrap = wrap;
exports.zero = bigInteger.zero;
exports.one = bigInteger.one;
exports.two = bigInteger['2'];
function add(x, y) {
return x.add(y);
}
exports.add = add;
function mul(x, y) {
return x.multiply(y);
}
exports.mul = mul;
function negate(x) {
return x.negate();
}
exports.negate = negate;
function sub(x, y) {
return x.subtract(y);
}
exports.sub = sub;
function gcd(x, y) {
return bigInteger.gcd(x, y);
}
exports.gcd = gcd;
function lcm(x, y) {
return bigInteger.lcm(x, y);
}
exports.lcm = lcm;
exports.setoid = {
equals: function (x, y) { return x.equals(y); }
};
exports.ord = __assign({}, exports.setoid, { compare: function (x, y) { return x.compare(y); } });
exports.ring = {
add: function (x, y) { return add(x, y); },
zero: exports.zero,
mul: function (x, y) { return mul(x, y); },
one: exports.one,
sub: function (x, y) { return sub(x, y); }
};
//# sourceMappingURL=BigInteger.js.map