UNPKG

parjs

Version:

A parser-combinator library for JavaScript.

48 lines (47 loc) 1.5 kB
"use strict"; /** * @module parjs/combinators */ /** */ Object.defineProperty(exports, "__esModule", { value: true }); const helpers_1 = require("../functions/helpers"); const combinator_1 = require("./combinator"); const parser_1 = require("../parser"); /** * Applies the source parser and yields a stringified result. */ function stringify() { return combinator_1.defineCombinator(source => { return new class Str extends parser_1.ParjserBase { constructor() { super(...arguments); this.type = "stringify"; this.expecting = source.expecting; } _apply(ps) { source.apply(ps); if (!ps.isOk) { return; } let { value } = ps; let typeStr = typeof value; if (typeStr === "string") { } else if (value === null || value === undefined) { ps.value = String(value); } else if (value instanceof Array) { ps.value = helpers_1.StringHelpers.recJoin(value); } else if (typeStr === "symbol") { ps.value = String(value).slice(7, -1); } else { ps.value = value.toString(); } } }(); }); } exports.stringify = stringify; //# sourceMappingURL=stringify.js.map