~statianzo/janet-nanoid

9218a533c3d12659dae4610e550aff60641665b3 — Jason Staten 4 years ago d62a620 0.1.0
readme and update project.janet
2 files changed, 48 insertions(+), 2 deletions(-)

A README.md
M project.janet
A README.md => README.md +45 -0
@@ 0,0 1,45 @@
# janet-nanoid

nanoid is a library for generating random IDs.

Implementation of [nanoid](https://zelark.github.io/nano-id-cc/) in
[Janet](https://janet-lang.org/).

# Install

```
jpm install git+https://git.sr.ht/~statianzo/janet-nanoid
```

# Usage

nanoid comes with two variants `gen` and `gen-non-secure`.

`gen` relies on Janet's `os/cryptorand` to obtain cryptographically
secure random bytes.

`gen-non-secure` uses the `math/rng` pseudorandom generator.

## Options

* `:size` - Length of the output string (default `21`)
* `:alphabet` - Alphabet of characters to use (default `"_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"`)
* `:rng` - `math/rng` instance to generate (`gen-non-secure` only)

## Example

```clojure
(import nanoid)

(nanoid/gen)
# "xo25OEhGZ7yoHYbfPpmZE"

(nanoid/gen :size 5)
# "U5bBu"

(nanoid/gen :alphabet "abcd1234")
# "24234a13a4ddddc3dbb4a"

(nanoid/gen-non-secure :size 5)
# "vWgzu"
```

M project.janet => project.janet +3 -2
@@ 1,9 1,10 @@
(declare-project
  :name "nanoid"
  :description "A library for generating random IDs"
  :author "Jason Staten"
  :license "Unlicense"
  :version "0.0.1"
  :url "https://git.sr.ht/~statianzo/janet-nanoid"
  :version "0.1.0"
  :url "https://sr.ht/~statianzo/janet-nanoid"
  :repo "git+https://git.sr.ht/~/statianzo/janet-nanoid")

(declare-source