JCC Express

Digging Deeper

Strings

Introduction

JCC Express MVC provides string utilities through Str, available as a global helper (str()) or via import from jcc-express-mvc/Core/Str.

TypeScript
import { Str } from "jcc-express-mvc/Core/Str";
// or:
const S = str();

Common transformations

TypeScript
Str.slug("Hello World"); // "hello-world"
Str.slug("Hello World", true); // "hello-world-abc12"

Str.camel("user_profile"); // "userProfile"
Str.snake("userProfile"); // "user_profile"
Str.kebab("userProfile"); // "user-profile"

Str.upper("hello"); // "HELLO"
Str.lower("HELLO"); // "hello"
Str.title("hello world"); // "Hello World"
Str.capitalize("hello"); // "Hello"

Inflection helpers

Backed by inflection:

TypeScript
Str.plural("category"); // "categories"
Str.singular("users"); // "user"

Str.pluralCamel("user"); // "users"
Str.singularSnake("UsersProfile"); // "user_profile"
Str.pluralTitle("person"); // "People"

There are multiple variants (plural*, singular*) for casing styles.


Search and extraction helpers

TypeScript
Str.contains("hello world", "world"); // true
Str.containsAll("a,b,c", ["a", "b"]); // true
Str.containsAny("a,b,c", ["x", "b"]); // true
Str.doesNotContain("hello", "x"); // true

Str.before("foo@bar.com", "@"); // "foo"
Str.after("foo@bar.com", "@"); // "bar.com"
Str.beforeLast("a.b.c", "."); // "c" (implementation behavior)
Str.afterLast("a.b.c", "."); // "c"
Str.between("id=[123]", "[", "]"); // "123"
Str.betweenLast("x[a]y[b]", "[", "]"); // "b"

Note: methods reflect current implementation behavior exactly.


Formatting and masking

TypeScript
Str.limit("This is long text", 7); // "This is..."
Str.padLeft("7", 3, "0"); // "007"
Str.padRight("7", 3, "0"); // "700"
Str.padBoth("A", 5, "-"); // "--A--"

Str.mask("1234567890", 2, 2); // "12******90"
Str.deduplicate("hello    world"); // "hello world"
Str.finish("path/to/dir", "/"); // "path/to/dir/"

Encoding and validation helpers

TypeScript
Str.base64Encode("hello");
Str.base64Decode("aGVsbG8=");

Str.isJson('{"ok":true}'); // true
Str.isUrl("https://example.com"); // true
Str.count("hello"); // 5
Str.position("hello", "ll"); // 2

IDs and generated values

TypeScript
Str.random(16);
Str.password(12);
Str.orderedUuid();

Summary

  • Use str() or Str for reusable string operations.
  • Includes casing, inflection, extraction, masking, encoding, and generation helpers.
  • Favor these helpers to keep transformations consistent across your app.