Registry / serialization / css-font-parser-papandreou

css-font-parser-papandreou

JSON →
library0.2.3-patch1jsnpmunverified

The `css-font-parser-papandreou` package provides a lightweight, dedicated parser for CSS font shorthand property values. It transforms a CSS font string, such as `15px/18px "Neue Helvetica", Helvetica, sans-serif`, into a structured JavaScript object, extracting components like `font-family` (as an array), `font-size`, and `line-height`. The current stable version, `0.2.3-patch1`, signifies a pre-1.0 development stage, and as a fork of the original `css-font-parser`, it suggests a maintenance-oriented release cadence by Andreas Papandreou. This library differentiates itself through its singular focus on parsing this specific CSS property, offering a minimal footprint solution for environments where a full CSS parser is overkill. It's particularly useful for applications that need to programmatically inspect or manipulate font declarations from user input or dynamic styles.

npm install css-font-parser-papandreou
INSTALL
IMPORT
SIG · CSS-FONT-PARSER-PA
C
css-font-parser-papandreou
serializationjavascriptv0.2.3-patch1
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.

parse
const parse = require('css-font-parser-papandreou');
import parse from 'css-font-parser-papandreou';
This package primarily exposes a CommonJS module where the `parse` function is the module's default export. Direct ESM import using `import parse from '...'` will result in a runtime error in Node.js or unexpected behavior with some bundlers.
parse
const parse = require('css-font-parser-papandreou');
import { parse } from 'css-font-parser-papandreou';
The `parse` function is the default (and only primary) export of this CommonJS module. Attempting to destructure it as a named export like `import { parse } from '...'` will result in `undefined` or a `TypeError`.

Demonstrates how to import and use the `parse` function to extract font properties from various CSS font shorthand strings.

const parse = require('css-font-parser-papandreou'); // Parse a simple font value const simpleFont = parse('15px sans-serif'); console.log('Simple Font:', simpleFont); /* Expected output: { 'font-family': ['sans-serif'], 'font-size': '15px' } */ // Parse a more complex font value with line-height and multiple font families const complexFont = parse('15px/18px "Neue Helvetica", Helvetica, sans-serif'); console.log('Complex Font:', complexFont); /* Expected output: { 'font-family': ['Neue Helvetica', 'Helvetica', 'sans-serif'], 'font-size': '15px', 'line-height': '18px' } */ // Example with a different font style (assuming it's supported by the parser) const italicFont = parse('italic bold 16px/24px Arial, sans-serif'); console.log('Italic Font:', italicFont); /* Expected structure (actual parsed values depend on parser's full capabilities): { 'font-style': 'italic', 'font-weight': 'bold', 'font-size': '16px', 'line-height': '24px', 'font-family': ['Arial', 'sans-serif'] } */
Debug
Known issues
gotchaThis package is primarily a CommonJS module. Direct ESM imports (e.g., `import ... from '...'`) may not work as expected in pure ESM environments without a bundler or specific Node.js configuration, leading to `require is not defined` errors.
fix
Use `const parse = require('css-font-parser-papandreou');` for Node.js environments. For ESM compatibility, consider using a bundler like Webpack or Rollup, or dynamic `import()` if available and suitable.
affects: >=0.1.0
gotchaAs a pre-1.0 version (`0.2.3-patch1`), the API, while seemingly stable for its primary function, could theoretically have minor breaking changes in parsing behavior or output structure in future patch or minor releases, though less likely for such a focused utility.
fix
Pin the exact version (`"css-font-parser-papandreou": "0.2.3-patch1"`) in your `package.json` to ensure consistent behavior and thoroughly test after any updates.
affects: >=0.1.0
gotchaThe parser is specifically designed for CSS font shorthand values. Supplying malformed or unexpected CSS strings (e.g., non-font properties) may result in incomplete parsing, `null` values, or unexpected object structures rather than throwing explicit errors.
fix
Pre-validate input strings to ensure they adhere to the CSS font shorthand syntax. Implement robust error handling or fallback logic for cases where `parse()` might return incomplete or unexpected results.
affects: >=0.1.0
gotchaThis package is a fork (`-papandreou`) of an older `css-font-parser` library. While providing ongoing maintenance, it might diverge in behavior or feature set from the original or other community forks. Be aware of the specific fork being used.
fix
Verify that this specific fork meets your requirements and consider the maintenance status of both the original and this fork if long-term support is critical. Monitor `npm` for further updates to this specific fork.
affects: >=0.2.3-patch1
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ECMAScript Module (ESM) context without proper configuration or a bundler.
fix
Ensure your project is configured for CommonJS, or use a bundler to resolve CommonJS modules in an ESM project. If in Node.js ESM, consider dynamic `import('css-font-parser-papandreou').then(mod => mod.default)`.
TypeError: parse is not a function
Incorrectly importing the `parse` function. This typically happens when using `import { parse } from '...'` on a CommonJS module that exports the function as `module.exports = parseFunction` (a default export pattern).
fix
For CommonJS, use `const parse = require('css-font-parser-papandreou');`. If attempting ESM, `import parse from 'css-font-parser-papandreou';` might be the correct syntax if your bundler handles CJS interoperability, but `require()` is the canonical way.
Parse result does not include expected font properties (e.g., 'font-weight', 'font-style').
The input CSS font value might be malformed, contain unsupported keywords, or the parser might not recognize all possible CSS font shorthand variations or complex values.
fix
Double-check the input string against CSS font shorthand syntax rules. Test with simpler inputs first. If certain properties are consistently missed, the parser may not support them, and manual extraction or a different library might be needed.
Upgrade
Version history
0.2.3-patch1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
12
Resources