mirror of
https://github.com/sbrow/strings.git
synced 2025-12-29 15:17:38 -05:00
build: Prepared package for npm publishing.
This commit is contained in:
6
lib/index.d.ts
vendored
Normal file
6
lib/index.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
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>;
|
||||
/**
|
||||
* Trims characters from the left side of a string.
|
||||
*/
|
||||
export declare const ltrim: import("ts-toolbelt/out/Function/Curry").Curry<(cutset: string, str: string) => string>;
|
||||
67
lib/index.js
Normal file
67
lib/index.js
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ltrim = exports.endsWith = exports.startsWith = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
function escapeRegExp(str) {
|
||||
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));
|
||||
/**
|
||||
* Trims characters from the left side of a string.
|
||||
*/
|
||||
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();
|
||||
});
|
||||
// export const afterFirst = curry(
|
||||
// /**
|
||||
// * @param {String} separator
|
||||
// * @param {String} str
|
||||
// * @return {String}
|
||||
// */
|
||||
// (separator, str) => str.substring(str.indexOf(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(' ');
|
||||
// /**
|
||||
// * @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),
|
||||
// );
|
||||
5
lib/utils.d.ts
vendored
Normal file
5
lib/utils.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
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;
|
||||
export declare const when: typeof _when;
|
||||
19
lib/utils.js
Normal file
19
lib/utils.js
Normal file
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.when = exports.tail = exports.isEmpty = exports.curry = void 0;
|
||||
exports.curry = function (fn) {
|
||||
return (...args) => {
|
||||
if (args.length >= fn.length) {
|
||||
return fn(...args);
|
||||
}
|
||||
// @ts-ignore
|
||||
return (...more) => (0, exports.curry)(fn)(...args, ...more);
|
||||
};
|
||||
};
|
||||
const isEmpty = (str) => str == null || str === '';
|
||||
exports.isEmpty = isEmpty;
|
||||
const tail = (str) => str.substring(1);
|
||||
exports.tail = tail;
|
||||
exports.when = (0, exports.curry)((predicate, whenTrueFn, arg) => {
|
||||
return predicate(arg) ? whenTrueFn(arg) : arg;
|
||||
});
|
||||
@@ -2,11 +2,13 @@
|
||||
"name": "@sbrow/strings",
|
||||
"version": "0.1.0",
|
||||
"description": "Library for string manipulation",
|
||||
"main": "src/index.ts",
|
||||
"main": "./lib/index.js",
|
||||
"types": "./lib/index.d.ts",
|
||||
"repository": "https://github.com/sbrow/strings",
|
||||
"author": "Spencer Brower <brower.spencer@gmail.com>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "vitest --run"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -49,13 +49,13 @@
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||
"outDir": "./lib", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
@@ -104,6 +104,7 @@
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
},
|
||||
"exclude": ["src/**/*.spec.ts", "lib"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user