mirror of
https://github.com/sbrow/strings.git
synced 2025-12-29 15:17:38 -05:00
fix: re-built code.
This commit is contained in:
3
lib/index.d.ts
vendored
3
lib/index.d.ts
vendored
@@ -1,3 +1,4 @@
|
||||
export * from "./shorten";
|
||||
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>;
|
||||
@@ -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 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 afterFirstWord: (str: string) => string;
|
||||
export declare const removeFirstWord: (str: string) => string;
|
||||
|
||||
42
lib/index.js
42
lib/index.js
@@ -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);
|
||||
};
|
||||
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");
|
||||
__exportStar(require("./shorten"), exports);
|
||||
__exportStar(require("./trim"), exports);
|
||||
function escapeRegExp(str) {
|
||||
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.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.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
|
||||
exports.beforeFirstWord = (0, exports.beforeFirst)(" ");
|
||||
// /**
|
||||
// * @param {String} str
|
||||
// * @return {String}
|
||||
// */
|
||||
// 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),
|
||||
// );
|
||||
// @todo Test
|
||||
exports.afterFirstWord = (0, exports.afterFirst)(" ");
|
||||
exports.removeFirstWord = exports.afterFirstWord;
|
||||
|
||||
3
lib/shorten.d.ts
vendored
Normal file
3
lib/shorten.d.ts
vendored
Normal 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
14
lib/shorten.js
Normal 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
3
lib/utils.d.ts
vendored
@@ -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 isEmpty: (str: string) => boolean;
|
||||
export declare const tail: (str: string) => string;
|
||||
export declare const when: typeof _when;
|
||||
export declare const until: typeof _until;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
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) {
|
||||
return (...args) => {
|
||||
if (args.length >= fn.length) {
|
||||
@@ -17,3 +17,7 @@ exports.tail = tail;
|
||||
exports.when = (0, exports.curry)((predicate, whenTrueFn, 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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user