chris-website/source/nl/netsoj/chris/blog/utils.d
Chris Josten 35d5b02b5e Refractor code
* This project now should make proper use of modules
* HTTP specific logic was extracted from app.d to http.d
* Logic for managing files in memory was moved to cache.d from watcher.d
* Added license
2021-06-22 01:37:51 +02:00

32 lines
579 B
D

import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import dyaml;
string toHumanString(DateTime value) {
return to!string(value.day) ~ "-" ~ to!string(ubyte(value.month)) ~ "-" ~ to!string(value.year);
}
T getOr(T)(Node node, string key, T or) {
if (key in node) {
try {
return node[key].get!T;
} catch (Exception e) {
return or;
}
} else {
return or;
}
}
T[] getArray(T)(Node node, string key, T[] or = []) {
try {
return node.getOr!(Node[])(key, [])
.map!(x => x.as!T).array;
} catch (NodeException e) {
return or;
}
}