From 0f0f9b6d5af4d0038d331e7b1ebc0cd5dd4b7abd Mon Sep 17 00:00:00 2001 From: Spencer Brower Date: Thu, 25 May 2023 15:40:04 -0400 Subject: [PATCH] feat: Added docs. --- README.md | 5 ++ docs/.nojekyll | 1 + docs/README.md | 1 + docs/modules.md | 125 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++ src/index.spec.ts | 17 ++++++- src/index.ts | 8 +-- yarn.lock | 113 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 268 insertions(+), 5 deletions(-) create mode 100644 README.md create mode 100644 docs/.nojekyll create mode 100644 docs/README.md create mode 100644 docs/modules.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..093b5cf --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Strings + +A small, simple, functional, and dependency-free library for JavaScript string manipulation. + +You can view the docs [here](./docs) \ No newline at end of file diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e2ac661 --- /dev/null +++ b/docs/.nojekyll @@ -0,0 +1 @@ +TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..64cf9be --- /dev/null +++ b/docs/README.md @@ -0,0 +1 @@ +@sbrow/strings / [Exports](modules.md) diff --git a/docs/modules.md b/docs/modules.md new file mode 100644 index 0000000..a1746fc --- /dev/null +++ b/docs/modules.md @@ -0,0 +1,125 @@ +[@sbrow/strings](README.md) / Exports + +# @sbrow/strings + +## Table of contents + +### Functions + +- [endsWith](modules.md#endswith) +- [ltrim](modules.md#ltrim) +- [startsWith](modules.md#startswith) + +## Functions + +### endsWith + +▸ **endsWith**<`P`, `G`, `R`\>(`...p`): `RequiredKeys`<`ObjectOf`<`G`\>\> extends `never` ? `R` : `Curry`<(...`p`: `G`) => `R`\> + +Curry a [[Function]] + +**`Example`** + +```ts +import {F} from 'ts-toolbelt' + +/// If you are looking for creating types for `curry` +/// It handles placeholders and variable arguments +declare function curry(fn: Fn): F.Curry +``` + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `P` | extends [needle: string \| typeof \_, haystack: string \| typeof \_] | +| `G` | extends readonly `any`[] = `GapsOf`<`P`, [needle: string, haystack: string]\> | +| `R` | extends `unknown` = `boolean` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `...p` | `P` \| [needle: string \| typeof \_, haystack: string \| typeof \_] | + +#### Returns + +`RequiredKeys`<`ObjectOf`<`G`\>\> extends `never` ? `R` : `Curry`<(...`p`: `G`) => `R`\> + +[[Function]] + +#### Defined in + +node_modules/ts-toolbelt/out/Function/Curry.d.ts:77 + +___ + +### ltrim + +▸ **ltrim**<`P`, `G`, `R`\>(`...p`): `RequiredKeys`<`ObjectOf`<`G`\>\> extends `never` ? `R` : `Curry`<(...`p`: `G`) => `R`\> + +Trims characters from the left side of a string. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `P` | extends [cutset: string \| typeof \_, str: string \| typeof \_] | +| `G` | extends readonly `any`[] = `GapsOf`<`P`, [cutset: string, str: string]\> | +| `R` | extends `unknown` = `string` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `...p` | `P` \| [cutset: string \| typeof \_, str: string \| typeof \_] | + +#### Returns + +`RequiredKeys`<`ObjectOf`<`G`\>\> extends `never` ? `R` : `Curry`<(...`p`: `G`) => `R`\> + +#### Defined in + +node_modules/ts-toolbelt/out/Function/Curry.d.ts:77 + +___ + +### startsWith + +▸ **startsWith**<`P`, `G`, `R`\>(`...p`): `RequiredKeys`<`ObjectOf`<`G`\>\> extends `never` ? `R` : `Curry`<(...`p`: `G`) => `R`\> + +Curry a [[Function]] + +**`Example`** + +```ts +import {F} from 'ts-toolbelt' + +/// If you are looking for creating types for `curry` +/// It handles placeholders and variable arguments +declare function curry(fn: Fn): F.Curry +``` + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `P` | extends [needle: string \| typeof \_, haystack: string \| typeof \_] | +| `G` | extends readonly `any`[] = `GapsOf`<`P`, [needle: string, haystack: string]\> | +| `R` | extends `unknown` = `boolean` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `...p` | `P` \| [needle: string \| typeof \_, haystack: string \| typeof \_] | + +#### Returns + +`RequiredKeys`<`ObjectOf`<`G`\>\> extends `never` ? `R` : `Curry`<(...`p`: `G`) => `R`\> + +[[Function]] + +#### Defined in + +node_modules/ts-toolbelt/out/Function/Curry.d.ts:77 diff --git a/package.json b/package.json index 17cc6e6..9fa8a4a 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,9 @@ "@types/ramda": "^0.29.1", "fast-check": "^3.9.0", "ramda": "^0.29.0", + "typedoc": "^0.24.7", + "typedoc-plugin-markdown": "^3.15.3", + "typescript": "^5.0.4", "vitest": "^0.31.1" } } diff --git a/src/index.spec.ts b/src/index.spec.ts index 8a63a43..ec41fdb 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest'; import fc from 'fast-check'; import { - /*afterFirstWord, beforeFirstWord, endsWith,*/ ltrim, startsWith, + /*afterFirstWord, beforeFirstWord, */ endsWith, ltrim, startsWith, } from './index'; describe('strings', () => { @@ -20,6 +20,21 @@ describe('strings', () => { })); }) }); + describe('endsWith', () => { + it('returns true if haystack end with needle', () => { + expect(endsWith('bar', 'foobar')).toBe(true); + }) + it('returns true when haystack is needle', () => { + expect(endsWith('foo', 'foo')).toBe(true); + }) + it('works', () => { + fc.assert(fc.property(fc.string(), fc.string(), (needle, haystack) => { + if (haystack.substring(haystack.indexOf(needle)) == needle) { + expect(endsWith(needle, haystack)).toBe(true); + } + })); + }) + }); // describe('afterFirstWord', () => { // it('removes the first word', () => { // fc.assert(fc.property(fc.string(), (str) => { diff --git a/src/index.ts b/src/index.ts index 584eb7a..faa1ce9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,12 @@ import { curry, isEmpty, tail, when } from "./utils"; -// function escapeRegExp(string) { -// return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string -// } +function escapeRegExp(str: string) { + return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string +} export const startsWith = curry((needle: string, haystack: string) => haystack.indexOf(needle) === 0); -// export const endsWith = curry((needle, haystack) => (new RegExp(`${escapeRegExp(needle)}$`)).test(haystack)); +export const endsWith = curry((needle: string, haystack: string) => (new RegExp(`${escapeRegExp(needle)}$`)).test(haystack)); /** * Trims characters from the left side of a string. diff --git a/yarn.lock b/yarn.lock index 64d2c99..25cca35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -200,6 +200,11 @@ ansi-regex@^5.0.1: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== +ansi-sequence-parser@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/ansi-sequence-parser/-/ansi-sequence-parser-1.1.0.tgz#4d790f31236ac20366b23b3916b789e1bde39aed" + integrity sha512-lEm8mt52to2fT8GhciPCGeCXACSz2UwIN4X2e2LJSnZ5uAbn2/dsYdOmUXq0AtWS5cpAupysIneExOgH0Vd2TQ== + ansi-styles@^5.0.0: version "5.2.0" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-5.2.0.tgz#07449690ad45777d1924ac2abb2fc8895dba836b" @@ -210,11 +215,23 @@ assertion-error@^1.1.0: resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== +balanced-match@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" + integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== + blueimp-md5@^2.10.0: version "2.19.0" resolved "https://registry.yarnpkg.com/blueimp-md5/-/blueimp-md5-2.19.0.tgz#b53feea5498dcb53dc6ec4b823adb84b729c4af0" integrity sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w== +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + cac@^6.7.14: version "6.7.14" resolved "https://registry.yarnpkg.com/cac/-/cac-6.7.14.tgz#804e1e6f506ee363cb0e3ccbb09cad5dd9870959" @@ -328,6 +345,18 @@ get-func-name@^2.0.0: resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" integrity sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig== +handlebars@^4.7.7: + version "4.7.7" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1" + integrity sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA== + dependencies: + minimist "^1.2.5" + neo-async "^2.6.0" + source-map "^0.6.1" + wordwrap "^1.0.0" + optionalDependencies: + uglify-js "^3.1.4" + js-string-escape@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/js-string-escape/-/js-string-escape-1.0.1.tgz#e2625badbc0d67c7533e9edc1068c587ae4137ef" @@ -362,6 +391,11 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" +lunr@^2.3.9: + version "2.3.9" + resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.9.tgz#18b123142832337dd6e964df1a5a7707b25d35e1" + integrity sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow== + magic-string@^0.30.0: version "0.30.0" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.0.tgz#fd58a4748c5c4547338a424e90fa5dd17f4de529" @@ -369,6 +403,11 @@ magic-string@^0.30.0: dependencies: "@jridgewell/sourcemap-codec" "^1.4.13" +marked@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/marked/-/marked-4.3.0.tgz#796362821b019f734054582038b116481b456cf3" + integrity sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A== + md5-hex@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/md5-hex/-/md5-hex-3.0.1.tgz#be3741b510591434b2784d79e556eefc2c9a8e5c" @@ -376,6 +415,18 @@ md5-hex@^3.0.1: dependencies: blueimp-md5 "^2.10.0" +minimatch@^9.0.0: + version "9.0.1" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.1.tgz#8a555f541cf976c622daf078bb28f29fb927c253" + integrity sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w== + dependencies: + brace-expansion "^2.0.1" + +minimist@^1.2.5: + version "1.2.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c" + integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA== + mlly@^1.2.0: version "1.3.0" resolved "https://registry.yarnpkg.com/mlly/-/mlly-1.3.0.tgz#3184cb80c6437bda861a9f452ae74e3434ed9cd1" @@ -396,6 +447,11 @@ nanoid@^3.3.6: resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c" integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA== +neo-async@^2.6.0: + version "2.6.2" + resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" + integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== + p-limit@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-4.0.0.tgz#914af6544ed32bfa54670b061cafcbd04984b644" @@ -474,6 +530,16 @@ semver@^7.3.2: dependencies: lru-cache "^6.0.0" +shiki@^0.14.1: + version "0.14.2" + resolved "https://registry.yarnpkg.com/shiki/-/shiki-0.14.2.tgz#d51440800b701392b31ce2336036058e338247a1" + integrity sha512-ltSZlSLOuSY0M0Y75KA+ieRaZ0Trf5Wl3gutE7jzLuIcWxLp5i/uEnLoQWNvgKXQ5OMpGkJnVMRLAuzjc0LJ2A== + dependencies: + ansi-sequence-parser "^1.1.0" + jsonc-parser "^3.2.0" + vscode-oniguruma "^1.7.0" + vscode-textmate "^8.0.0" + siginfo@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/siginfo/-/siginfo-2.0.0.tgz#32e76c70b79724e3bb567cb9d543eb858ccfaf30" @@ -484,6 +550,11 @@ source-map-js@^1.0.2: resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c" integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw== +source-map@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" + integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== + stackback@0.0.2: version "0.0.2" resolved "https://registry.yarnpkg.com/stackback/-/stackback-0.0.2.tgz#1ac8a0d9483848d1695e418b6d031a3c3ce68e3b" @@ -531,6 +602,23 @@ type-detect@^4.0.0, type-detect@^4.0.5: resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== +typedoc-plugin-markdown@^3.15.3: + version "3.15.3" + resolved "https://registry.yarnpkg.com/typedoc-plugin-markdown/-/typedoc-plugin-markdown-3.15.3.tgz#f5419a32b93efbdc0fcba60ca4de37727aeb8ba9" + integrity sha512-idntFYu3vfaY3eaD+w9DeRd0PmNGqGuNLKihPU9poxFGnATJYGn9dPtEhn2QrTdishFMg7jPXAhos+2T6YCWRQ== + dependencies: + handlebars "^4.7.7" + +typedoc@^0.24.7: + version "0.24.7" + resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.24.7.tgz#7eeb272a1894b3789acc1a94b3f2ae8e7330ee39" + integrity sha512-zzfKDFIZADA+XRIp2rMzLe9xZ6pt12yQOhCr7cD7/PBTjhPmMyMvGrkZ2lPNJitg3Hj1SeiYFNzCsSDrlpxpKw== + dependencies: + lunr "^2.3.9" + marked "^4.3.0" + minimatch "^9.0.0" + shiki "^0.14.1" + types-ramda@^0.29.2: version "0.29.2" resolved "https://registry.yarnpkg.com/types-ramda/-/types-ramda-0.29.2.tgz#2bf33863a51498b43f616cd8cd98227efe9109eb" @@ -538,11 +626,21 @@ types-ramda@^0.29.2: dependencies: ts-toolbelt "^9.6.0" +typescript@^5.0.4: + version "5.0.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b" + integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw== + ufo@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/ufo/-/ufo-1.1.2.tgz#d0d9e0fa09dece0c31ffd57bd363f030a35cfe76" integrity sha512-TrY6DsjTQQgyS3E3dBaOXf0TpPD8u9FVrVYmKVegJuFw51n/YB9XPt+U6ydzFG5ZIN7+DIjPbNmXoBj9esYhgQ== +uglify-js@^3.1.4: + version "3.17.4" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.17.4.tgz#61678cf5fa3f5b7eb789bb345df29afb8257c22c" + integrity sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g== + vite-node@0.31.1: version "0.31.1" resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-0.31.1.tgz#9fea18cbf9552ab262b969068249a8b8e7fb8b38" @@ -597,6 +695,16 @@ vitest@^0.31.1: vite-node "0.31.1" why-is-node-running "^2.2.2" +vscode-oniguruma@^1.7.0: + version "1.7.0" + resolved "https://registry.yarnpkg.com/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz#439bfad8fe71abd7798338d1cd3dc53a8beea94b" + integrity sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA== + +vscode-textmate@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-8.0.0.tgz#2c7a3b1163ef0441097e0b5d6389cd5504b59e5d" + integrity sha512-AFbieoL7a5LMqcnOF04ji+rpXadgOXnZsxQr//r83kLPr7biP7am3g9zbaZIaBGwBRWeSvoMD4mgPdX3e4NWBg== + well-known-symbols@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/well-known-symbols/-/well-known-symbols-2.0.0.tgz#e9c7c07dbd132b7b84212c8174391ec1f9871ba5" @@ -610,6 +718,11 @@ why-is-node-running@^2.2.2: siginfo "^2.0.0" stackback "0.0.2" +wordwrap@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== + yallist@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"