UNPKG

@jmespath-community/jmespath

Version:

Typescript implementation of the JMESPath Community specification

44 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Text = void 0; class Text { constructor(text) { this._text = text; } get string() { return this._text; } get length() { return this.codePoints.length; } compareTo(other) { return Text.compare(this, new Text(other)); } static get comparer() { const stringComparer = (left, right) => { return new Text(left).compareTo(right); }; return stringComparer; } static compare(left, right) { const leftCp = left.codePoints; const rightCp = right.codePoints; for (let index = 0; index < Math.min(leftCp.length, rightCp.length); index++) { if (leftCp[index] === rightCp[index]) { continue; } return leftCp[index] - rightCp[index] > 0 ? 1 : -1; } return leftCp.length - rightCp.length > 0 ? 1 : -1; } reverse() { return String.fromCodePoint(...this.codePoints.reverse()); } get codePoints() { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const array = [...this._text].map(s => s.codePointAt(0)); return array; } } exports.Text = Text; //# sourceMappingURL=text.js.map