UNPKG

parjs

Version:

Library for building parsers using combinators.

42 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stringify = void 0; const combinated_1 = require("../combinated"); const functions_1 = require("../functions"); const wrap_implicit_1 = require("../wrap-implicit"); class Str extends combinated_1.Combinated { constructor() { super(...arguments); this.type = "stringify"; this.expecting = this.source.expecting; } _apply(ps) { this.source.apply(ps); if (!ps.isOk) { return; } const { value } = ps; const typeStr = typeof value; if (typeStr === "string") { return; } if (value === null || value === undefined) { ps.value = String(value); } else if (value instanceof Array) { ps.value = (0, functions_1.recJoin)(value); } else if (typeStr === "symbol") { ps.value = String(value).slice(7, -1); } else { ps.value = value.toString(); } } } /** Applies the source parser and yields a stringified result. */ function stringify() { return source => new Str((0, wrap_implicit_1.wrapImplicit)(source)); } exports.stringify = stringify; //# sourceMappingURL=stringify.js.map