Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 784 Bytes

string.md

File metadata and controls

32 lines (21 loc) · 784 Bytes

String

string primitive

string/coerce

Restricted string coercion. Returns string presentation for every value that follows below constraints

  • is implicitly coercible to string
  • is neithernull nor undefined
  • its toString method is not Object.prototype.toString

For all other values null is returned

const coerceToString = require("type/string/coerce");

coerceToString(12); // "12"
coerceToString(undefined); // null

string/ensure

If given argument is a string coercible value (via string/coerce) returns result string. Otherwise TypeError is thrown.

const ensureString = require("type/string/ensure");

ensureString(12); // "12"
ensureString(null); // Thrown TypeError: null is not a string