String

License

MIT-style license.

Author

Takashi Mizohata bea.nosp@m.tak@nydd.nosp@m..org

Copyright

2008 [nydd](http://code.nydd.org/).

Code & Documentation

[nydd jslib](http://code.nydd.org/).

Inspiration

Everything is worthwhile / if the soul isn’t small.

Summary
StringMIT-style license.
Constants
PRIVATE_REGEX_TRIMOptimization for trim()
Functions
fillRepeat chunk of sting.
paddingAlign length of string.
reverseReverse the order of given string.
trimTrim empty characters on both side.

Constants

PRIVATE_REGEX_TRIM

Optimization for trim()

PRIVATE_REGEX_TRIMnew RegExp(/^\s+|\s+$/g)

Functions

fill

String.fill = function (filler,
len)

Repeat chunk of sting.

Type

static

Parameters

filleranything but Function nor Object.  Eventually casted to String
len(Number) expected length

Examples

String.fill(‘abc’, 7) // “abcabca”

Retruns

(String) repeated string with given number of length.

padding

String.padding = function (hay,
len,
filler,
dirc)

Align length of string.

Type

static

Parameters

hayanything but Function nor Object.  Eventually casted to String
len(Number) expected length
filleranything but Function nor Object.  Eventually casted to String
dirc[option] (Boolean) direction of filling.  true for Left align, false for right align and null for justify.

Examples

  • String.padding(123, 5, 0) // “00123”
  • String.padding(‘name’, 6, ‘*’, true) // “**name”
  • String.padding(‘foo’, 9, ‘+’, null) // “+++foo+++”

Retruns

(String) given length of string hay with filled by filler

reverse

String.reverse = function (str)

Reverse the order of given string.

Type

static

Parameters

stranything but Function nor Object.  Eventually casted to String

Examples

String.reverse(‘abc’) // “cba”

Retruns

(String) reversed order string

trim

String.trim = function (str)

Trim empty characters on both side.

Type

static

Parameters

str(String)

Examples

String.trim(“\t foo \n”) // “foo”

Retruns

(String) string without empty chars on both side.

String.fill = function (filler,
len)
Repeat chunk of sting.
String.padding = function (hay,
len,
filler,
dirc)
Align length of string.
String.reverse = function (str)
Reverse the order of given string.
String.trim = function (str)
Trim empty characters on both side.
Close