Skip to content

uncaughterrol/smartstring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

SmartString

Java License Lightweight Maven Central

SmartString is a lightweight Java library for string case conversion, pluralization, and fluent string transformations.

It provides both:

  • SmartStringUtils – static utility methods
  • SmartString – a fluent chainable wrapper

The library is dependency-free, fast, and designed for everyday backend or tooling tasks.


Features

  • Convert between common naming conventions
  • Fluent chainable API
  • Singular ↔ plural conversion
  • Support for irregular word mappings
  • Zero external dependencies
  • Small and fast

Installation

Maven

<dependency>
    <groupId>io.github.uncaughterrol</groupId>
    <artifactId>smartstring</artifactId>
    <version>0.1.0</version>
</dependency>

Gradle

implementation 'io.github.uncaughterrol:smartstring:0.1.0'

Quick Start

Fluent API (SmartString)

SmartString provides a chainable API for transforming strings.

import io.github.uncaughterrol.smartstring.SmartString;

public class Example {

    public static void main(String[] args) {

        String result = SmartString.of("user_profile")
                .toCamelCase()
                .toPlural()
                .capFirst()
                .getValue();

        System.out.println(result);
        // UserProfiles
    }
}

Static Utility Usage (SmartStringUtils)

If you prefer static utility methods, you can use SmartStringUtils.

import io.github.uncaughterrol.smartstring.SmartStringUtils;

public class Example {

    public static void main(String[] args) {

        String snake = SmartStringUtils.toSnakeCase("HelloWorldExample");
        System.out.println(snake);
        // hello_world_example

        String camel = SmartStringUtils.toCamelCase("hello_world");
        System.out.println(camel);
        // helloWorld

        String pascal = SmartStringUtils.toPascalCase("hello_world");
        System.out.println(pascal);
        // HelloWorld
    }
}

Pluralization

import io.github.uncaughterrol.smartstring.SmartStringUtils;

public class Example {

    public static void main(String[] args) {

        System.out.println(SmartStringUtils.toPlural("city"));
        // cities

        System.out.println(SmartStringUtils.toPlural("box"));
        // boxes

        System.out.println(SmartStringUtils.toPlural("dog"));
        // dogs
    }
}

Singularization

import io.github.uncaughterrol.smartstring.SmartStringUtils;

public class Example {

    public static void main(String[] args) {

        System.out.println(SmartStringUtils.toSingular("cities"));
        // city

        System.out.println(SmartStringUtils.toSingular("boxes"));
        // box
    }
}

Irregular Word Support

You can define irregular plural mappings in:

irregular-mapping.properties

Example:

children=child
men=man
women=woman
people=person

The file is automatically loaded from the classpath.


License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages