From 473573026d4188ad5af720244b94bec849b08cb1 Mon Sep 17 00:00:00 2001 From: eeshsaxena Date: Fri, 31 Jul 2026 11:47:09 +0530 Subject: [PATCH] fix: normalize hyphens in `kebabcase` The `RE_SPECIAL` regular expression in `@stdlib/string/base/kebabcase` omitted the hyphen, unlike the equivalent `snakecase`, `camelcase`, and `constantcase` implementations. As a result, inputs mixing hyphens and whitespace produced runs of hyphens, e.g. `kebabcase( 'foo - bar' )` returned `'foo---bar'` instead of `'foo-bar'`, and `'foo--bar'` was left unchanged. Add the hyphen to `RE_SPECIAL` so hyphens are treated as word separators and collapsed like the other cases. Adds regression tests. --- .../@stdlib/string/base/kebabcase/lib/main.js | 2 +- .../@stdlib/string/base/kebabcase/test/test.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/kebabcase/lib/main.js b/lib/node_modules/@stdlib/string/base/kebabcase/lib/main.js index 04c1894b76c6..a631ac7388c9 100644 --- a/lib/node_modules/@stdlib/string/base/kebabcase/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/kebabcase/lib/main.js @@ -28,7 +28,7 @@ var trim = require( '@stdlib/string/base/trim' ); // VARIABLES // var RE_WHITESPACE = /\s+/g; -var RE_SPECIAL = /[!"'(),–.:;<>?`{}|~\/\\\[\]_#$*&^@%]+/g; // eslint-disable-line no-useless-escape +var RE_SPECIAL = /[\-!"'(),–.:;<>?`{}|~\/\\\[\]_#$*&^@%]+/g; // eslint-disable-line no-useless-escape var RE_CAMEL = /([a-z0-9])([A-Z])/g; diff --git a/lib/node_modules/@stdlib/string/base/kebabcase/test/test.js b/lib/node_modules/@stdlib/string/base/kebabcase/test/test.js index ecdbceced7bd..a6e611c3e6b0 100644 --- a/lib/node_modules/@stdlib/string/base/kebabcase/test/test.js +++ b/lib/node_modules/@stdlib/string/base/kebabcase/test/test.js @@ -47,7 +47,9 @@ tape( 'the function converts a string to kebab case', function test( t ) { 'foo bar baz', 'foo bar baz qux', 'foo_bar_baz_qux', - 'foo_bar baz qux' + 'foo_bar baz qux', + 'foo - bar', + 'foo--bar' ]; expected = [ @@ -60,7 +62,9 @@ tape( 'the function converts a string to kebab case', function test( t ) { 'foo-bar-baz', 'foo-bar-baz-qux', 'foo-bar-baz-qux', - 'foo-bar-baz-qux' + 'foo-bar-baz-qux', + 'foo-bar', + 'foo-bar' ]; for ( i = 0; i < values.length; i++ ) {