FORGEBOX Enterprise 🚀 - Take your ColdFusion (CFML) Development to Modern Times! Learn More...

str

v3.0.0 Public

str

A collection of string helper functions

Methods

plural

Pluralizes a word. Takes an optional count.

str.plural( "entity" );

// "entities"

str.plural( "tree", 1 );

// "tree"

slice

Takes a subset of a word from begin to end. If end is not provided, it will slice to the end of the word.

str.slice( "competent", 2, 4 );

// "omp"

str.slice( "competent", 2 );

// "ompetent"

startsWith

Returns whether a word starts with a given substring.

str.startsWith( "getDynamicMethod", "get" );

// true

str.startsWith( "setDynamicMethod", "get" );

// false

slug

Converts a string to a lowercased slug-delimited string with a given delimiter. Can take the character to use as the delimiter as the second argument. (Default: `-``)

str.slug( "My Post Title" );

// "my-post-title"

str.slug( "Another Post", "_" );

// "another_post"

snake

Converts a string to snake case.

str.snake( "Another Post" );

// "another_post"

kebab

Converts a string to kebab case.

str.kebab( "My Post Title" );

// "my-post-title"

studly

Converts a string to studly case.

str.studly( "My Post Title" );

// "MyPostTitle"

camel

Converts a string to camel case.

str.camel( "My Post Title" );

// "myPostTitle"

capitalizeWords

Capitalizes each word in a string.

str.capitalizeWords( "my post title" );

// "My Post Title"

capitalize

Capitalizes the beginning of the string. It takes an optional second parameter to preserve the casing of other words in the sentence. It defaults to false which means all other letters besides the first one will be lowercased.

str.capitalize( "my post title" );

// "My post title"

str.capitalize( str = "my pOsT tiTLe" );

// "My post title"

str.capitalize( str = "my pOsT tiTLe", preserveCase = true );

// "My pOsT tiTLe"

lowercaseWords

Capitalizes each word in a string.

str.lowercaseWords( "my post title" );

// "my post title"

lowercase

Capitalizes the beginning of the string. It takes an optional second parameter to preserve the casing of other words in the sentence. It defaults to false which means all other letters besides the first one will be lowercased.

str.lowercase( "My post title" );

// "my post title"

str.lowercase( str = "My pOsT tiTLe" );

// "my post title"

str.lowercase( str = "My pOsT tiTLe", preserveCase = true );

// "my pOsT tiTLe"

limit

Truncates the string at the specified limit and appends an ending character sequence. If the string is not longer than the limit, the entire string is returned unmodified. The ending character sequence can be passed in as the third argument. (Default: ...)

str.limit( "A short string", 20 );

// "A short string"

str.limit( "A really long sentence that I want to cut off", 20 );

// "A really long senten..."

str.limit( "A really long sentence that I want to cut off", 20, "---" );

// "A really long senten---"

limitWords

Truncates the string at the specified number of words and appends an ending character sequence. If the number of words in the string is not longer than the limit, the entire string is returned unmodified. The ending character sequence can be passed in as the third argument. (Default: ...)

str.limitWords( "A short string", 4 );

// "A short string"

str.limitWords( "A really long sentence that I want to cut off", 4 );

// "A really long sentence..."

str.limitWords( "A really long sentence that I want to cut off", 4, "---" );

// "A really long sentence---"

words

Splits a string into words and returns the words as an array. Splits on capital letters, underscores, and dashes.

str.words( "myCamelCaseString" );

// [ "my", "Camel", "Case", "String" ]

str.words( "MyMixed-caseString" );

// [ "My", "Mixed", "case", "String" ]

Dependencies (1)


Dev Dependencies (1)


v3.0.0

24 Aug 2021 — 03:08: 45 UTC

BREAKING

  • *: chore: Drop ACF 10, 11, and Lucee 4.5 (2b6146c)

chore

fix

  • capitalize: Capitalize the first word character (2414e7c)

other

  • *: fix: update ignore list (6293e8c)
  • *: fix: Fix losing words when adding space to capital letters (f367b15)
  • *: fix: Add space between periods when converting cases (0b00e31)
  • *: chore: Automatic formatting (83f0408)
  • *: chore: Migrate from Travis to GA (ad856c9)
  • *: 1.0.7 (916d95f)
  • *: 1.0.6 (b8030aa)
  • *: chore: Publish to forgeboxStorage (d2af4f0)
  • *: 1.0.5 (4740017)
  • *: fix: Fix postPublish script (7537a5e)
  • *: 1.0.4 (f74c580)
  • *: fix: Use variables.wirebox so it works on CommandBox as well (6d1793d)
  • *: 1.0.3 (a8afb07)
  • *: Merge pull request #3 from wpdebruin/patch-1 (9dbe7de)
  • *: bugfix global var (3c9b4f4)
  • *: 1.0.2 (989169a)
  • *: Remove all-contributors because emoji and ForgeBox are not friends (1667184)
  • *: 1.0.1 (417f58b)
  • *: Merge pull request #2 from joeltobey/master (2eedf76)
  • *: Use newer version of cbjavaloader (80f3eaf)
  • *: Remove CodeSponsor (0fc5ec9)
  • *: Add codesponsor to README (4e11335)
  • *: Add @elpete as a contributor (61f636c)
  • *: 1.0.0 (aa30b22)
  • *: Add documentation (0796384)
  • *: Make sure to initialize the pluralize java class (500b3e6)
  • *: Fix typo in java class path (4e661c7)
  • *: Add plural helper (3249221)
  • *: Add startsWith method (0c485a2)
  • *: Add slice method (245c293)
  • *: Add sublime-project file (b1c45c3)
  • *: Merge branch 'master' of github.com:elpete/str (e2df7a2)
  • *: Add testbox runner to box.json (43019a5)
  • *: add MIT License (ddbf68f)
  • *: Add slug and limit helpers (6c72fc2)
  • *: ACF compatibility (309bcf2)
  • *: Add more test cases around studly and camel casing (63d3315)
  • *: Add initial features like case conversion (1b354fc)
  • *: Remove unneeded test scaffolding (e0a3875)
  • *: Initial commit (6f772a2)

 

  •   Eric Peterson
  • Published
  • 3.0.0 is the latest of 11 release(s)
    Published
  • Published on {{ getFullDate("Aug 24 2021 03:08 AM GMT") }}
  • elpete/str

$ box install str

No collaborators yet.
     
  • {{ getFullDate("Aug 24 2021 03:08 AM GMT") }}
  • {{ getFullDate("Aug 24 2021 03:08 AM GMT") }}
  • 2,174
  • 0
  • 18,802