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-10/

Product Code Normalizer

Build a product code normalizer that converts product names into standardized codes for an e-commerce inventory system. The system needs to handle special symbols commonly found in product names and produce consistent, URL-safe identifiers.

Requirements

Your solution must:

  1. Convert product names to lowercase, URL-safe slugs
  2. Apply custom character mappings before any other transformations:
    • Convert '@' to 'at'
    • Convert '$' to 'dollar'
    • Convert '%' to 'percent'
    • Convert '+' to 'plus'
    • Convert '#' to 'number'
  3. Use hyphens as separators between words
  4. Export a function normalizeProductCode(productName: string): string that takes a product name and returns the normalized code

Test Cases

  • normalizeProductCode("Coffee @ Home") returns "coffee-at-home" @test
  • normalizeProductCode("Discount $50") returns "discount-dollar-50" @test
  • normalizeProductCode("Widget+Tool") returns "widget-plus-tool" @test
  • normalizeProductCode("Product #123") returns "product-number-123" @test
  • normalizeProductCode("Save 25%!") returns "save-25-percent" @test

Implementation

@generates

API

export function normalizeProductCode(productName: string): string;

Dependencies { .dependencies }

@sindresorhus/slugify { .dependency }

Provides string slugification with custom character replacement support.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-sindresorhus--slugify

tile.json