@harmoniclabs/plu-ts-onchain
Version:
An embedded DSL for Cardano smart contracts creation coupled with a library for Cardano transactions, all in Typescript
30 lines (29 loc) • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pshowInt = exports.ppositiveIntToBs = exports.pdigitToString = void 0;
var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
var bool_1 = require("../builtins/bool/index.js");
var types_1 = require("../../type_system/types.js");
var phoist_1 = require("../phoist.js");
var pfn_1 = require("../pfn.js");
var plam_1 = require("../plam.js");
var precursive_1 = require("../precursive/index.js");
var punsafeConvertType_1 = require("../punsafeConvertType/index.js");
var std_1 = require("../std/index.js");
exports.pdigitToString = (0, phoist_1.phoist)((0, pfn_1.pfn)([
types_1.int
], types_1.bs)(function (n) { return (0, std_1.pByteString)("").prepend(n.add(48)); }));
exports.ppositiveIntToBs = (0, phoist_1.phoist)((0, precursive_1.precursive)((0, pfn_1.pfn)([
(0, types_1.lam)(types_1.int, types_1.bs),
types_1.int
], types_1.bs)(function (_self, n) {
var self = (0, punsafeConvertType_1.punsafeConvertType)(_self, (0, types_1.lam)(types_1.int, types_1.bs));
return (0, bool_1.pif)(types_1.bs).$(n.gtEq(10))
.then(self.$(n.div(10)).concat(exports.pdigitToString.$(n.mod(10))))
.else(exports.pdigitToString.$(n));
})));
exports.pshowInt = (0, phoist_1.phoist)((0, plam_1.plam)(types_1.int, types_1.bs)(function (n) {
return (0, bool_1.pif)(types_1.bs).$(n.gtEq(0))
.then(exports.ppositiveIntToBs.$(n))
.else((0, std_1.pByteString)((0, uint8array_utils_1.fromAscii)("-")).concat(exports.ppositiveIntToBs.$((0, std_1.pInt)(0).sub(n))));
}));