diff options
author | bob <bcz@cs.brown.edu> | 2019-06-20 17:09:50 -0400 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-06-20 17:09:50 -0400 |
commit | a39b2854b848006c19460685d7bf4005a9f650ae (patch) | |
tree | 3de2358c2d25470eebb3292728a590ca5daf6497 /src/new_fields/Doc.ts | |
parent | 8dbfb3029a99eaf37a5234e9d9e33cc64f779b03 (diff) |
moved AddDocToList to Doc utils
Diffstat (limited to 'src/new_fields/Doc.ts')
-rw-r--r-- | src/new_fields/Doc.ts | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 1b0ff812f..7bae7a02d 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -222,6 +222,16 @@ export namespace Doc { return Array.from(results); } + export function AddDocToList(target: Doc, key: string, doc: Doc, relativeTo?: Doc, before?: boolean) { + let list = Cast(target[key], listSpec(Doc)); + if (list) { + let ind = relativeTo ? list.indexOf(relativeTo) : -1; + if (ind === -1) list.push(doc); + else list.splice(before ? ind : ind + 1, 0, doc); + } + return true; + } + export function MakeAlias(doc: Doc) { if (!GetT(doc, "isPrototype", "boolean", true)) { return Doc.MakeCopy(doc); |