CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sindresorhus--slugify

Slugify a string with comprehensive Unicode transliteration and extensive customization options

94

1.34x
Overview
Eval results
Files

task.mdevals/scenario-5/

Brand Name Formatter

Overview

Create a command-line tool that processes a list of brand names and formats them for different contexts. The tool should handle case conversion, transliteration, and generate URL-friendly identifiers.

Requirements

You will receive brand names that may contain:

  • Mixed case letters (uppercase, lowercase, camelCase)
  • Unicode characters from various languages
  • Special characters and symbols

Your tool must:

  1. Read Input: Accept a JSON file containing an array of brand names
  2. Generate Output: Create a JSON file with formatted versions of each brand name:
    • original: The original brand name
    • lowercase: A lowercase ASCII version of the brand name (transliterated if needed)
    • uppercase: An uppercase ASCII version of the brand name (transliterated if needed)
    • slug: A URL-friendly slug version (lowercase, hyphen-separated)

Implementation Details

  • Read brand names from brands.json (an array of strings)
  • Write output to formatted-brands.json
  • All output values should be ASCII-only (transliterate Unicode characters)
  • The slug version should replace spaces and special characters with hyphens
  • Handle empty strings and whitespace appropriately

Example

Input (brands.json)

[
  "FooBar Technologies",
  "Café München",
  "北京科技",
  "Mix3dCase"
]

Expected Output (formatted-brands.json)

[
  {
    "original": "FooBar Technologies",
    "lowercase": "foobar technologies",
    "uppercase": "FOOBAR TECHNOLOGIES",
    "slug": "foobar-technologies"
  },
  {
    "original": "Café München",
    "lowercase": "cafe munchen",
    "uppercase": "CAFE MUNCHEN",
    "slug": "cafe-munchen"
  },
  {
    "original": "北京科技",
    "lowercase": "bei jing ke ji",
    "uppercase": "BEI JING KE JI",
    "slug": "bei-jing-ke-ji"
  },
  {
    "original": "Mix3dCase",
    "lowercase": "mix3dcase",
    "uppercase": "MIX3DCASE",
    "slug": "mix3dcase"
  }
]

Test Cases { .test }

Create a test file named formatter.test.js with the following test cases:

Test 1: Basic ASCII lowercase conversion { .test @test }

Input:

["Hello World", "TESTING"]

Expected Output:

[
  {
    "original": "Hello World",
    "lowercase": "hello world",
    "uppercase": "HELLO WORLD",
    "slug": "hello-world"
  },
  {
    "original": "TESTING",
    "lowercase": "testing",
    "uppercase": "TESTING",
    "slug": "testing"
  }
]

Test 2: Unicode transliteration with case conversion { .test @test }

Input:

["Zürich", "Москва"]

Expected Output:

[
  {
    "original": "Zürich",
    "lowercase": "zurich",
    "uppercase": "ZURICH",
    "slug": "zurich"
  },
  {
    "original": "Москва",
    "lowercase": "moskva",
    "uppercase": "MOSKVA",
    "slug": "moskva"
  }
]

Test 3: CamelCase handling { .test @test }

Input:

["iPhone", "macOS"]

Expected Output:

[
  {
    "original": "iPhone",
    "lowercase": "iphone",
    "uppercase": "IPHONE",
    "slug": "iphone"
  },
  {
    "original": "macOS",
    "lowercase": "macos",
    "uppercase": "MACOS",
    "slug": "macos"
  }
]

Dependencies { .dependencies }

@sindresorhus/slugify { .dependency }

Provides string slugification and transliteration support.

Install with Tessl CLI

npx tessl i tessl/npm-sindresorhus--slugify

tile.json