Skip to content

Commit

Permalink
feat: initialize using JSON string or object
Browse files Browse the repository at this point in the history
  • Loading branch information
crookse committed Nov 27, 2021
1 parent c22b3ae commit 6b4fb93
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/accio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { FieldType } from "./field_type";
import { Collection } from "./collection";
import * as Types from "./types";

export function accio<T>(json: string): Collection<T> {
const parsed = JSON.parse(json);
return new Collection<T>(parsed);
export function accio<T>(json: unknown): Collection<T> {
if (typeof json === "string") {
return new Collection<T>(JSON.parse(json));
}

return new Collection<T>(json as T);
}

export const FieldTypes = {
Expand Down

0 comments on commit 6b4fb93

Please sign in to comment.