MCPcopy
hub / github.com/arfct/itty-bitty / parse

Function parse

docs/render/contact.js:222–263  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

220// ]).then(render);
221
222function parse(input) {
223 var Re1 = /^(version|fn|title|org):(.+)$/i;
224 var Re2 = /^([^:;]+);([^:]+):(.+)$/;
225 var ReKey = /item\d{1,2}\./;
226 var fields = {};
227
228 input.split(/\r\n|\r|\n/).forEach(function (line) {
229 var results, key;
230
231 if (Re1.test(line)) {
232 results = line.match(Re1);
233 key = results[1].toLowerCase();
234 fields[key] = results[2];
235 } else if (Re2.test(line)) {
236 results = line.match(Re2);
237 key = results[1].replace(ReKey, '').toLowerCase();
238
239 var meta = {};
240 results[2].split(';')
241 .map(function (p, i) {
242 var match = p.match(/([a-z]+)=(.*)/i);
243 if (match) {
244 return [match[1], match[2]];
245 } else {
246 return ["TYPE" + (i === 0 ? "" : i), p];
247 }
248 })
249 .forEach(function (p) {
250 meta[p[0]] = p[1];
251 });
252
253 if (!fields[key]) fields[key] = [];
254
255 fields[key].push({
256 meta: meta,
257 value: results[3].split(';')
258 })
259 }
260 });
261
262 return fields;
263};
264
265
266 window.addEventListener("message", function(e) {

Callers 1

renderFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected