{"id":18545,"library":"mensch","title":"mensch","description":"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.","status":"maintenance","version":"0.3.4","language":"javascript","source_language":"en","source_url":"git://github.com/brettstimmerman/mensch","tags":["javascript","css","parser","parsing","stylesheet"],"install":[{"cmd":"npm install mensch","lang":"bash","label":"npm"},{"cmd":"yarn add mensch","lang":"bash","label":"yarn"},{"cmd":"pnpm add mensch","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default import is the module object containing parse, stringify, lex.","wrong":"import { mensch } from 'mensch'","symbol":"default","correct":"import mensch from 'mensch'"},{"note":"Named import works in ESM; require also works in CJS.","wrong":"const parse = require('mensch').parse","symbol":"parse","correct":"import { parse } from 'mensch'"},{"note":"stringify is a named export, not default.","wrong":"import stringify from 'mensch'","symbol":"stringify","correct":"import { stringify } from 'mensch'"},{"note":"lex is a member of the main module; no subpath.","wrong":"const lex = require('mensch/lex')","symbol":"lex","correct":"import { lex } from 'mensch'"}],"quickstart":{"code":"import mensch from 'mensch';\n\nconst css = 'p { color: black; }';\nconst ast = mensch.parse(css, { comments: true, position: true });\nconsole.log(JSON.stringify(ast, null, 2));\nconst output = mensch.stringify(ast, { comments: true, indentation: '  ' });\nconsole.log(output);","lang":"typescript","description":"Parse a CSS string with comments and positions, then stringify with indentation."},"warnings":[{"fix":"Use a validating parser (e.g., PostCSS with stylelint) if validation is needed.","message":"Mensch is a non-validating parser. It will not flag invalid CSS like misspelled property names or misplaced @import.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Keep comments only between rules or declarations.","message":"Comments within selectors, properties, or values are silently ignored. They do not appear in the AST even with {comments: true}.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider using PostCSS or csstree for modern CSS parsing.","message":"The package has no new releases since 2015. It is effectively in maintenance mode; no updates for modern CSS features (e.g., custom properties, nesting).","severity":"deprecated","affected_versions":"*"},{"fix":"Update to v0.3.4 or later.","message":"Global leak in v0.3.3 and earlier: the parser could leak variables into global scope.","severity":"gotcha","affected_versions":"<0.3.4"},{"fix":"Use const mensch = require('mensch'); or import * as mensch from 'mensch'.","message":"When using CommonJS require(), the default export is the whole module, not an object with methods. Use const mensch = require('mensch'); then mensch.parse().","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use import mensch from 'mensch'; then mensch.parse().","cause":"Importing mensch incorrectly, e.g., import parse from 'mensch' instead of import mensch from 'mensch'.","error":"TypeError: mensch.parse is not a function"},{"fix":"Run npm install mensch and ensure correct casing.","cause":"Package not installed or typo in package name.","error":"Cannot find module 'mensch'"},{"fix":"Switch to a modern parser like PostCSS.","cause":"CSS contains modern syntax like CSS custom properties (var(--foo)) or nesting that mensch cannot parse.","error":"Unexpected token ILLEGAL"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}