chris-website/source/utils.d

28 lines
526 B
D

import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import dyaml;
string toHumanString(DateTime value) {
return to!string(value.year) ~ "-" ~ to!string(ubyte(value.month)) ~ "-" ~ to!string(value.day);
}
T getOr(T)(Node node, string key, T or) {
if (key in node) {
return node[key].get!T;
} 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;
}
}