CertainLach / jrsonnet

Rust implementation of Jsonnet language
MIT License
290 stars 33 forks source link

feat: missing std features #124

Closed pawelbeza closed 12 months ago

pawelbeza commented 12 months ago

Hey 👋 I've implemented missing std features which were listed in the #118

You can test new features with the following jsonnet snippet:

{
    local test = ["a", "b", "a"],
    local obj = {a: "1", b: "2", c:: "3"},
    round1: std.round(1.0),
    round2: std.round(1.2),
    round3: std.round(1.5),
    isEven1: std.isEven(1),
    isEven2: std.isEven(2),
    isOdd1: std.isOdd(1),
    isOdd2: std.isOdd(2),
    isInteger1: std.isInteger(1.0),
    isInteger2: std.isInteger(1.1),
    isDecimal1: std.isDecimal(1.0),
    isDecimal2: std.isDecimal(1.1),
    xnortt: std.xnor(true, true),
    xnortf: std.xnor(true, false),
    xnorff: std.xnor(false, false),
    isEmpty1: std.isEmpty(""),
    isEmpty2: std.isEmpty(" "),
    isEmpty3: std.isEmpty("abc"),
    equalsIgnoreCase1: std.equalsIgnoreCase("a", "ac"),
    equalsIgnoreCase2: std.equalsIgnoreCase("a", "a"),
    equalsIgnoreCase3: std.equalsIgnoreCase("aB", "ab"),
    equalsIgnoreCase4: std.equalsIgnoreCase("aB", "Ab"),
    sha1: std.sha1("abcd"),
    sha3: std.sha3("abcd"),
    remove1: std.remove(["a", "b", "a"], "a"),
    remove2: std.remove(["a", "b", "a"], "c"),
    remove3: std.remove(test, "b"),
    remove4: test,
    remove5: std.removeAt(["a", "b", "a"], 0),
    remove6: std.removeAt(["a", "b", "a"], 1),
    remove7: std.removeAt(["a", "b", "a"], 4),
    objectRemoveKey1: std.objectRemoveKey(obj, "b"),
    objectRemoveKey2: std.objectRemoveKey(obj, "c"),
    objectRemoveKey3: obj,
    objectKeyValues: std.objectKeysValues(obj),
    objectKeyValuesAll: std.objectKeysValuesAll(obj)
}

Feel free to leave comments as that's my first time writing some Rust code.

pawelbeza commented 12 months ago

Hey @CertainLach sorry for ping but I guess you might be interested in looking into this. Cheers