docs: migrate lib.versions to doc-comments

This commit is contained in:
KFears 2025-09-09 03:51:43 +04:00
parent 683b6cb609
commit 14074222a8
Signed by: KFearsoff
SSH key fingerprint: SHA256:sn39ts1xvi/KGQNlqDyrj8nNlhp9ilndgIolXKnPraw
2 changed files with 156 additions and 30 deletions

View file

@ -39,12 +39,24 @@ let
# For this, we return a new attrset with key "${filename}", and we wrap this thing into a lambda
libs = builtins.map (f: lib: { "${f}" = import (pathify f) lib; }) files;
## Calculate the fixed point of a function. This will evaluate the function `f`
## until its result settles (or Nix's recursion limit is reached). This allows
## us to define recursive functions without worrying about the order of their
## definitions.
##
## @type (a -> a) -> a
/**
Calculate the fixed point of a function. This will evaluate the function `f`
until its result settles (or Nix's recursion limit is reached). This allows
us to define recursive functions without worrying about the order of their
definitions.
# Inputs
`f`
: 1\. Function argument
# Type
```
fix :: (a -> a) -> a
```
*/
fix =
f:
let

View file

@ -1,32 +1,119 @@
/**
Version string functions.
*/
lib: {
## Check if a version is greater than another.
##
## @type String -> String -> Bool
/**
Check if a version is greather than another.
# Example
```nix
gt "1.2.3" "1.2.2"
=>
true
```
# Type
```
gt :: String -> String -> Bool
```
*/
gt = first: second: builtins.compareVersions first second == -1;
## Check if a version is greater than or equal to another.
##
## @type String -> String -> Bool
/**
Check if a version is greater than or equal to another.
# Example
```nix
gte "1.2.3" "1.2.2"
=>
true
```
# Type
```
gte :: String -> String -> Bool
```
*/
gte = first: second: builtins.compareVersions first second != 1;
## Check if a version is less than another.
##
## @type String -> String -> Bool
/**
Check if a version is lesser than another.
# Example
```nix
lt "1.2.3" "1.2.2"
=>
false
```
# Type
```
lt :: String -> String -> Bool
```
*/
lt = first: second: builtins.compareVersions first second == 1;
## Check if a version is less than or equal to another.
##
## @type String -> String -> Bool
/**
Check if a version is lesser than or equal to another.
# Example
```nix
lte "1.2.3" "1.2.2"
=>
false
```
# Type
```
lte :: String -> String -> Bool
```
*/
lte = first: second: builtins.compareVersions first second != -1;
## Check if a version is equal to another.
##
## @type String -> String -> Bool
/**
Checks if a version is equal to another.
# Example
```nix
eq "1.2.3" "1.2.2"
=>
false
```
# Type
```
eq :: String -> String -> Bool
```
*/
eq = first: second: builtins.compareVersions first second == 0;
## Get the major version from a version string.
##
## @type String -> String
/**
Get the major version from a version string.
# Example
```nix
major "1.2.3"
=>
1
```
# Type
```
major :: String -> String
```
*/
major =
version:
let
@ -34,19 +121,46 @@ lib: {
in
builtins.elemAt parts 0;
## Get the minor version from a version string.
##
## @type String -> String
/**
Get the minor version from a version string.
# Example
```nix
minor "1.2.3"
=>
2
```
# Type
```
minor :: String -> String
```
*/
minor =
version:
let
parts = builtins.splitVersion version;
in
builtins.elemAt parts 1;
/**
Get the patch version from a version string.
## Get the patch version from a version string.
##
## @type String -> String
# Example
```nix
patch "1.2.3"
=>
3
```
# Type
```
patch :: String -> String
```
*/
patch =
version:
let