From 4fbaaff49ccd90a0e3ffbbc99d81e20f7a9a6a84 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 22 May 2025 16:39:27 +0530 Subject: [PATCH 1/9] docs: update string builder example --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fdc49a2..99ad52c 100644 --- a/README.md +++ b/README.md @@ -985,10 +985,17 @@ The string builder offers a fluent API for applying a set of transforms on a str ```ts import StringBuilder from '@poppinss/string/builder' -const builder = new StringBuilder('hello world') +const builder = new StringBuilder('userController') -const value = builder.snakeCase().suffix('_controller').toString() -assert(value === 'hello_world_controller') +const value = builder + .removeSuffix('controller') // user + .plural() // users + .snakeCase() // users + .suffix('_controller') // users_controller + .ext('ts') // users_controller.ts + .toString() + +assert(value === 'users_controller.ts') ``` ## Contributing From 7c3f5a432372b46071877e2e565be65ee6d5a29f Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 23 May 2025 15:02:49 +0530 Subject: [PATCH 2/9] feat: add toUnixSlash method --- README.md | 14 +++++++++++++ index.ts | 2 ++ src/to_unix_slash.ts | 40 +++++++++++++++++++++++++++++++++++++ tests/to_unix_slash.spec.ts | 24 ++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 src/to_unix_slash.ts create mode 100644 tests/to_unix_slash.spec.ts diff --git a/README.md b/README.md index 99ad52c..81b0e7d 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,20 @@ string.interpolate('hello \\{{ users.0 }}', {}) // hello {{ users.0 }} ``` +### slash + +Convert OS-specific file paths to Unix file paths. Credits [https://github.com/sindresorhus/slash](https://github.com/sindresorhus/slash) + +```ts +import string from '@poppinss/string' + +const value = path.join('foo', 'bar') +// Unix => foo/bar +// Windows => foo\\bar + +string.slash(value) // foo/bar +``` + ### plural Convert a word to its plural form. The method is exported directly from the [pluralize](https://www.npmjs.com/package/pluralize) package. diff --git a/index.ts b/index.ts index d53317b..51f52d8 100644 --- a/index.ts +++ b/index.ts @@ -21,6 +21,7 @@ import { wordWrap } from './src/word_wrap.js' import milliseconds from './src/milliseconds.js' import { htmlEscape } from './src/html_escape.js' import { interpolate } from './src/interpolate.js' +import { toUnixSlash } from './src/to_unix_slash.js' import { plural, pluralize, singular, isPlural, isSingular } from './src/pluralize.js' import { noCase, @@ -71,6 +72,7 @@ const string = { htmlEscape, justify, uuid, + toUnixSlash, } export default string diff --git a/src/to_unix_slash.ts b/src/to_unix_slash.ts new file mode 100644 index 0000000..d2e4d6f --- /dev/null +++ b/src/to_unix_slash.ts @@ -0,0 +1,40 @@ +/* + * @poppinss/string + * + * (c) Poppinss + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Copy-pasted from https://github.com/sindresorhus/slash/blob/main/index.d.ts + * @credit - https://github.com/sindresorhus/slash + */ + +/** + * Convert Windows backslash paths to slash paths: `foo\\bar` ➔ `foo/bar`. + * [Forward-slash paths can be used in Windows](http://superuser.com/a/176395/6877) as long as + * they're not extended-length paths. + * + * @example + * ``` + * import path from 'node:path'; + * import string from '@poppinss/string'; + * + * const string = path.join('foo', 'bar'); + * // Unix => foo/bar + * // Windows => foo\\bar + * + * string.toUnixSlash(string); + * // Unix => foo/bar + * // Windows => foo/bar + * ``` + */ +export function toUnixSlash(path: string): string { + const isExtendedLengthPath = path.startsWith('\\\\?\\') + if (isExtendedLengthPath) { + return path + } + return path.replace(/\\/g, '/') +} diff --git a/tests/to_unix_slash.spec.ts b/tests/to_unix_slash.spec.ts new file mode 100644 index 0000000..43ee782 --- /dev/null +++ b/tests/to_unix_slash.spec.ts @@ -0,0 +1,24 @@ +/* + * @poppinss/string + * + * (c) Poppinss + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { test } from '@japa/runner' +import { toUnixSlash } from '../src/to_unix_slash.js' + +test.group('Slash', () => { + test('convert backwards-slash paths to forward slash paths', ({ assert }) => { + assert.equal(toUnixSlash('c:/aaaa\\bbbb'), 'c:/aaaa/bbbb') + assert.equal(toUnixSlash('c:\\aaaa\\bbbb'), 'c:/aaaa/bbbb') + assert.equal(toUnixSlash('c:\\aaaa\\bbbb\\★'), 'c:/aaaa/bbbb/★') + }) + + test('not convert extended-length paths', ({ assert }) => { + const path = '\\\\?\\c:\\aaaa\\bbbb' + assert.equal(toUnixSlash(path), path) + }) +}) From 771f623dc7fc003759abf1468bf9607673b1e3cb Mon Sep 17 00:00:00 2001 From: thetutlage Date: Fri, 23 May 2025 09:45:11 +0000 Subject: [PATCH 3/9] chore(docs): update TOC --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 81b0e7d..117a59a 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ import string from '@poppinss/string' - [OPTIONS](#options-1) - [slug](#slug) - [interpolate](#interpolate) + - [slash](#slash) - [plural](#plural) - [singular](#singular) - [pluralize](#pluralize) From 4fcfa63d84b59b580ba2280c0e55e56368e3226d Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 23 May 2025 15:24:03 +0530 Subject: [PATCH 4/9] docs: fix docs to use toUnixSlash for the method name --- README.md | 101 +++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 117a59a..0f7ac7b 100644 --- a/README.md +++ b/README.md @@ -29,56 +29,57 @@ import string from '@poppinss/string' + **Table of Contents** - - [excerpt](#excerpt) - - [OPTIONS](#options) - - [truncate](#truncate) - - [OPTIONS](#options-1) - - [slug](#slug) - - [interpolate](#interpolate) - - [slash](#slash) - - [plural](#plural) - - [singular](#singular) - - [pluralize](#pluralize) - - [isPlural](#isplural) - - [isSingular](#issingular) - - [camelCase](#camelcase) - - [EXAMPLES](#examples) - - [capitalCase](#capitalcase) - - [EXAMPLES](#examples-1) - - [dashCase](#dashcase) - - [EXAMPLES](#examples-2) - - [dotCase](#dotcase) - - [EXAMPLES](#examples-3) - - [noCase](#nocase) - - [EXAMPLES](#examples-4) - - [pascalCase](#pascalcase) - - [EXAMPLES](#examples-5) - - [sentenceCase](#sentencecase) - - [EXAMPLES](#examples-6) - - [snakeCase](#snakecase) - - [EXAMPLES](#examples-7) - - [titleCase](#titlecase) - - [EXAMPLES](#examples-8) - - [wordWrap](#wordwrap) - - [OPTIONS](#options-2) - - [htmlEscape](#htmlescape) - - [EXAMPLES](#examples-9) - - [justify](#justify) - - [random](#random) - - [uuid](#uuid) - - [toSentence](#tosentence) - - [condenseWhitespace](#condensewhitespace) - - [ordinal](#ordinal) - - [seconds.parse](#secondsparse) - - [seconds.format](#secondsformat) - - [milliseconds.parse](#millisecondsparse) - - [milliseconds.format](#millisecondsformat) - - [bytes.parse](#bytesparse) - - [bytes.format](#bytesformat) - - [OPTIONS](#options-3) - - [String builder](#string-builder) +- [excerpt](#excerpt) + - [OPTIONS](#options) +- [truncate](#truncate) + - [OPTIONS](#options-1) +- [slug](#slug) +- [interpolate](#interpolate) +- [slash](#slash) +- [plural](#plural) +- [singular](#singular) +- [pluralize](#pluralize) +- [isPlural](#isplural) +- [isSingular](#issingular) +- [camelCase](#camelcase) + - [EXAMPLES](#examples) +- [capitalCase](#capitalcase) + - [EXAMPLES](#examples-1) +- [dashCase](#dashcase) + - [EXAMPLES](#examples-2) +- [dotCase](#dotcase) + - [EXAMPLES](#examples-3) +- [noCase](#nocase) + - [EXAMPLES](#examples-4) +- [pascalCase](#pascalcase) + - [EXAMPLES](#examples-5) +- [sentenceCase](#sentencecase) + - [EXAMPLES](#examples-6) +- [snakeCase](#snakecase) + - [EXAMPLES](#examples-7) +- [titleCase](#titlecase) + - [EXAMPLES](#examples-8) +- [wordWrap](#wordwrap) + - [OPTIONS](#options-2) +- [htmlEscape](#htmlescape) + - [EXAMPLES](#examples-9) +- [justify](#justify) +- [random](#random) +- [uuid](#uuid) +- [toSentence](#tosentence) +- [condenseWhitespace](#condensewhitespace) +- [ordinal](#ordinal) +- [seconds.parse](#secondsparse) +- [seconds.format](#secondsformat) +- [milliseconds.parse](#millisecondsparse) +- [milliseconds.format](#millisecondsformat) +- [bytes.parse](#bytesparse) +- [bytes.format](#bytesformat) + - [OPTIONS](#options-3) +- [String builder](#string-builder) - [Contributing](#contributing) - [Code of Conduct](#code-of-conduct) - [License](#license) @@ -222,7 +223,7 @@ string.interpolate('hello \\{{ users.0 }}', {}) // hello {{ users.0 }} ``` -### slash +### toUnixSlash Convert OS-specific file paths to Unix file paths. Credits [https://github.com/sindresorhus/slash](https://github.com/sindresorhus/slash) @@ -233,7 +234,7 @@ const value = path.join('foo', 'bar') // Unix => foo/bar // Windows => foo\\bar -string.slash(value) // foo/bar +string.toUnixSlash(value) // foo/bar ``` ### plural From 5e1b6a820424f35812620911ec4fb74a3c74b321 Mon Sep 17 00:00:00 2001 From: thetutlage Date: Fri, 23 May 2025 09:54:15 +0000 Subject: [PATCH 5/9] chore(docs): update TOC --- README.md | 97 +++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 0f7ac7b..dfadade 100644 --- a/README.md +++ b/README.md @@ -29,57 +29,56 @@ import string from '@poppinss/string' - **Table of Contents** -- [excerpt](#excerpt) - - [OPTIONS](#options) -- [truncate](#truncate) - - [OPTIONS](#options-1) -- [slug](#slug) -- [interpolate](#interpolate) -- [slash](#slash) -- [plural](#plural) -- [singular](#singular) -- [pluralize](#pluralize) -- [isPlural](#isplural) -- [isSingular](#issingular) -- [camelCase](#camelcase) - - [EXAMPLES](#examples) -- [capitalCase](#capitalcase) - - [EXAMPLES](#examples-1) -- [dashCase](#dashcase) - - [EXAMPLES](#examples-2) -- [dotCase](#dotcase) - - [EXAMPLES](#examples-3) -- [noCase](#nocase) - - [EXAMPLES](#examples-4) -- [pascalCase](#pascalcase) - - [EXAMPLES](#examples-5) -- [sentenceCase](#sentencecase) - - [EXAMPLES](#examples-6) -- [snakeCase](#snakecase) - - [EXAMPLES](#examples-7) -- [titleCase](#titlecase) - - [EXAMPLES](#examples-8) -- [wordWrap](#wordwrap) - - [OPTIONS](#options-2) -- [htmlEscape](#htmlescape) - - [EXAMPLES](#examples-9) -- [justify](#justify) -- [random](#random) -- [uuid](#uuid) -- [toSentence](#tosentence) -- [condenseWhitespace](#condensewhitespace) -- [ordinal](#ordinal) -- [seconds.parse](#secondsparse) -- [seconds.format](#secondsformat) -- [milliseconds.parse](#millisecondsparse) -- [milliseconds.format](#millisecondsformat) -- [bytes.parse](#bytesparse) -- [bytes.format](#bytesformat) - - [OPTIONS](#options-3) -- [String builder](#string-builder) + - [excerpt](#excerpt) + - [OPTIONS](#options) + - [truncate](#truncate) + - [OPTIONS](#options-1) + - [slug](#slug) + - [interpolate](#interpolate) + - [toUnixSlash](#tounixslash) + - [plural](#plural) + - [singular](#singular) + - [pluralize](#pluralize) + - [isPlural](#isplural) + - [isSingular](#issingular) + - [camelCase](#camelcase) + - [EXAMPLES](#examples) + - [capitalCase](#capitalcase) + - [EXAMPLES](#examples-1) + - [dashCase](#dashcase) + - [EXAMPLES](#examples-2) + - [dotCase](#dotcase) + - [EXAMPLES](#examples-3) + - [noCase](#nocase) + - [EXAMPLES](#examples-4) + - [pascalCase](#pascalcase) + - [EXAMPLES](#examples-5) + - [sentenceCase](#sentencecase) + - [EXAMPLES](#examples-6) + - [snakeCase](#snakecase) + - [EXAMPLES](#examples-7) + - [titleCase](#titlecase) + - [EXAMPLES](#examples-8) + - [wordWrap](#wordwrap) + - [OPTIONS](#options-2) + - [htmlEscape](#htmlescape) + - [EXAMPLES](#examples-9) + - [justify](#justify) + - [random](#random) + - [uuid](#uuid) + - [toSentence](#tosentence) + - [condenseWhitespace](#condensewhitespace) + - [ordinal](#ordinal) + - [seconds.parse](#secondsparse) + - [seconds.format](#secondsformat) + - [milliseconds.parse](#millisecondsparse) + - [milliseconds.format](#millisecondsformat) + - [bytes.parse](#bytesparse) + - [bytes.format](#bytesformat) + - [OPTIONS](#options-3) + - [String builder](#string-builder) - [Contributing](#contributing) - [Code of Conduct](#code-of-conduct) - [License](#license) From 23469dc5f342e3a61352bb29b60ea4b4eee65726 Mon Sep 17 00:00:00 2001 From: thetutlage Date: Fri, 23 May 2025 09:56:38 +0000 Subject: [PATCH 6/9] chore(release): 1.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 353eb1b..9c09c6e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@poppinss/string", "description": "A collection of helpers to perform operations on/related to a string value", - "version": "1.5.0", + "version": "1.6.0", "type": "module", "files": [ "build", From 78da94b7bd0db9b083a780556e17b54324feb945 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Sat, 5 Jul 2025 12:16:09 +0530 Subject: [PATCH 7/9] chore: update dependencies --- package.json | 20 ++++++++++---------- src/uuid.ts | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 9c09c6e..070a4ae 100644 --- a/package.json +++ b/package.json @@ -28,25 +28,25 @@ "quick:test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts" }, "devDependencies": { - "@adonisjs/eslint-config": "^2.0.0", - "@adonisjs/prettier-config": "^1.4.4", - "@adonisjs/tsconfig": "^1.4.0", + "@adonisjs/eslint-config": "^3.0.0-next.0", + "@adonisjs/prettier-config": "^1.4.5", + "@adonisjs/tsconfig": "^2.0.0-next.0", "@japa/assert": "^4.0.1", "@japa/expect": "^3.0.4", "@japa/expect-type": "^2.0.3", "@japa/file-system": "^2.3.2", "@japa/runner": "^4.2.0", "@japa/snapshot": "^2.0.8", - "@poppinss/colors": "^4.1.4", - "@poppinss/ts-exec": "^1.1.5", + "@poppinss/colors": "^4.1.5", + "@poppinss/ts-exec": "^1.4.0", "@release-it/conventional-changelog": "^10.0.1", - "@types/node": "^22.15.18", + "@types/node": "^24.0.10", "c8": "^10.1.3", - "eslint": "^9.26.0", - "prettier": "^3.5.3", - "release-it": "^19.0.2", + "eslint": "^9.30.1", + "prettier": "^3.6.2", + "release-it": "^19.0.3", "string-width": "^7.2.0", - "tsup": "^8.4.0", + "tsup": "^8.5.0", "typescript": "^5.8.3" }, "dependencies": { diff --git a/src/uuid.ts b/src/uuid.ts index 7bd7d9a..21a3d67 100644 --- a/src/uuid.ts +++ b/src/uuid.ts @@ -7,7 +7,7 @@ * file that was distributed with this source code. */ -import { randomUUID, RandomUUIDOptions, UUID } from 'node:crypto' +import { randomUUID, type RandomUUIDOptions, type UUID } from 'node:crypto' let uuidGenerator: typeof randomUUID = randomUUID From 98572b41d6432b823e9eeb7e8b5aa84bba1d2eda Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Sat, 5 Jul 2025 12:17:25 +0530 Subject: [PATCH 8/9] feat: add toUnixSlash method to the StringBuilder --- string_builder.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/string_builder.ts b/string_builder.ts index 2062f22..f51c855 100644 --- a/string_builder.ts +++ b/string_builder.ts @@ -187,6 +187,14 @@ export default class StringBuilder { return this } + /** + * Convert slashes to unix slash + */ + toUnixSlash(): this { + this.#value = string.toUnixSlash(this.#value) + return this + } + toString() { return this.#value } From 37e30c49b667f900662adb062c5fcc6db519d405 Mon Sep 17 00:00:00 2001 From: thetutlage Date: Sat, 5 Jul 2025 06:51:05 +0000 Subject: [PATCH 9/9] chore(release): 1.7.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 070a4ae..0bfa9f9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@poppinss/string", "description": "A collection of helpers to perform operations on/related to a string value", - "version": "1.6.0", + "version": "1.7.0", "type": "module", "files": [ "build",