Skip to content

Feature: Type: String

Аниса edited this page Sep 9, 2022 · 4 revisions

━ What's the Objective?

JS provides built in String module by default, however its deprived of certain functions that may usually be needed (formatting and such). Not to mention default string APIs also doesn't support numeric inputs, while Vital.kit's implementation does!

━ APIs

ℹ️ Note:

Our extensions are written with backwards compatibility in mind; Expect your previous code to work as usual! However we recommend upgrading to newer syntax.

You can also provide a number as value to below APIs and expect it work similar to string values; Returns will be automatically converted to your input's type!


━ vKit.String() (Shared)

@Objective: Converts a value to string.
const string: result = vKit.String(
  ~: value
)

━ vKit.String.isVoid() (Shared)

@Objective: Verifies whether the value is void.
const bool: result = vKit.String.isVoid(
  string: value
)

━ vKit.String.sub() (Shared)

@Objective: Retrieves subset of the provided value.
const string: result = vKit.String.sub(
  string: value,
  int: startIndex,
  int: endIndex
)

━ vKit.String.replace() (Shared)

@Objective: Replaces matches of the provided value.
const string: result = vKit.String.replace(
  string: value,
  string: matchValue, // Regex is supported too
  string: replaceValue
)

━ vKit.String.match() (Shared)

@Objective: Retrieves matches of the provided value.
const string: result = vKit.String.match(
  string: value,
  string: matchValue // Regex is supported too
)

━ vKit.String.format() (Shared)

@Objective: Formats the value using provided values.
⚠️ Formatting strictly works based on notation: %argIndex.
const string: result = vKit.String.format(
  string: value,
  ~: ...arguments
)

// Example:
rwText = vKit.String("My name is %0, I am from %1.", "Anisa", "Russia")

━ vKit.String.split() (Shared)

@Objective: Splits the value using provided separator.
const array: result = vKit.String.split(
  string: value,
  string: separator
)

━ vKit.String.detab() (Shared)

@Objective: Converts all tabs of provided value to spaces.
const string: result = vKit.String.detab(
  string: value
)