{"library":"marcheur","title":"Marcheur: XSLT-like Tree Processor Builder","description":"Marcheur is a JavaScript library designed for building simplistic tree-walking and pattern-matching processors, drawing inspiration from XSLT 1.0's core algorithm. It allows developers to define rules for transforming tree structures, offering functionality analogous to XSLT without aiming to be a full replacement. The current stable version is 0.9.0, indicating it is pre-1.0 and its API may still be subject to changes. Due to the incomplete documentation (marked with 'XXX TDB' in the provided README excerpt), the release cadence is likely irregular, and the project's current development activity might be low. Its key differentiator is providing a lightweight mechanism for common tree transformation needs in JavaScript where full XSLT support is cumbersome or unavailable.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install marcheur"],"cli":null},"imports":["import { Matcher } from 'marcheur';","import { Nodal } from 'marcheur/nodal';","import { qname } from 'marcheur/qname';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createTreeWalker } from 'marcheur'; // Hypothetical core processor builder\nimport { Matcher } from 'marcheur';\nimport { qname } from 'marcheur/qname';\n\n// Example source data representing an XML-like JS object tree\nconst document = {\n  element: 'root',\n  attrs: { 'xmlns:foo': 'http://foo.com/ns', version: '1.0' },\n  children: [\n    { element: 'item', attrs: { id: 'a' }, children: ['Text A'] },\n    { element: 'foo:data', attrs: { value: '123' }, children: ['Some Foo Data'] },\n  ],\n};\n\nconst nsMap = { foo: 'http://foo.com/ns' };\n\n// Define transformation rules using Matcher and qname for pattern matching\nconst rules = [\n  {\n    // Match any 'item' element and transform it\n    match: new Matcher().element('item'),\n    apply: (node) => ({\n      element: 'transformedItem',\n      attrs: { ...node.attrs, processed: 'true' },\n      children: node.children.map(c => typeof c === 'string' ? `MODIFIED: ${c}` : c),\n    }),\n  },\n  {\n    // Match 'foo:data' using qname for namespace-aware matching\n    match: new Matcher().element(qname('foo:data', nsMap)),\n    apply: (node) => ({\n      element: 'foo:transformedData',\n      attrs: { originalValue: node.attrs.value },\n      children: ['Namespace handled!'],\n    }),\n  },\n  {\n    // Default rule: copy nodes and recurse for unmatched elements\n    match: new Matcher().any(), // Assumes a generic 'any' matcher\n    apply: (node, walk) => {\n      if (typeof node === 'string') return node; // Handle text nodes\n      return {\n        ...node,\n        children: node.children ? node.children.map(walk) : [],\n      };\n    },\n  },\n];\n\n// Hypothetical function to create and execute a tree walker/processor\nconst walker = createTreeWalker(rules); // 'createTreeWalker' is an assumed API\nconst transformedDoc = walker.walk(document);\n\nconsole.log('Original Document:', JSON.stringify(document, null, 2));\nconsole.log('\\nTransformed Document:', JSON.stringify(transformedDoc, null, 2));\n\n// Direct usage of the qname utility\nconst qualifiedNameInfo = qname('foo:bar', nsMap);\nconsole.log('\\nqname(\"foo:bar\", nsMap):', qualifiedNameInfo); \n// Expected output: { ns: 'http://foo.com/ns', ln: 'bar' }\n\nconst simpleNameInfo = qname('baz');\nconsole.log('qname(\"baz\"):', simpleNameInfo);\n// Expected output: { qn: 'baz' }","lang":"typescript","description":"This quickstart demonstrates how to define and apply transformation rules to a JavaScript object tree using Marcheur's `Matcher` and `qname` utilities. It illustrates a conceptual `createTreeWalker` for processing.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}