fix: re-built code.

This commit is contained in:
Spencer Brower
2023-06-15 13:43:40 -04:00
parent 559217ac60
commit f46b68c709
8 changed files with 41 additions and 35 deletions

View File

@@ -81,7 +81,7 @@ ___
#### Defined in #### Defined in
[src/index.ts:34](https://github.com/sbrow/strings/blob/7b676b7/src/index.ts#L34) [src/index.ts:38](https://github.com/sbrow/strings/blob/559217a/src/index.ts#L38)
___ ___
@@ -299,7 +299,7 @@ ___
#### Defined in #### Defined in
[src/index.ts:35](https://github.com/sbrow/strings/blob/7b676b7/src/index.ts#L35) [src/index.ts:39](https://github.com/sbrow/strings/blob/559217a/src/index.ts#L39)
___ ___

View File

@@ -14,6 +14,7 @@
in { in {
devShells.x86_64-linux.default = pkgs.mkShell { devShells.x86_64-linux.default = pkgs.mkShell {
buildInputs = with pkgs; [ buildInputs = with pkgs; [
nodejs
yarn yarn
]; ];
}; };

3
lib/index.d.ts vendored
View File

@@ -1,3 +1,4 @@
export * from "./shorten";
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 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 endsWith: import("ts-toolbelt/out/Function/Curry").Curry<(needle: string, haystack: string) => boolean>;
@@ -5,3 +6,5 @@ export declare const afterFirst: import("ts-toolbelt/out/Function/Curry").Curry<
export declare const afterLast: 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 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>; export declare const beforeFirstWord: import("ts-toolbelt/out/Function/Curry").Curry<(str: string) => string>;
export declare const afterFirstWord: (str: string) => string;
export declare const removeFirstWord: (str: string) => string;

View File

@@ -14,8 +14,9 @@ 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); for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.beforeFirstWord = exports.beforeFirst = exports.afterLast = exports.afterFirst = exports.endsWith = exports.startsWith = void 0; exports.removeFirstWord = exports.afterFirstWord = exports.beforeFirstWord = exports.beforeFirst = exports.afterLast = exports.afterFirst = exports.endsWith = exports.startsWith = void 0;
const utils_1 = require("./utils"); const utils_1 = require("./utils");
__exportStar(require("./shorten"), exports);
__exportStar(require("./trim"), exports); __exportStar(require("./trim"), exports);
function escapeRegExp(str) { function escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
@@ -24,35 +25,14 @@ exports.startsWith = (0, utils_1.curry)((needle, haystack) => haystack.indexOf(n
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.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)); exports.afterLast = (0, utils_1.curry)((separator, str) => str.substring(str.lastIndexOf(separator) + 1, str.length));
exports.beforeFirst = (0, utils_1.curry)((separator, str) => str.substring(0, str.indexOf(separator))); exports.beforeFirst = (0, utils_1.curry)((separator, str) => {
const index = str.indexOf(separator);
return index === -1
? str
: str.substring(0, index);
});
// @todo Test // @todo Test
exports.beforeFirstWord = (0, exports.beforeFirst)(" "); exports.beforeFirstWord = (0, exports.beforeFirst)(" ");
// /** // @todo Test
// * @param {String} str exports.afterFirstWord = (0, exports.afterFirst)(" ");
// * @return {String} exports.removeFirstWord = exports.afterFirstWord;
// */
// export function afterFirstWord(str) {
// return afterFirst(' ', str);
// }
// export const removeFirstWord = afterFirstWord;
// /**
// * @param {Number} maxChars
// * @param {String} str
// * @return {Boolean} False if str is longer than maxChars characters.
// */
// const shorterThan = curry((maxChars, str) => str.length <= maxChars);
// /**
// * @param {Number} maxChars The maximum length of the desired output string.
// * @param strategy a function that accepts a string and returns a shorter string.
// * @return {String} The input string, shortened to maxChars by strategy.
// */
// const shortenString = (maxChars, strategy) => until(shorterThan(maxChars), strategy);
// /**
// * @param {Number} maxChars
// * @param {String} str The string to remove words from.
// * @return {String} the shortened string.
// */
// export const removeWordsFromStartOfString = uncurryN(
// 2,
// (maxChars) => shortenString(maxChars, removeFirstWord),
// );

3
lib/shorten.d.ts vendored Normal file
View File

@@ -0,0 +1,3 @@
export declare const shorterThan: import("ts-toolbelt/out/Function/Curry").Curry<(maxChars: number, str: string) => boolean>;
export declare const shorten: import("ts-toolbelt/out/Function/Curry").Curry<(maxChars: number, strategy: any) => (init: unknown) => unknown>;
export declare const removeWordsFromBeginning: import("ts-toolbelt/out/Function/Curry").Curry<(maxChars: number, str: string) => unknown>;

14
lib/shorten.js Normal file
View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeWordsFromBeginning = exports.shorten = exports.shorterThan = void 0;
const index_1 = require("./index");
const utils_1 = require("./utils");
exports.shorterThan = (0, utils_1.curry)((maxChars, str) => str.length <= maxChars);
exports.shorten = (0, utils_1.curry)((maxChars, strategy) => (0, utils_1.until)((0, exports.shorterThan)(maxChars), strategy));
exports.removeWordsFromBeginning = (0, utils_1.curry)((maxChars, str) => (0, exports.shorten)(maxChars, index_1.removeFirstWord)(str));
/*
export const removeWordsFromBeginning = uncurryN(
2,
(maxChars: number) => shorten(maxChars, removeFirstWord),
);
*/

3
lib/utils.d.ts vendored
View File

@@ -1,5 +1,6 @@
import type { curry as _curry, when as _when } from "ramda"; import type { curry as _curry, until as _until, when as _when } from "ramda";
export declare const curry: typeof _curry; export declare const curry: typeof _curry;
export declare const isEmpty: (str: string) => boolean; export declare const isEmpty: (str: string) => boolean;
export declare const tail: (str: string) => string; export declare const tail: (str: string) => string;
export declare const when: typeof _when; export declare const when: typeof _when;
export declare const until: typeof _until;

View File

@@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.when = exports.tail = exports.isEmpty = exports.curry = void 0; exports.until = exports.when = exports.tail = exports.isEmpty = exports.curry = void 0;
exports.curry = function (fn) { exports.curry = function (fn) {
return (...args) => { return (...args) => {
if (args.length >= fn.length) { if (args.length >= fn.length) {
@@ -17,3 +17,7 @@ exports.tail = tail;
exports.when = (0, exports.curry)((predicate, whenTrueFn, arg) => { exports.when = (0, exports.curry)((predicate, whenTrueFn, arg) => {
return predicate(arg) ? whenTrueFn(arg) : arg; return predicate(arg) ? whenTrueFn(arg) : arg;
}); });
exports.until = (0, exports.curry)((predicate, fn, arg) => {
const loop = (a) => predicate(a) ? a : loop(fn(a));
return loop(arg);
});