Registry / serialization / mensch

mensch

JSON →
library0.3.4jsnpmunverified

A decent, non-validating CSS parser and stringifier. Current stable version is 0.3.4 (last release 2015-04-02, now in maintenance mode). Provides parse, stringify, and lex functions with support for comments and position tracking. Unlike validating parsers, mensch handles malformed CSS (mis-matched braces, missing semi-colons) without error. Differentiators: comments in AST, position info, and lenient parsing. Alternatives: PostCSS, css, csstree.

npm install mensch
INSTALL
IMPORT
SIG · MENSCH
M
mensch
serializationjavascriptv0.3.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import mensch from 'mensch'
import { mensch } from 'mensch'
Default import is the module object containing parse, stringify, lex.
parse
import { parse } from 'mensch'
const parse = require('mensch').parse
Named import works in ESM; require also works in CJS.
stringify
import { stringify } from 'mensch'
import stringify from 'mensch'
stringify is a named export, not default.
lex
import { lex } from 'mensch'
const lex = require('mensch/lex')
lex is a member of the main module; no subpath.

Parse a CSS string with comments and positions, then stringify with indentation.

import mensch from 'mensch'; const css = 'p { color: black; }'; const ast = mensch.parse(css, { comments: true, position: true }); console.log(JSON.stringify(ast, null, 2)); const output = mensch.stringify(ast, { comments: true, indentation: ' ' }); console.log(output);
Debug
Known issues
gotchaMensch is a non-validating parser. It will not flag invalid CSS like misspelled property names or misplaced @import.
fix
Use a validating parser (e.g., PostCSS with stylelint) if validation is needed.
affects: >=0.1.0
gotchaComments within selectors, properties, or values are silently ignored. They do not appear in the AST even with {comments: true}.
fix
Keep comments only between rules or declarations.
affects: >=0.1.0
deprecatedThe package has no new releases since 2015. It is effectively in maintenance mode; no updates for modern CSS features (e.g., custom properties, nesting).
fix
Consider using PostCSS or csstree for modern CSS parsing.
affects: *
gotchaGlobal leak in v0.3.3 and earlier: the parser could leak variables into global scope.
fix
Update to v0.3.4 or later.
affects: <0.3.4
gotchaWhen using CommonJS require(), the default export is the whole module, not an object with methods. Use const mensch = require('mensch'); then mensch.parse().
fix
Use const mensch = require('mensch'); or import * as mensch from 'mensch'.
affects: *
Errors
Common errors & fixes
TypeError: mensch.parse is not a function
Importing mensch incorrectly, e.g., import parse from 'mensch' instead of import mensch from 'mensch'.
fix
Use import mensch from 'mensch'; then mensch.parse().
Cannot find module 'mensch'
Package not installed or typo in package name.
fix
Run npm install mensch and ensure correct casing.
Unexpected token ILLEGAL
CSS contains modern syntax like CSS custom properties (var(--foo)) or nesting that mensch cannot parse.
fix
Switch to a modern parser like PostCSS.
Upgrade
Version history
0.3.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
Amazon
1
Resources
mensch — npm install mensch · libregistry