MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / constructor

Method constructor

contributed/jsonparser/jsonparser.js:108–140  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

106export class Pattern extends Matcher {
107 // Constructor for the Pattern class, validates options and establishes pattern value items.
108 constructor(options) {
109 super(options);
110 this.setup = options.setup; // setup function
111 this.value = options.value; // pattern value string
112 const itemDelimiter = options.itemDelimiter || "/";
113 const nameDelimiter = options.nameDelimiter || ":";
114 this.items = this.value.split(itemDelimiter).map((item, index) => {
115 if (index === 0 && item === "" && this.value.startsWith(itemDelimiter))
116 return { type: NodeType.root };
117 const pair = item.split(nameDelimiter);
118 const text = pair[1]; // field name
119 switch (pair[0]) {
120 case "null":
121 return { type: NodeType.null };
122 case "false":
123 return { type: NodeType.false };
124 case "true":
125 return { type: NodeType.true };
126 case "number":
127 return { type: NodeType.number, text };
128 case "string":
129 return { type: NodeType.string, text };
130 case "array":
131 return { type: NodeType.array };
132 case "object":
133 return { type: NodeType.object };
134 case "field":
135 return { type: NodeType.field, text };
136 case "root":
137 return { type: NodeType.root };
138 }
139 }).reverse().filter(item => item !== undefined);
140 }
141
142 // Gets an array of field names from the pattern.
143 get names() {

Callers

nothing calls this directly

Calls 3

reverseMethod · 0.80
mapMethod · 0.80
filterMethod · 0.45

Tested by

no test coverage detected