diff --git a/README.md b/README.md index 910176c..a1342f5 100644 --- a/README.md +++ b/README.md @@ -178,8 +178,9 @@ Swedish personnummer): `address`, `color`, `company`, `date`, `email`, `ip`, `data/misc` carries locale-neutral categories — universal data that isn't tied to a language or region: -- ids & networking: `uuid` (a proper random v4), `mac`, `creditcard` (per-network - numbers ending in a valid `{luhn()}` digit) +- ids & networking: `uuid` (a proper random v4), `mac`, `objectid` (MongoDB + ObjectID, 24 hex chars), `creditcard` (per-network numbers ending in a valid + `{luhn()}` digit) - reference codes: `currency` (ISO 4217), `country` (ISO 3166), `language` (ISO 639), `timezone` (IANA) - web & systems: `mimetype`, `httpstatus`, `useragent` @@ -276,7 +277,6 @@ fat-fingered `hex(2000000000)` can't try to allocate gigabytes at render. | `{ean()}` | derivation | EAN-13 / UPC-A / ISBN-13 / GTIN check digit | | `{uuid()}` | generator | UUID v7 (v4 ships as data — see [Data](#data)) | | `{ulid()}` | generator | ULID, 26-char Crockford base32 | -| `{objectid()}` | generator | MongoDB ObjectID, 24 hex chars | | `{nanoid(n)}` | generator | URL-safe Nano ID, `n` chars | | `{hex(n)}` | generator | `n` lowercase hex digits | | `{base64(n)}` | generator | `n` random bytes, base64 | diff --git a/builtins.go b/builtins.go index 357869c..c0d3aa5 100644 --- a/builtins.go +++ b/builtins.go @@ -20,18 +20,17 @@ const ( // the digits emitted so far in the current expansion (luhn, mod11, ean — place // them after their payload); generators read only the rng (uuid, ulid, ...). All // must stay pure over (rng, emitted, args) so a seeded faker is reproducible — a -// time-based id (uuid v7, ulid, objectid) draws its timestamp from the rng, not +// time-based id (uuid v7, ulid) draws its timestamp from the rng, not // the wall clock. Add a builtin only for what data can't express: a random v4 // UUID already ships as data (data/misc/uuid.json), so the builtin is v7. var builtins = map[string]builtin{ "luhn": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return string(rune('0' + luhnCheck(e))) }}, - "mod11": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return mod11Check(e) }}, - "ean": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return eanCheck(e) }}, - "uuid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return uuidV7(s) }}, - "ulid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return ulid(s) }}, - "objectid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return randHex(s, 24) }}, + "mod11": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return mod11Check(e) }}, + "ean": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return eanCheck(e) }}, + "uuid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return uuidV7(s) }}, + "ulid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return ulid(s) }}, "nanoid": {arity: 1, check: posIntArg, prep: func(a []string) callFn { n := atoi(a[0]) return func(s *session, _ string, _ map[string]node) string { return nanoid(s, n) } diff --git a/data/misc/objectid.json b/data/misc/objectid.json new file mode 100644 index 0000000..9681734 --- /dev/null +++ b/data/misc/objectid.json @@ -0,0 +1,3 @@ +[ + { "format": "{hex(24)}" } +]