UNPKG

@hokaccha/sql-formatter

Version:

Format whitespace in a SQL query to make it more readable

22 lines 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sortByLengthDesc = exports.escapeRegExp = exports.isEmpty = exports.last = exports.trimSpacesEnd = void 0; // Only removes spaces, not newlines const trimSpacesEnd = (str) => str.replace(/[ \t]+$/u, ""); exports.trimSpacesEnd = trimSpacesEnd; // Last element from array const last = (arr) => arr[arr.length - 1]; exports.last = last; // True array is empty, or it's not an array at all const isEmpty = (arr) => !Array.isArray(arr) || arr.length === 0; exports.isEmpty = isEmpty; // Escapes regex special chars const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"); exports.escapeRegExp = escapeRegExp; // Sorts strings by length, so that longer ones are first // Also sorts alphabetically after sorting by length. const sortByLengthDesc = (strings) => strings.sort((a, b) => { return b.length - a.length || a.localeCompare(b); }); exports.sortByLengthDesc = sortByLengthDesc; //# sourceMappingURL=utils.js.map