UIZE JavaScript Framework

MODULES Uize.Str.Camel

1. Introduction

The Uize.Str.Camel module provides convenience methods for dealing with camelCased strings.

DEVELOPERS: Chris van Rensburg

1.1. Examples

There are no dedicated showcase example pages for the Uize.Str.Camel module.

SEARCH FOR EXAMPLES

Use the link below to search for example pages on the UIZE Web site that reference the Uize.Str.Camel module...

SEARCH

1.2. Implementation Info

The Uize.Str.Camel module defines the Uize.Str.Camel package under the Uize.Str namespace.

1.2.1. Features Introduced in This Module

The features listed in this section have been introduced in this module.

STATIC METHODS

Uize.Str.Camel.from | Uize.Str.Camel.to

STATIC PROPERTIES

Uize.Str.Camel.moduleName | Uize.Str.Camel.pathToResources

1.2.2. Features Overridden in This Module

No features have been overridden in this module.

1.2.3. Features Inherited From Other Modules

This module has no inherited features.

1.2.4. Modules Directly Under This Namespace

There are no modules directly under this namespace.

1.2.5. Unit Tests

The Uize.Str.Camel module is unit tested by the Uize.Test.Uize.Str.Camel test module.

2. Static Methods

2.1. Uize.Str.Camel.from

Returns a string, that is the specified source string converted from a camelCase formatted string to a delimited string.

DIFFERENT USAGES

Convert a camelCased String to a Hyphenated String

hyphenatedSTR = Uize.Str.Camel.from (sourceSTR);

Convert a camelCased String to a Delimited String, With Options

hyphenatedSTR = Uize.Str.Camel.from (sourceSTR,optionsOBJ);

Convert a camelCased String to a Hyphenated String, Without Lowercasing

hyphenatedSTR = Uize.Str.Camel.from (sourceSTR,{lowerCaseFirstChar:false});

Convert a camelCased String to a Delimited String, Specifying a Custom Delimiter

delimitedSTR = Uize.Str.Camel.from (sourceSTR,{delimiter:delimiterSTR});

2.1.1. Convert a camelCased String to a Hyphenated String

In the simplest use case, a camelCased string can be converted to a hyphenated string by specifying the camelCased source string as the first argument.

SYNTAX

hyphenatedSTR = Uize.Str.Camel.from (sourceSTR);

EXAMPLES

Uize.Str.Camel.from ('city');            // returns 'city'
Uize.Str.Camel.from ('cityStateZip');    // returns 'city-state-zip'
Uize.Str.Camel.from ('CityStateZip');    // returns 'city-state-zip'
Uize.Str.Camel.from ('propertyAValue');  // returns 'property-a-value'

2.1.2. Convert a camelCased String to a Delimited String, With Options

When the default behavior of the method is not suitable, the method's behavior can be customized by specifying the optional optionsOBJ second argument.

SYNTAX

hyphenatedSTR = Uize.Str.Camel.from (sourceSTR,optionsOBJ);

2.1.2.1. optionsOBJ

An object, containing properties for specifying conversion options.

SYNTAX

{
  delimiter:delimiterSTR,
  lowerCaseFirstChar:lowerCaseFirstCharBOOL
}
2.1.2.1.1. delimiter

A string, specifying a set of characters that should be used to delimit the words parsed from the camelCased source string.

The value of the delimiter property may be any string, containing zero or more characters. Typically, the value will be a single character, but multi-character delimiters are acceptable. If no value is specified for the delimiter property, or if the value null or undefined is specified, then the value for this property is defaulted to a '-' (hyphen) character.

2.1.2.1.2. lowerCaseFirstChar

A boolean, specifying whether or not the first character of each of the words parsed from the camelCased source string should be lowercased.

When the value false is specified for the lowerCaseFirstChar property, the first character of each word will not be lowercased and will be left as is. For words after the first word, this will mean that the characters will remain uppercased, although it is possible for the camelCased source string to also start with an uppercase letter. If no value is specified for the lowerCaseFirstChar property, or if the value null or undefined is specified, then the value for this property is defaulted to true.

2.1.3. Convert a camelCased String to a Hyphenated String, Without Lowercasing

A camelCased source string can be converted to a hyphenated string without lowercasing of the first letters of words by specifying the value false for the lowerCaseFirstChar option.

SYNTAX

hyphenatedSTR = Uize.Str.Camel.from (sourceSTR,{lowerCaseFirstChar:false});

EXAMPLES

Uize.Str.Camel.from ('city',{lowerCaseFirstChar:false});            // returns 'city'
Uize.Str.Camel.from ('cityStateZip',{lowerCaseFirstChar:false});    // returns 'city-State-Zip'
Uize.Str.Camel.from ('CityStateZip',{lowerCaseFirstChar:false});    // returns 'City-State-Zip'
Uize.Str.Camel.from ('propertyAValue',{lowerCaseFirstChar:false});  // returns 'property-A-Value'

2.1.4. Convert a camelCased String to a Delimited String, Specifying a Custom Delimiter

A camelCased source string can be converted to a delimited string with a custom delimiter, by specifying the custom delimiter for the delimiter option.

SYNTAX

delimitedSTR = Uize.Str.Camel.from (sourceSTR,{delimiter:delimiterSTR});

EXAMPLE

Uize.Str.Camel.from ('cityStateZip',{delimiter:'-'});    // returns 'city-state-zip'
Uize.Str.Camel.from ('cityStateZip',{delimiter:'_'});    // returns 'city_state_zip'
Uize.Str.Camel.from ('cityStateZip',{delimiter:', '});   // returns 'city, state, zip'
Uize.Str.Camel.from ('cityStateZip',{delimiter:''});     // returns 'citystatezip'
Uize.Str.Camel.from ('cityStateZip',{delimiter:'#'});    // returns 'city#state#zip'
Uize.Str.Camel.from ('cityStateZip',{delimiter:' + '});  // returns 'city + state + zip'

NOTES

compare to the companion Uize.Str.Camel.to static method

IMPLEMENTATION INFO

this feature was introduced in this module

2.2. Uize.Str.Camel.to

Returns a string, that is the specified source string converted to a camelCase formatted string.

SYNTAX

camelCaseSTR = Uize.Str.Camel.to (sourceSTR);

This method removes all non-word characters separating words in the source string, capitalizes the first letters of the words, and lowercases all other letters.

EXAMPLES

Uize.Str.Camel.to ('encode HTML entity');    // returns 'encodeHtmlEntity'
Uize.Str.Camel.to ('XML document');          // returns 'xmlDocument'
Uize.Str.Camel.to ('XML document',true);     // returns 'XmlDocument'
Uize.Str.Camel.to ('city, state, zip');      // returns 'cityStateZip'
Uize.Str.Camel.to ('uize.com');          // returns 'wwwUizeCom'
Uize.Str.Camel.to ('theme/css/button.css');  // returns 'themeCssButtonCss'
Uize.Str.Camel.to ('nav-arrow-horz-next');   // returns 'navArrowHorzNext'
Uize.Str.Camel.to ('json 2 XML');            // returns 'json2Xml'
Uize.Str.Camel.to ('--hyphens-are-cool--');  // returns 'hyphensAreCool'

The above example illustrates how the method will behave with a variety of input values.

VARIATION

camelCaseSTR = Uize.Str.Camel.to (sourceSTR,capFirstCharBOOL);

By default, the first letter of the camelCased string is lowercase, although the optional capFirstCharBOOL parameter allows control over this behavior. Specify the value true for this parameter and the first letter of the camelCased string will be uppercase.

VARIATION

camelCaseSTR = Uize.Str.Camel.to (stringSegmentsARRAY);

In addition to being able to camelCase a source string, the Uize.Str.Camel.to method can also generate a camelCase string from an array of string segments.

EXAMPLE

Uize.Str.Camel.to (['city','state','zip']);  // returns 'cityStateZip'

VARIATION

camelCaseSTR = Uize.Str.Camel.to (stringSegmentsARRAY,capFirstCharBOOL);

Naturally, the optional capFirstCharBOOL parameter can also be used when the stringSegmentsARRAY parameter is specified.

NOTES

compare to the companion Uize.Str.Camel.from static method

IMPLEMENTATION INFO

this feature was introduced in this module

3. Static Properties

3.1. Uize.Str.Camel.moduleName

IMPLEMENTATION INFO

this feature was introduced in this module

3.2. Uize.Str.Camel.pathToResources

IMPLEMENTATION INFO

this feature was introduced in this module