{"id":14693,"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.","status":"maintenance","version":"0.9.0","language":"javascript","source_language":"en","source_url":"https://github.com/scienceai/marcheur","tags":["javascript","XSLT","transformaltion","tree","walkter"],"install":[{"cmd":"npm install marcheur","lang":"bash","label":"npm"},{"cmd":"yarn add marcheur","lang":"bash","label":"yarn"},{"cmd":"pnpm add marcheur","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Marcheur is primarily used in ESM environments. Matcher is a core utility for defining pattern-matching conditions.","wrong":"const { Matcher } = require('marcheur');","symbol":"Matcher","correct":"import { Matcher } from 'marcheur';"},{"note":"Nodal is a specialized utility for element creation and attribute remapping, imported from its own sub-path.","wrong":"const { Nodal } = require('marcheur/nodal');","symbol":"Nodal","correct":"import { Nodal } from 'marcheur/nodal';"},{"note":"The `qname` function for qualified name parsing and namespace handling is available as a named export from its specific sub-path.","wrong":"const { qname } = require('marcheur/qname');","symbol":"qname","correct":"import { qname } from 'marcheur/qname';"}],"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."},"warnings":[{"fix":"Always pin exact versions (`npm install marcheur@0.9.0`) and review changelogs carefully when upgrading. Be prepared for manual code adjustments.","message":"As a pre-1.0 release (version 0.9.0), Marcheur's API is not yet stable. Expect potential breaking changes in minor or even patch versions before a stable 1.0 release.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Consult the GitHub repository's source code for deeper insights into the API, or open issues for clarification from the maintainers.","message":"The provided README contains 'XXX TDB' placeholders, indicating incomplete or missing documentation for key API sections (Core, Matcher, Nodal). This makes understanding the full capabilities and precise usage challenging without diving into the source code.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Familiarize yourself with basic XSLT 1.0 concepts or review examples of tree transformation patterns before implementing complex processors with Marcheur.","message":"The library's design is heavily inspired by XSLT 1.0. Developers unfamiliar with XSLT's tree-walking and pattern-matching paradigm may face a steeper learning curve.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[],"ecosystem":"npm"}