validationController.addRenderer(new Bootstrap4ValidationFormRenderer());
import {createChecksum} from 'objects';
const myObject = {
"hello": "world"
}
const checksum = createChecksum(myObject);
Implements a workaround for copying text in framed applications.
import {Clipboard} from 'clipboard';
const clipboard = new Clipboard()
clipboard.writeText("hello world").then(() => console.log("Copied"));
Number handling and formatting.
import {bytesMap, getFactor, kiloMap} from "./numbers";
const posts = 1300;
const kilo = getFactor(posts, kiloMap);
const bytes = getFactor(posts, bytesMap);
console.log(`Your wrote ${(posts / kilo.factor).toFixed(1)} ${kilo.unit} posts with a size of ${(posts / bytes.factor).toFixed(0)} ${bytes.unit} `);
// You wrote 1.3k posts with a size of 1 KiB
Provides some time functions.
import {addTimedelta, DateTimeComponents, subtractTimedelta} from "./time";
const now = new Date();
const timedelta: DateTimeComponents = {
days: 10
}
const newDate = addTimedelta(now, timedelta);
const oldDate = subtractTimedelta(newDate, timedelta);
Normalizes the time of a given date to full divisors of the components.
import {normalizeTime, TimeComponents} from "./time";
const now = new Date();
// now: 13:44:33
const timedelta: TimeComponents = {
hours: 4,
minutes: 5,
seconds: 0
}
const newDate = normalizeTime(now, timedelta);
// newDate: 12:40:00
import {toMilliseconds} from "./time";
window.setTimeout(() => console.log("Hello"), toMilliseconds({seconds: 10}));
Implements the behaviour of a trash bin.
TypeScript
import {TrashBin} from 'trash-bin';
const itemList = [
{
name: "Something",
deleted: false,
deletable: false,
}
];
const trashBin = TrashBin.create<any>();
trashBin.source(itemList);
trashBin.onTrash(item => {
// Prevent deletion
if (item.deletable === false) {
return false;
} else {
item.deleted = true;
}
});
trashBin.onRestore(item=>{
item.deleted = false;
});
const item = itemList[0];
trashBin.trash(item);
console.log(trashBin.sourceItems.length); // 0
console.log(trashBin.trashItems.length); // 1
trashBin.restore(item);
console.log(trashBin.sourceItems.length); // 1
console.log(trashBin.trashItems.length); // 0
trashBin.empty();
import {recursiveObjectSort} from 'objects';
const myObject = {
"katze": "kuh",
"hello": "world",
}
const sorted = recursiveObjectSort(myObject);
Allows setting objects to an implementation of a Storage interface
import {ObjectStorage} from "object-storage";
const objectStorage = new ObjectStorage();
objectStorage.setStorage(localStorage);
objectStorage.setItem("my-object", {});
const object = objectStorage.getItem("my-object");