mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-02-07 12:19:07 +00:00
bahaghari/lib: update hex subset with generateBaseDigitType
This commit is contained in:
parent
29d4bb657a
commit
b84d07ac0c
@ -23,4 +23,5 @@ pkgs.lib.makeExtensible
|
|||||||
inherit (self.trivial) importYAML toYAML toBaseDigitsWithGlyphs
|
inherit (self.trivial) importYAML toYAML toBaseDigitsWithGlyphs
|
||||||
generateGlyphSet generateConversionTable generateBaseDigitType pow;
|
generateGlyphSet generateConversionTable generateBaseDigitType pow;
|
||||||
|
|
||||||
|
inherit (self.hex) isHexString;
|
||||||
})
|
})
|
||||||
|
@ -3,8 +3,18 @@
|
|||||||
# purpose.
|
# purpose.
|
||||||
{ pkgs, lib }:
|
{ pkgs, lib }:
|
||||||
|
|
||||||
|
let
|
||||||
|
glyphList =
|
||||||
|
[ "0" "1" "2" "3" "4" "5" "6" "7"
|
||||||
|
"8" "9" "A" "B" "C" "D" "E" "F" ];
|
||||||
|
|
||||||
|
baseSet = lib.generateBaseDigitType glyphList;
|
||||||
|
in
|
||||||
rec {
|
rec {
|
||||||
inherit (pkgs.lib.trivial) toHexString;
|
/* Returns a convenient glyph set for creating your own conversion or
|
||||||
|
hex-related functions.
|
||||||
|
*/
|
||||||
|
inherit (baseSet) glyphSet conversionTable fromDec toDec;
|
||||||
|
|
||||||
/* A variant of `lib.lists.range` function just with hexadecimal digits.
|
/* A variant of `lib.lists.range` function just with hexadecimal digits.
|
||||||
|
|
||||||
@ -15,7 +25,7 @@ rec {
|
|||||||
=> [ "F" "10" "11" ]
|
=> [ "F" "10" "11" ]
|
||||||
*/
|
*/
|
||||||
range = first: last:
|
range = first: last:
|
||||||
builtins.map (n: toHexString n) (pkgs.lib.lists.range first last);
|
builtins.map (n: baseSet.fromDec n) (pkgs.lib.lists.range first last);
|
||||||
|
|
||||||
/* Checks if the given hex string is valid or not.
|
/* Checks if the given hex string is valid or not.
|
||||||
|
|
||||||
|
@ -2,10 +2,30 @@
|
|||||||
|
|
||||||
pkgs.lib.runTests {
|
pkgs.lib.runTests {
|
||||||
testToHexString = {
|
testToHexString = {
|
||||||
expr = lib.hex.toHexString 293454837;
|
expr = lib.hex.fromDec 293454837;
|
||||||
expected = "117DC3F5";
|
expected = "117DC3F5";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
testToHexString2 = {
|
||||||
|
expr = lib.hex.fromDec 4500;
|
||||||
|
expected = "1194";
|
||||||
|
};
|
||||||
|
|
||||||
|
testToHexString3 = {
|
||||||
|
expr = lib.hex.fromDec 5942819;
|
||||||
|
expected = "5AAE23";
|
||||||
|
};
|
||||||
|
|
||||||
|
testHexToDec = {
|
||||||
|
expr = lib.hex.toDec "FF";
|
||||||
|
expected = 255;
|
||||||
|
};
|
||||||
|
|
||||||
|
testHexToDec2 = {
|
||||||
|
expr = lib.hex.toDec "333FAB333";
|
||||||
|
expected = 13756969779;
|
||||||
|
};
|
||||||
|
|
||||||
testCreateHexRange = {
|
testCreateHexRange = {
|
||||||
expr = lib.hex.range 10 17;
|
expr = lib.hex.range 10 17;
|
||||||
expected = [ "A" "B" "C" "D" "E" "F" "10" "11" ];
|
expected = [ "A" "B" "C" "D" "E" "F" "10" "11" ];
|
||||||
|
Loading…
Reference in New Issue
Block a user