Retire the objectid builtin; ship it as data instead
This commit is contained in:
@@ -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
|
`data/misc` carries locale-neutral categories — universal data that isn't tied to
|
||||||
a language or region:
|
a language or region:
|
||||||
|
|
||||||
- ids & networking: `uuid` (a proper random v4), `mac`, `creditcard` (per-network
|
- ids & networking: `uuid` (a proper random v4), `mac`, `objectid` (MongoDB
|
||||||
numbers ending in a valid `{luhn()}` digit)
|
ObjectID, 24 hex chars), `creditcard` (per-network numbers ending in a valid
|
||||||
|
`{luhn()}` digit)
|
||||||
- reference codes: `currency` (ISO 4217), `country` (ISO 3166), `language` (ISO
|
- reference codes: `currency` (ISO 4217), `country` (ISO 3166), `language` (ISO
|
||||||
639), `timezone` (IANA)
|
639), `timezone` (IANA)
|
||||||
- web & systems: `mimetype`, `httpstatus`, `useragent`
|
- 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 |
|
| `{ean()}` | derivation | EAN-13 / UPC-A / ISBN-13 / GTIN check digit |
|
||||||
| `{uuid()}` | generator | UUID v7 (v4 ships as data — see [Data](#data)) |
|
| `{uuid()}` | generator | UUID v7 (v4 ships as data — see [Data](#data)) |
|
||||||
| `{ulid()}` | generator | ULID, 26-char Crockford base32 |
|
| `{ulid()}` | generator | ULID, 26-char Crockford base32 |
|
||||||
| `{objectid()}` | generator | MongoDB ObjectID, 24 hex chars |
|
|
||||||
| `{nanoid(n)}` | generator | URL-safe Nano ID, `n` chars |
|
| `{nanoid(n)}` | generator | URL-safe Nano ID, `n` chars |
|
||||||
| `{hex(n)}` | generator | `n` lowercase hex digits |
|
| `{hex(n)}` | generator | `n` lowercase hex digits |
|
||||||
| `{base64(n)}` | generator | `n` random bytes, base64 |
|
| `{base64(n)}` | generator | `n` random bytes, base64 |
|
||||||
|
|||||||
+5
-6
@@ -20,18 +20,17 @@ const (
|
|||||||
// the digits emitted so far in the current expansion (luhn, mod11, ean — place
|
// 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
|
// 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
|
// 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
|
// 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.
|
// UUID already ships as data (data/misc/uuid.json), so the builtin is v7.
|
||||||
var builtins = map[string]builtin{
|
var builtins = map[string]builtin{
|
||||||
"luhn": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string {
|
"luhn": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string {
|
||||||
return string(rune('0' + luhnCheck(e)))
|
return string(rune('0' + luhnCheck(e)))
|
||||||
}},
|
}},
|
||||||
"mod11": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return mod11Check(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) }},
|
"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) }},
|
"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) }},
|
"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) }},
|
|
||||||
"nanoid": {arity: 1, check: posIntArg, prep: func(a []string) callFn {
|
"nanoid": {arity: 1, check: posIntArg, prep: func(a []string) callFn {
|
||||||
n := atoi(a[0])
|
n := atoi(a[0])
|
||||||
return func(s *session, _ string, _ map[string]node) string { return nanoid(s, n) }
|
return func(s *session, _ string, _ map[string]node) string { return nanoid(s, n) }
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[
|
||||||
|
{ "format": "{hex(24)}" }
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user