diff --git a/.gitignore b/.gitignore index a547bf3..d056240 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ lerna-debug.log* node_modules dist dist-ssr +docs *.local # Editor directories and files diff --git a/package.json b/package.json index e90e2db..3fd23dd 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "globals": "^15.14.0", "husky": "^9.1.7", "prettier": "^3.4.2", + "typedoc": "^0.27.6", "typescript": "^5.7.2", "typescript-eslint": "^8.18.2", "vite": "^6.0.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 539f091..15bb864 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,6 +38,9 @@ importers: prettier: specifier: ^3.4.2 version: 3.4.2 + typedoc: + specifier: ^0.27.6 + version: 0.27.6(typescript@5.7.2) typescript: specifier: ^5.7.2 version: 5.7.2 @@ -46,7 +49,7 @@ importers: version: 8.18.2(eslint@9.17.0(jiti@2.4.2))(typescript@5.7.2) vite: specifier: ^6.0.6 - version: 6.0.6(@types/node@22.10.2)(jiti@2.4.2) + version: 6.0.6(@types/node@22.10.2)(jiti@2.4.2)(yaml@2.6.1) vitest: specifier: ^0.34.6 version: 0.34.6 @@ -459,6 +462,9 @@ packages: resolution: {integrity: sha512-zSkKow6H5Kdm0ZUQUB2kV5JIXqoG0+uH5YADhaEHswm664N9Db8dXSi0nMJpacpMf+MyyglF1vnZohpEg5yUtg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@gerrit0/mini-shiki@1.24.4': + resolution: {integrity: sha512-YEHW1QeAg6UmxEmswiQbOVEg1CW22b1XUD/lNTliOsu0LD0wqoyleFMnmbTp697QE0pcadQiR5cVtbbAPncvpw==} + '@humanfs/core@0.19.1': resolution: {integrity: sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==} engines: {node: '>=18.18.0'} @@ -612,6 +618,15 @@ packages: cpu: [x64] os: [win32] + '@shikijs/engine-oniguruma@1.24.4': + resolution: {integrity: sha512-Do2ry6flp2HWdvpj2XOwwa0ljZBRy15HKZITzPcNIBOGSeprnA8gOooA/bLsSPuy8aJBa+Q/r34dMmC3KNL/zw==} + + '@shikijs/types@1.24.4': + resolution: {integrity: sha512-0r0XU7Eaow0PuDxuWC1bVqmWCgm3XqizIaT7SM42K03vc69LGooT0U8ccSR44xP/hGlNx4FKhtYpV+BU6aaKAA==} + + '@shikijs/vscode-textmate@9.3.1': + resolution: {integrity: sha512-79QfK1393x9Ho60QFyLti+QfdJzRQCVLFb97kOIV7Eo9vQU/roINgk7m24uv0a7AUvN//RDH36FLjjK48v0s9g==} + '@sinclair/typebox@0.27.8': resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} @@ -627,6 +642,9 @@ packages: '@types/estree@1.0.6': resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==} + '@types/hast@3.0.4': + resolution: {integrity: sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==} + '@types/istanbul-lib-coverage@2.0.6': resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==} @@ -636,6 +654,9 @@ packages: '@types/node@22.10.2': resolution: {integrity: sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==} + '@types/unist@3.0.3': + resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==} + '@typescript-eslint/eslint-plugin@8.18.2': resolution: {integrity: sha512-adig4SzPLjeQ0Tm+jvsozSGiCliI2ajeURDGHjZ2llnA+A67HihCQ+a3amtPhUakd1GlwHxSRvzOZktbEvhPPg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -872,6 +893,10 @@ packages: emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + entities@4.5.0: + resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} + engines: {node: '>=0.12'} + env-paths@2.2.1: resolution: {integrity: sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==} engines: {node: '>=6'} @@ -1158,6 +1183,9 @@ packages: lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} + linkify-it@5.0.0: + resolution: {integrity: sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==} + local-pkg@0.4.3: resolution: {integrity: sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==} engines: {node: '>=14'} @@ -1200,6 +1228,9 @@ packages: loupe@2.3.7: resolution: {integrity: sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==} + lunr@2.3.9: + resolution: {integrity: sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==} + magic-string@0.30.17: resolution: {integrity: sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==} @@ -1207,6 +1238,13 @@ packages: resolution: {integrity: sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==} engines: {node: '>=10'} + markdown-it@14.1.0: + resolution: {integrity: sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==} + hasBin: true + + mdurl@2.0.0: + resolution: {integrity: sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==} + meow@12.1.1: resolution: {integrity: sha512-BhXM0Au22RwUneMPwSCnyhTOizdWoIEPU9sp0Aqa1PnDMR5Wv2FGXYDjuzJEIX+Eo2Rb8xuYe5jrnm5QowQFkw==} engines: {node: '>=16.10'} @@ -1323,6 +1361,10 @@ packages: resolution: {integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + punycode.js@2.3.1: + resolution: {integrity: sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==} + engines: {node: '>=6'} + punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} @@ -1457,6 +1499,13 @@ packages: resolution: {integrity: sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==} engines: {node: '>=4'} + typedoc@0.27.6: + resolution: {integrity: sha512-oBFRoh2Px6jFx366db0lLlihcalq/JzyCVp7Vaq1yphL/tbgx2e+bkpkCgJPunaPvPwoTOXSwasfklWHm7GfAw==} + engines: {node: '>= 18'} + hasBin: true + peerDependencies: + typescript: 5.0.x || 5.1.x || 5.2.x || 5.3.x || 5.4.x || 5.5.x || 5.6.x || 5.7.x + typescript-eslint@8.18.2: resolution: {integrity: sha512-KuXezG6jHkvC3MvizeXgupZzaG5wjhU3yE8E7e6viOvAvD9xAWYp8/vy0WULTGe9DYDWcQu7aW03YIV3mSitrQ==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -1469,6 +1518,9 @@ packages: engines: {node: '>=14.17'} hasBin: true + uc.micro@2.1.0: + resolution: {integrity: sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==} + ufo@1.5.4: resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==} @@ -1618,6 +1670,11 @@ packages: resolution: {integrity: sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==} engines: {node: '>=10'} + yaml@2.6.1: + resolution: {integrity: sha512-7r0XPzioN/Q9kXBro/XPnA6kznR73DHq+GXh5ON7ZozRO6aMjbmiBuKste2wslTFkC5d1dw0GooOCepZXJ2SAg==} + engines: {node: '>= 14'} + hasBin: true + yargs-parser@21.1.1: resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} engines: {node: '>=12'} @@ -1946,6 +2003,12 @@ snapshots: dependencies: levn: 0.4.1 + '@gerrit0/mini-shiki@1.24.4': + dependencies: + '@shikijs/engine-oniguruma': 1.24.4 + '@shikijs/types': 1.24.4 + '@shikijs/vscode-textmate': 9.3.1 + '@humanfs/core@0.19.1': {} '@humanfs/node@0.16.6': @@ -2051,6 +2114,18 @@ snapshots: '@rollup/rollup-win32-x64-msvc@4.29.1': optional: true + '@shikijs/engine-oniguruma@1.24.4': + dependencies: + '@shikijs/types': 1.24.4 + '@shikijs/vscode-textmate': 9.3.1 + + '@shikijs/types@1.24.4': + dependencies: + '@shikijs/vscode-textmate': 9.3.1 + '@types/hast': 3.0.4 + + '@shikijs/vscode-textmate@9.3.1': {} + '@sinclair/typebox@0.27.8': {} '@types/chai-subset@1.3.5': @@ -2065,6 +2140,10 @@ snapshots: '@types/estree@1.0.6': {} + '@types/hast@3.0.4': + dependencies: + '@types/unist': 3.0.3 + '@types/istanbul-lib-coverage@2.0.6': {} '@types/json-schema@7.0.15': {} @@ -2073,6 +2152,8 @@ snapshots: dependencies: undici-types: 6.20.0 + '@types/unist@3.0.3': {} + '@typescript-eslint/eslint-plugin@8.18.2(@typescript-eslint/parser@8.18.2(eslint@9.17.0(jiti@2.4.2))(typescript@5.7.2))(eslint@9.17.0(jiti@2.4.2))(typescript@5.7.2)': dependencies: '@eslint-community/regexpp': 4.12.1 @@ -2358,6 +2439,8 @@ snapshots: emoji-regex@8.0.0: {} + entities@4.5.0: {} + env-paths@2.2.1: {} error-ex@1.3.2: @@ -2680,6 +2763,10 @@ snapshots: lines-and-columns@1.2.4: {} + linkify-it@5.0.0: + dependencies: + uc.micro: 2.1.0 + local-pkg@0.4.3: {} locate-path@6.0.0: @@ -2712,6 +2799,8 @@ snapshots: dependencies: get-func-name: 2.0.2 + lunr@2.3.9: {} + magic-string@0.30.17: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 @@ -2720,6 +2809,17 @@ snapshots: dependencies: semver: 7.6.3 + markdown-it@14.1.0: + dependencies: + argparse: 2.0.1 + entities: 4.5.0 + linkify-it: 5.0.0 + mdurl: 2.0.0 + punycode.js: 2.3.1 + uc.micro: 2.1.0 + + mdurl@2.0.0: {} + meow@12.1.1: {} merge2@1.4.1: {} @@ -2830,6 +2930,8 @@ snapshots: ansi-styles: 5.2.0 react-is: 18.3.1 + punycode.js@2.3.1: {} + punycode@2.3.1: {} queue-microtask@1.2.3: {} @@ -2947,6 +3049,15 @@ snapshots: type-detect@4.1.0: {} + typedoc@0.27.6(typescript@5.7.2): + dependencies: + '@gerrit0/mini-shiki': 1.24.4 + lunr: 2.3.9 + markdown-it: 14.1.0 + minimatch: 9.0.5 + typescript: 5.7.2 + yaml: 2.6.1 + typescript-eslint@8.18.2(eslint@9.17.0(jiti@2.4.2))(typescript@5.7.2): dependencies: '@typescript-eslint/eslint-plugin': 8.18.2(@typescript-eslint/parser@8.18.2(eslint@9.17.0(jiti@2.4.2))(typescript@5.7.2))(eslint@9.17.0(jiti@2.4.2))(typescript@5.7.2) @@ -2959,6 +3070,8 @@ snapshots: typescript@5.7.2: {} + uc.micro@2.1.0: {} + ufo@1.5.4: {} undici-types@6.20.0: {} @@ -3003,7 +3116,7 @@ snapshots: '@types/node': 22.10.2 fsevents: 2.3.3 - vite@6.0.6(@types/node@22.10.2)(jiti@2.4.2): + vite@6.0.6(@types/node@22.10.2)(jiti@2.4.2)(yaml@2.6.1): dependencies: esbuild: 0.24.2 postcss: 8.4.49 @@ -3012,6 +3125,7 @@ snapshots: '@types/node': 22.10.2 fsevents: 2.3.3 jiti: 2.4.2 + yaml: 2.6.1 vitest@0.34.6: dependencies: @@ -3070,6 +3184,8 @@ snapshots: y18n@5.0.8: {} + yaml@2.6.1: {} + yargs-parser@21.1.1: {} yargs@17.7.2: diff --git a/src/camelise.ts b/src/camelise.ts index fa29fa1..0c1fc7a 100644 --- a/src/camelise.ts +++ b/src/camelise.ts @@ -1,3 +1,14 @@ +/** + * Converts a string of words to remove spaces and capitalise each word except + * for the first (lowerCamelCase). If the uppercaseFirstLetter parameter is set + * to true, then it produces the string in UpperCamelCase, also known as + * PascalCase. + + * @param words - an underscore separated string to be converted to camelcase. + * @param uppercaseFirstLetter - if true, the first letter will be uppercase. + * @returns a camelcase version of words. + */ + export default function camelise( words: string, uppercaseFirstLetter: boolean = false diff --git a/src/dasherise.ts b/src/dasherise.ts index 7eb8f44..dc4cae4 100644 --- a/src/dasherise.ts +++ b/src/dasherise.ts @@ -1,3 +1,9 @@ +/** + * Converts a string of words to a hyphen separated string (kebab-case). + * + * @param words - an underscore separated string to be converted to kebabcase. + * @returns a kebabcase version of words. + */ export default function dasherise(words: string): string { return words.replaceAll('_', '-') } diff --git a/src/downcase-first.ts b/src/downcase-first.ts index 829563b..bf7c45f 100644 --- a/src/downcase-first.ts +++ b/src/downcase-first.ts @@ -1,3 +1,9 @@ +/** + * Converts the first word of the string to start with a lowercase character. + * + * @param words - a space separated string. + * @returns a copy of words that starts with a lowercase character. + */ export default function downcaseFirst(words: string): string { return words .split(' ') diff --git a/src/humanise.ts b/src/humanise.ts index c70a805..5283453 100644 --- a/src/humanise.ts +++ b/src/humanise.ts @@ -1,3 +1,13 @@ +/** + * Converts a string of words to display better to end users by being space + * separated. If the uppercaseFirstLetter parameter is set to true, then the + * first letter of each word will also start with an uppercase letter. + * + * @param words - an underscore separated string to be made space separated. + * @param uppercaseFirstLetter - if true, the first letter of each word will be + * uppercase. + * @returns a space separated version of words. + */ export default function humanise( words: string, uppercaseFirstLetter: boolean = false diff --git a/src/ordinal.ts b/src/ordinal.ts index a9c9e61..7cf6fa3 100644 --- a/src/ordinal.ts +++ b/src/ordinal.ts @@ -1,3 +1,10 @@ +/** + * Returns the suffix that can be added to a number to indicate the position in + * an ordered sequence, for example 1st, 42nd, or 111th. + * + * @param number - the number to determine the ordinal suffix of. + * @returns - the ordinal suffix that will be st, nd, rd, or th. + */ export default function ordinal(number: number): string { switch (number % 10) { case 1: diff --git a/src/ordinalise.ts b/src/ordinalise.ts index 6a89eda..1231b66 100644 --- a/src/ordinalise.ts +++ b/src/ordinalise.ts @@ -1,5 +1,13 @@ import ordinal from './ordinal' +/** + * Converts a number into an ordinal string used to indiciate the position in an + * ordered sequence, for example 1st, 42nd, or 111th. + * + * @param number - the number to use as the ordinal prefix and used to determine + * what the ordinal suffix is. + * @returns the number with the correct ordinal suffix appended to it. + */ export default function ordinalise(number: number): string { return `${number}${ordinal(number)}` } diff --git a/src/parameterise.ts b/src/parameterise.ts index 3168943..d7b272b 100644 --- a/src/parameterise.ts +++ b/src/parameterise.ts @@ -1,8 +1,17 @@ +/** + * Replaces spaces in a word with a hyphen or custom separator character so + * that the word may be used as part of friendly URL slug. + * + * @param word - a word to have spaces replaced by a separator. + * @param separator - a separator character to replace spaces with. + * @param preserveCase - if set to true, the word will not be made lower case. + * @returns a copy of the word seperated by hyphens or a custom separator. + */ export default function parameterise( word: string, - seperator = '-', + separator = '-', preserveCase = false ): string { const stringToParameterise = preserveCase ? word : word.toLowerCase() - return stringToParameterise.split(' ').join(seperator) + return stringToParameterise.split(' ').join(separator) } diff --git a/src/pascalise.ts b/src/pascalise.ts index 8bf7a77..fcd248e 100644 --- a/src/pascalise.ts +++ b/src/pascalise.ts @@ -1,4 +1,12 @@ -export default function camelise(words: string): string { +/** + * Converts a string of words to remove spaces and capitalise each word + * including the first (UpperCamelCase or PascalCase). To make the first word + * start with a lowercase character, use the camelcase function instead. + + * @param words - an underscore separated string to be converted to pascal case. + * @returns a pascalcase version of words. + */ +export default function pascalise(words: string): string { return words .split('_') .map((word) => { diff --git a/src/titleise.ts b/src/titleise.ts index 510b816..90cc20b 100644 --- a/src/titleise.ts +++ b/src/titleise.ts @@ -1,5 +1,11 @@ import { letterIsUpperCase } from './shared-functions' +/** + * Capitalises each word in the specified string. + * + * @param words - a string of words to be titleised. + * @returns a copy of words where each word starts with an uppercase character. + */ export default function titleise(words: string): string { return words .trim() diff --git a/src/underscore.ts b/src/underscore.ts index 2c80ee8..f84661a 100644 --- a/src/underscore.ts +++ b/src/underscore.ts @@ -1,5 +1,11 @@ import { letterIsUpperCase } from './shared-functions' +/** + * Converts a camelcase separated string of words to be underscore separated. + * + * @param words - a camelcase separated string of words. + * @returns a copy of words where each word is underscore separated. + */ export default function underscore(words: string): string { return words .split('') diff --git a/src/upcase-first.ts b/src/upcase-first.ts index 0626cd7..46e7689 100644 --- a/src/upcase-first.ts +++ b/src/upcase-first.ts @@ -1,3 +1,9 @@ +/** + * Converts the first word of the string to start with an uppercase character. + * + * @param words - a space separated string. + * @returns a copy of words that starts with an uppercase character. + */ export default function upcaseFirst(words: string): string { return words .split(' ')