mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 04:58:01 +00:00
bahaghari/lib: init isHexString
This commit is contained in:
parent
b7ac964082
commit
fe4f1d1ae9
@ -21,5 +21,5 @@ pkgs.lib.makeExtensible
|
||||
tinted-theming = callLibs ./tinted-theming.nix;
|
||||
|
||||
inherit (self.trivial) importYAML toYAML toBaseDigitsWithGlyphs generateGlyphSet;
|
||||
inherit (self.hex) toHexString;
|
||||
inherit (self.hex) toHexString isHexString;
|
||||
})
|
||||
|
@ -14,4 +14,21 @@ rec {
|
||||
range 15 18 => [ "F" "10" "11" ]
|
||||
*/
|
||||
range = first: last: builtins.map (n: toHexString n) (pkgs.lib.lists.range first last);
|
||||
|
||||
/* Checks if the given hex string is valid or not.
|
||||
|
||||
Type: isHexString :: String -> Bool
|
||||
|
||||
Example:
|
||||
isHexString "ABC"
|
||||
=> true
|
||||
|
||||
isHexString "00ABC"
|
||||
=> true
|
||||
|
||||
isHexString "WHAT! HELL NO!"
|
||||
=> false
|
||||
*/
|
||||
isHexString = hex:
|
||||
builtins.match "[A-Fa-f0-9]+" hex != null;
|
||||
}
|
||||
|
@ -27,4 +27,14 @@ pkgs.lib.runTests {
|
||||
expr = lib.hex.range 49 17;
|
||||
expected = [ ];
|
||||
};
|
||||
|
||||
testIsHexString = {
|
||||
expr = lib.hex.isHexString "ABC";
|
||||
expected = true;
|
||||
};
|
||||
|
||||
testIsHexStringWithInvalidHex = {
|
||||
expr = lib.hex.isHexString "WHAT IS THIS";
|
||||
expected = false;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user