Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kebab-case

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kebab-case - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

eslint.config.js

33

index.d.ts

@@ -1,9 +0,26 @@

type Fn = (str: string) => string;
interface KebabCase extends Fn {
reverse: Fn
export default kebabCase;
/**
* Transforms a string into kebab-case.
*
* @example
* kebabCase("helloWorld"); // "hello-world"
* kebabCase("HelloWorld"); // "-hello-world"
* kebabCase("HelloWorld", false); // "hello-world"
*
* @param {string} str The string to transform
* @param {boolean} keepLeadingDash Whether to keep the leading dash in case the string starts with an uppercase letter (default: true)
* @returns The kebab-cased string
*/
declare function kebabCase(str: string, keepLeadingDash?: boolean): string | undefined;
declare namespace kebabCase {
/**
* Transforms a kebab-cased string back to the original string.
*
* @example
* kebabCase.reverse("hello-world"); // "helloWorld"
*
* @param {string} str
* @returns The original string, with the kebab-case transformation reversed
*/
function reverse(str: string): string;
}
const kebabCase: KebabCase;
export default kebabCase;

@@ -1,15 +0,39 @@

'use strict';
var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g;
var REVERSE_REGEX = /-[a-z\u00E0-\u00F6\u00F8-\u00FE]/g;
const KEBAB_REGEX = /\p{Lu}/gu;
const REVERSE_REGEX = /-\p{Ll}/gu;
module.exports = exports = function kebabCase(str) {
return str.replace(KEBAB_REGEX, function (match) {
return '-' + match.toLowerCase();
});
/**
* Transforms a string into kebab-case.
*
* @example
* kebabCase("helloWorld"); // "hello-world"
* kebabCase("HelloWorld"); // "-hello-world"
* kebabCase("HelloWorld", false); // "hello-world"
*
* @param {string} str The string to transform
* @param {boolean} keepLeadingDash Whether to keep the leading dash in case the string starts with an uppercase letter (default: true)
* @returns The kebab-cased string
*/
const kebabCase = (str, keepLeadingDash = true) => {
const result = str.replace(KEBAB_REGEX, (match) => `-${match.toLowerCase()}`);
if (keepLeadingDash) {
return result;
}
if (result.startsWith("-")) {
return result.slice(1);
}
};
exports.reverse = function (str) {
return str.replace(REVERSE_REGEX, function (match) {
return match.slice(1).toUpperCase();
});
};
/**
* Transforms a kebab-cased string back to the original string.
*
* @example
* kebabCase.reverse("hello-world"); // "helloWorld"
*
* @param {string} str
* @returns The original string, with the kebab-case transformation reversed
*/
kebabCase.reverse = (str) => str.replace(REVERSE_REGEX, (match) => match.slice(1).toUpperCase());
export default kebabCase;
{
"name": "kebab-case",
"version": "1.0.2",
"version": "2.0.0",
"description": "Convert a string to kebab-case, i.e. its dash separated form",
"main": "index.js",
"type": "module",
"types": "index.d.ts",
"scripts": {
"lint": "eslint *.js",
"pretest": "npm run lint -s",
"test": "node test.js"
"test": "node --test test.js",
"types": "tsc"
},

@@ -32,5 +35,8 @@ "repository": {

"devDependencies": {
"eslint": "^7.21.0",
"zora": "^4.0.2"
}
"@eslint/js": "^9.5.0",
"eslint": "^9.5.0",
"globals": "^15.6.0",
"typescript": "^5.5.2"
},
"packageManager": "pnpm@9.4.0"
}

@@ -28,3 +28,3 @@ # kebab-case

```javascript
var kebabCase = require("kebab-case");
import kebabCase from "kebab-case";

@@ -35,2 +35,4 @@ kebabCase("WebkitTransform");

// "WebkitTransform"
kebabCase("WebkitTransform", false);
// "webkit-transform"
```

@@ -42,5 +44,6 @@

| Name | Type | Description |
| ---- | -------- | --------------------- |
| str | `String` | The string to convert |
| Name | Type | Description |
| --------------- | --------- | ----------------------------------------------------------- |
| str | `String` | The string to convert |
| keepLeadingDash | `Boolean` | Whether to keep the leading dash or not. Default is `true`. |

@@ -47,0 +50,0 @@ Returns: `String`, the kebab cased string.

@@ -1,28 +0,33 @@

"use strict";
const { test } = require("zora");
const kebabCase = require("./");
import { test } from 'node:test';
import assert from 'node:assert';
import kebabCase from "./index.js";
test("string with uppercased letters", (t) => {
t.equal(kebabCase("helloWorld"), "hello-world");
t.equal(kebabCase("hello World!"), "hello -world!");
test("string with uppercased letters", () => {
assert.strictEqual(kebabCase("helloWorld"), "hello-world");
assert.strictEqual(kebabCase("hello World!"), "hello -world!");
});
test("string without uppercased letters", (t) => {
t.equal(kebabCase("hello world"), "hello world");
t.equal(kebabCase("-- hello world --"), "-- hello world --");
test("string without uppercased letters", () => {
assert.strictEqual(kebabCase("hello world"), "hello world");
assert.strictEqual(kebabCase("-- hello world --"), "-- hello world --");
});
test("string with leading uppercased letters", (t) => {
t.equal(kebabCase("WebkitTransform"), "-webkit-transform");
t.equal(kebabCase("Mr. Kebab"), "-mr. -kebab");
test("string with leading uppercased letters", () => {
assert.strictEqual(kebabCase("WebkitTransform"), "-webkit-transform");
assert.strictEqual(kebabCase("Mr. Kebab"), "-mr. -kebab");
});
test("string with international uppercased letters", (t) => {
t.equal(kebabCase("ølÜberÅh"), "øl-über-åh");
t.equal(kebabCase("Érnest"), "-érnest");
test("string with leading uppercased letters when ditching the leading slash", () => {
assert.strictEqual(kebabCase("WebkitTransform", false), "webkit-transform");
assert.strictEqual(kebabCase("Mr. Kebab", false), "mr. -kebab");
});
test("the reverse", (t) => {
test("string with international uppercased letters", () => {
assert.strictEqual(kebabCase("ølÜberÅh"), "øl-über-åh");
assert.strictEqual(kebabCase("Érnest"), "-érnest");
});
test("the reverse", () => {
const str = "Hallå, Mr. Kebab Überstein! How you doin'?-";
t.equal(kebabCase.reverse(kebabCase(str)), str);
assert.strictEqual(kebabCase.reverse(kebabCase(str)), str);
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc