A collection of reusable functions & utilities (timers, validators, sanitizers, ranges, logging, ...)
To install this package from the
Dub package repository, you may add nyinaa
as
dependency in your dub.json
file and the package will be downloaded
automatically during project build if it's not downloaded already.
{
"dependencies": {
"nyinaa": "~>0.0.3"
}
}
You may also fetch the latest version manually in the command-line:
dub add nyinaa
import nyinaa.timers : setInterval, stopInterval;
import std.stdio : writeln;
import std.datetime : seconds;
import core.thread.osthread : Thread;
void main()
{
// "tid" of type Tid can be referenced
// to stop setInterval()
auto tid = setInterval(1000.seconds, { writeln("tick"); });
auto tid2 = setInterval(3000.seconds, { writeln("tock"); });
Thread.sleep(12.seconds);
// stop running setInterval()
stopInterval(tid);
stopInterval(tid2);
// OR keep running timers
// using import core.thread.osthread: thread_joinAll;
// thread_joinAll();
}
Validators - for user data (e.g. form data)
-
isEmail()
-
isIP()
-
isIPv4()
-
isIPv6()
-
isUUID()
-
isUUIDv3()
-
isUUIDv4()
-
isUUIDv5()
import nyinaa.validators;
assert(isIP("192.169.0.0"));
assert(isIP("2001:db8:0:1:1:1:1:1"));
assert(!isIP("192.169.0.500"));
assert(!isIP("2001:db8:0:1:1:1:1:1xxx"));
assert(isIPv4("127.0.0.1"));
assert(!isIPv4("127.0.0.500"));
Time-based utility functions
-
setInterval()
-
stopInterval()
Sanitizing data
-
stripTags()
Image related operation
-
isImageDataURI()
-
bufferFromDataURI()
Handy functions for use in range related tasks
-
concreteRange()
-
orElse()
-
then()
See the documentation for the various functions and examples on how to use them.
Any generic validator form validation, etc. is welcomed