String and array manipulation, easy-to-use fetch controller and more, written in Typescript.
colorGenerator
Given a starting RGB value and an ending RGB value, it RETURNs a range of colors generated by its factor.
PARAMETERS
Type | Description | Optional |
---|---|---|
Array | Starting array with RGB values, e.g. [255, 255, 255] | No |
Array | Ending array with RGB values, e.g. [255, 255, 255] | No |
Number | The factor which will multiply the values. | No |
RETURN
Array with generated string RGB values in the following format: "rgba(r,g,b,a)"
import { colorGenerator } from "uno-js";
const x = [0, 0, 0];
const y = [90, 60, 30];
colorGenerator(x, y, 3);
// => ["rgba(0,0,0, 1)", "rgba(45,30,15, 1)", "rgba(90,60,30, 1)"]
Open CodeSandbox
debounce
This function delays its execution and if the function is called again, it interrupts the first one and restarts the timer, so this ensures that the function is only called once in the lapse defined.
PARAMETERS
Type | Description | Optional |
---|---|---|
Function | Function to be executed after the lapse finishes. | No |
Number | Milliseconds until the function will execute. | No |
RETURN
Function, it will be executed once the lapse finishes without interruptions.
import { debounce } from 'uno-js';
const fn = debounce(() => {
console.log('Hello!');
}, 150);
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
const showDebounce = async () => {
fn();
await delay(100);
fn();
await delay(100);
fn();
await delay(300);
}
showDebounce();
Open CodeSandbox
humanize
It returns a humanized string.
PARAMETERS
Type | Description | Optional |
---|---|---|
String | String to humanize | No |
RETURN
A humanized string
import { humanize } from "uno-js";
const toHumanize = humanize("thisIsAnAwesomeExample");
// => This Is An Awesome Example
Open CodeSandbox
objectDifference
Get the difference between 2 objects and RETURN an object with the previous and new values of each difference.
PARAMETERS
Type | Description | Optional |
---|---|---|
Object | First object to be compared. | No |
Object | Second object to be compared. | No |
RETURN
Returns an object where each prop is an object with the difference, formated as:
{[prop]: {prev:
"Old
value", new: "New value", type: [prop]}}
import { objectDifference } from "uno-js";
const x = { name: "Mike", age: 3, gender: "Male" };
const y = { name: "John", age: 5, gender: "Male" };
const difference = objectDifference(x, y);
// => [{ name: { prev: "Mike", new: "John", type: "name" }, age: { prev: 3, new: 5, type: "age" }}]
Open CodeSandbox
removeDuplicated
Remove the duplicated entries in an object array by prop.
PARAMETERS
Type | Description | Optional |
---|---|---|
Array | Array of objects to be evaluated. | No |
String | Prop to be evaluated. | No |
RETURN
An array with unique objects.
import { removeDuplicated } from "uno-js";
const x1 = { name: "Mike", age: 3, gender: "Male" };
const x2 = { name: "Mike", age: 3, gender: "Male" };
const y1 = { name: "John", age: 5, gender: "Male" };
const y2 = { name: "John", age: 5, gender: "Male" };
const array = [x1, x2, y1, y2];
const unique = removeDuplicated([x1, x2, y1, y2], "name");
// => [{ name: "Mike", age: 3, gender: "Male" }, { name: "John", age: 5, gender: "Male" }]
Open CodeSandbox
stringTemplate
Build a string with a given template
PARAMETERS
Type | Description | Optional |
---|---|---|
|
No | |
boolean | No |
RETURN
A function that may build a string
import { humanize } from "uno-js";
const toHumanize = humanize("thisIsAnAwesomeExample");
// => This Is An Awesome Example
toDate
Iterate between object props to convert any valid string into a Date object
PARAMETERS
Type | Description | Optional |
---|---|---|
Object | Object containing valid props for string conversion. | No |
RETURN
None
import { toDate } from "uno-js";
const MyObject: any = { myDateString: "08.17.1994" };
toDate(MyObject);
// => 1994-08-17T06:00:00.000Z
Open CodeSandbox
toLocalTime
Converts a date object or string to UTC Date
PARAMETERS
Type | Description | Optional |
---|---|---|
|
Date to convert to UTC | No |
RETURN
A DateTime object converted to UTC
import { toDate } from "uno-js";
const MyObject: any = { myDateString: "08.17.1994" };
toDate(MyObject);
// => 1994-08-17T06:00:00.000Z
toTitleCase
Returns the given string in Title Case
PARAMETERS
Type | Description | Optional |
---|---|---|
String | String to be converted on Title Case. | No |
RETURN
A Title Case string.
import { toTitleCase } from "uno-js";
const x = toTitleCase("heLLo WoRld!");
// => Hello World
Open CodeSandbox
truncateText
Truncates a string to a certain length
PARAMETERS
Type | Description | Optional |
---|---|---|
|
Complements for the resulting truncated string | No |
string | Text to be truncated | No |
number | Length of truncation | No |
RETURN
A humanized string
validateNotNull
Validate if an object is not null
PARAMETERS
Type | Description | Optional |
---|---|---|
Object | Object to validate | No |
string[] | Object props that will be ignored for validation | No |
RETURN
True if object is correctly validated
validateObject
Validate an object, and ommit certain properties
PARAMETERS
Type | Description | Optional |
---|---|---|
Object | Object to be validated | No |
Function | Function used to validate object | No |
RETURN
True, false