@patrand/typexts v0.1.8
Typexts
A library giving some types useful extensions.
Simple example i bet you know:
Check if the string is empty. -Well not complex but annoying:
const test = "string";
if (test.length === 0) {
// ...
}
With typexts:
import "@patrand/typexts";
if (test.isEmpty()) {
// ...
}
Getting started
Usage
To get started include typexts in a top level file like index.ts
, main.ts
or just in the file where you want to use the extension.
Examples
Example:
import "@patrand/typexts";
const test = "iAmString";
if (test.isEmpty()) {
console.log("string is empty");
} else {
console.log("string is not empty");
}
Example 2:
import "@patrand/typexts";
const test = ["i", "am", "string", "array"];
test.print(); // is equal to `console.log(test)`
Example 3:
import "@patrand/typexts";
const test = {
any: "object",
can: "be",
easy: "printed",
};
test.print(); // is equal to `console.log(test)`
Includes
Include everything
The following will include all extensions.
Typscript:
import "@patrand/typexts";
Javascript:
In JavaScript you can use the same paths like for typescirpt just with require statement
const typexts = require("@patrand/typexts");
Single includes
In order to minimize the imports you can just import the extensions you need.
You can import extensions for only some types.
Example of only including StringExts:
import "@patrand/typexts/StringExts";
Here's a list of typexts packs:
1. import "@patrand/typexts/StringExts"
2. import "@patrand/typexts/ArrayExts"
3. import "@patrand/typexts/BooleanExts"
4. import "@patrand/typexts/ObjectExts"
5. import "@patrand/typexts/NumberExts"
Or in case you only need a specifc extension like isEmpty
for strings:
import "@patrand/typexts/string/IsEmpty";
// Or import multiple extensions
import "@patrand/typexts/string/IsEmpty";
import "@patrand/typexts/string/IsNotEmpty";
List of features
Strings
isEmpty
isNotEmpty
isNumber
print
reverse
isUrl
Array
isEmpty
isNotEmpty
print
reverse
Boolean
print
on
onFalse
onTrue
Number
isPositive
isNegative
isZero
Object
print
printJson