Skip to content

Commit

Permalink
improve Json types, adding Json_Primitive, Json_Object, and `Js…
Browse files Browse the repository at this point in the history
…on_Array`
  • Loading branch information
ryanatkn committed Nov 1, 2024
1 parent 7725660 commit 9db9a1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/two-meals-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ryanatkn/belt': patch
---

improve `Json` types, adding `Json_Primitive`, `Json_Object`, and `Json_Array`
8 changes: 7 additions & 1 deletion src/lib/json.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import {is_plain_object} from '$lib/object.js';

export type Json = string | number | boolean | null | {[prop: string]: Json} | Json[];
export type Json = Json_Primitive | Json_Object | Json_Array;

export type Json_Primitive = string | number | boolean | null;

export interface Json_Object extends Record<string, Json> {} // eslint-disable-line @typescript-eslint/no-empty-object-type

export interface Json_Array extends Array<Json> {} // eslint-disable-line @typescript-eslint/no-empty-object-type

/**
* Like `typeof json`, but includes arrays. Excludes `'undefined'` because it's not valid JSON.
Expand Down
3 changes: 3 additions & 0 deletions src/routes/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ export const src_json = {
path: 'json.ts',
declarations: [
{name: 'Json', kind: 'type'},
{name: 'Json_Primitive', kind: 'type'},
{name: 'Json_Object', kind: 'type'},
{name: 'Json_Array', kind: 'type'},
{name: 'Json_Type', kind: 'type'},
{name: 'to_json_type', kind: 'function'},
{name: 'canonicalize', kind: 'function'},
Expand Down

0 comments on commit 9db9a1d

Please sign in to comment.