From 337942657a60dbbd57235d23e33b05c7934f2e41 Mon Sep 17 00:00:00 2001 From: Spencer Brower Date: Thu, 25 May 2023 17:32:29 -0400 Subject: [PATCH] style: Ran prettier. --- lib/index.d.ts | 4 +++- lib/index.js | 19 ++++++------------- lib/trim.js | 12 ++++-------- lib/utils.d.ts | 2 +- lib/utils.js | 2 +- 5 files changed, 15 insertions(+), 24 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index f39e444..11517ea 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,5 +1,7 @@ -export * from './trim'; +export * from "./trim"; export declare const startsWith: import("ts-toolbelt/out/Function/Curry").Curry<(needle: string, haystack: string) => boolean>; export declare const endsWith: import("ts-toolbelt/out/Function/Curry").Curry<(needle: string, haystack: string) => boolean>; export declare const afterFirst: import("ts-toolbelt/out/Function/Curry").Curry<(separator: string, str: string) => string>; export declare const afterLast: import("ts-toolbelt/out/Function/Curry").Curry<(separator: string, str: string) => string>; +export declare const beforeFirst: import("ts-toolbelt/out/Function/Curry").Curry<(separator: string, str: string) => string>; +export declare const beforeFirstWord: import("ts-toolbelt/out/Function/Curry").Curry<(str: string) => string>; diff --git a/lib/index.js b/lib/index.js index 345eca1..768f603 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,26 +14,19 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.afterLast = exports.afterFirst = exports.endsWith = exports.startsWith = void 0; +exports.beforeFirstWord = exports.beforeFirst = exports.afterLast = exports.afterFirst = exports.endsWith = exports.startsWith = void 0; const utils_1 = require("./utils"); __exportStar(require("./trim"), exports); function escapeRegExp(str) { - return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string + return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string } exports.startsWith = (0, utils_1.curry)((needle, haystack) => haystack.indexOf(needle) === 0); -exports.endsWith = (0, utils_1.curry)((needle, haystack) => (new RegExp(`${escapeRegExp(needle)}$`)).test(haystack)); +exports.endsWith = (0, utils_1.curry)((needle, haystack) => new RegExp(`${escapeRegExp(needle)}$`).test(haystack)); exports.afterFirst = (0, utils_1.curry)((separator, str) => str.substring(str.indexOf(separator) + 1, str.length)); exports.afterLast = (0, utils_1.curry)((separator, str) => str.substring(str.lastIndexOf(separator) + 1, str.length)); -// export const beforeFirst = curry( -// /** -// * -// * @param {String} separator -// * @param {String} str -// * @returns {String} -// */ -// (separator, str) => str.substring(0, str.indexOf(separator)), -// ); -// export const beforeFirstWord = beforeFirst(' '); +exports.beforeFirst = (0, utils_1.curry)((separator, str) => str.substring(0, str.indexOf(separator))); +// @todo Test +exports.beforeFirstWord = (0, exports.beforeFirst)(" "); // /** // * @param {String} str // * @return {String} diff --git a/lib/trim.js b/lib/trim.js index 7859bac..0e751df 100644 --- a/lib/trim.js +++ b/lib/trim.js @@ -8,18 +8,14 @@ const utils_1 = require("./utils"); exports.ltrim = (0, utils_1.curry)((cutset, str) => { const _trim = (x) => (0, exports.ltrim)(cutset)((0, utils_1.tail)(x)); // const _trim = compose(ltrim(cutset), tail); - const trimmed = () => (0, utils_1.when)((x = '') => cutset.includes(x.charAt(0)), _trim)(str); - return (0, utils_1.isEmpty)(cutset) || (0, utils_1.isEmpty)(str) - ? str - : trimmed(); + const trimmed = () => (0, utils_1.when)((x = "") => cutset.includes(x.charAt(0)), _trim)(str); + return (0, utils_1.isEmpty)(cutset) || (0, utils_1.isEmpty)(str) ? str : trimmed(); }); exports.rtrim = (0, utils_1.curry)((cutset, str) => { const _trim = (x) => (0, exports.rtrim)(cutset)(x.substring(0, x.length - 1)); // const _trim = compose(rtrim(cutset), init); - const trimmed = () => (0, utils_1.when)((x = '') => cutset.includes(x.charAt(x.length - 1)), _trim)(str); - return (0, utils_1.isEmpty)(cutset) || (0, utils_1.isEmpty)(str) - ? str - : trimmed(); + const trimmed = () => (0, utils_1.when)((x = "") => cutset.includes(x.charAt(x.length - 1)), _trim)(str); + return (0, utils_1.isEmpty)(cutset) || (0, utils_1.isEmpty)(str) ? str : trimmed(); }); // const trim = curry((cutset: string, str: string) => compose(ltrim(cutset), rtrim(cutset))(str)); exports.trim = (0, utils_1.curry)((cutset, str) => (0, exports.ltrim)(cutset)((0, exports.rtrim)(cutset, str))); diff --git a/lib/utils.d.ts b/lib/utils.d.ts index 1058174..28cf703 100644 --- a/lib/utils.d.ts +++ b/lib/utils.d.ts @@ -1,4 +1,4 @@ -import type { curry as _curry, when as _when } from 'ramda'; +import type { curry as _curry, when as _when } from "ramda"; export declare const curry: typeof _curry; export declare const isEmpty: (str: string) => boolean; export declare const tail: (str: string) => string; diff --git a/lib/utils.js b/lib/utils.js index fe47f58..10f8191 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -10,7 +10,7 @@ exports.curry = function (fn) { return (...more) => (0, exports.curry)(fn)(...args, ...more); }; }; -const isEmpty = (str) => str == null || str === ''; +const isEmpty = (str) => str == null || str === ""; exports.isEmpty = isEmpty; const tail = (str) => str.substring(1); exports.tail = tail;