UNPKG

@prismicio/types-internal

Version:
24 lines (23 loc) 929 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const Either_1 = require("fp-ts/Either"); const function_1 = require("fp-ts/function"); const t = (0, tslib_1.__importStar)(require("io-ts")); function trimScalaStyle(s) { let startAt = 0; /* eslint-disable @typescript-eslint/no-non-null-assertion */ while (startAt < s.length && s[startAt] <= " ") { startAt++; } let endAt = s.length; /* eslint-disable @typescript-eslint/no-non-null-assertion */ while (startAt < endAt && s[endAt - 1] <= " ") { endAt--; } return s.substring(startAt, endAt); } /** A codec that validates a Boolean and convert it as a string */ exports.default = new t.Type("TrimmedString", t.string.is, (u, c) => (0, function_1.pipe)(t.string.validate(u, c), (0, Either_1.chain)((s) => { return t.success(trimScalaStyle(s)); })), (i) => i);