scule

repository·main·Indexed 19 days ago

https://github.com/unjs/scule

A utility library for string case conversion and manipulation, providing functions to convert strings or arrays of strings between camelCase, PascalCase, kebab-case, flatcase, and Title Case, as well as capitalization utilities like upperFirst and lowerFirst.

Tokens
915
Snippets
7
Records
8
Agent score
18%

What's inside scule

  1. Split a string by case or separators

    main
    The splitByCase function breaks a string into an array of parts based on case changes (e.g., camelCase to ['camel', 'Case']) or specific separators. By default, it uses `[
  2. Convert strings to Title Case

    main

    Convert a string or an array of strings to Title Case (parts joined by spaces). This function includes logic to keep specific small words (e.g., 'a', 'an', 'the', 'of', 'to') in lowercase unless they are at the start of a part. You can use normalize: true to ensure consistent casing.

    import { titleCase } from 'scule';
    
    titleCase('the lord of the rings'); // 'The Lord of the Rings'
    titleCase(['the', 'lord', 'of', 'the', 'rings']); // 'The Lord of the Rings'
  3. Configure case transformation with CaseOptions

    main

    When using Scule's case transformation functions, you can provide an optional CaseOptions object to control how strings are processed. The primary option is normalize, which determines whether words should be lowercased before being transformed (e.g., during PascalCase or TrainCase operations).

    export type CaseOptions = {
      normalize?: boolean;
    };
  4. Check if a character is uppercase

    main

    The isUppercase function checks if a given character is an uppercase letter. It returns undefined if the character is a number.

    import { isUppercase } from 'scule';
    
    isUppercase('A'); // true
    isUppercase('a'); // false
    isUppercase('1'); // undefined
  5. Convert strings to flatCase

    main

    Convert a string or an array of strings to flatcase by joining parts with an empty string ("").

    import { flatCase } from 'scule';
    
    flatCase('hello-world'); // 'helloworld'
    flatCase(['hello', 'world']); // 'helloworld'
  6. Convert strings to kebabCase

    main

    Convert a string or an array of strings to kebab-case. You can optionally specify a custom joiner string to replace the default hyphen (-).

    import { kebabCase } from 'scule';
    
    // Default hyphen
    kebabCase('helloWorld'); // 'hello-world'
    
    // Custom joiner
    kebabCase('helloWorld', '.'); // 'hello.world'
    
    // From array
    kebabCase(['hello', 'world']); // 'hello-world'
  7. Manipulate string capitalization

    main

    Use upperFirst and lowerFirst to capitalize or uncapitalize only the first character of a string without affecting the rest of the string.

    import { upperFirst, lowerFirst } from 'scule';
    
    upperFirst('hello'); // 'Hello'
    lowerFirst('Hello'); // 'hello'
  8. Convert strings to camelCase

    main

    Convert a string or an array of strings to camelCase. This is implemented by generating a PascalCase string and then applying lowerFirst to the result.

    import { camelCase } from 'scule';
    
    // From string
    camelCase('hello-world'); // 'helloWorld'
    
    camelCase('HELLO_WORLD', { normalize: true }); // 'helloWorld'
    
    // From array
    camelCase(['hello', 'world']); // 'helloWorld'