css-calipers 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +47 -23
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,18 +1,26 @@
1
1
  # CSS-Calipers
2
2
 
3
- **CSS is code. Measure it like one.**
4
- Compile-time unit safety for numeric, unit-bearing CSS values, no surprises at runtime.
3
+ [![npm](https://img.shields.io/npm/v/css-calipers.svg)](https://www.npmjs.com/package/css-calipers)
4
+ [![types](https://img.shields.io/npm/types/css-calipers.svg)](https://www.npmjs.com/package/css-calipers)
5
+ [![license](https://img.shields.io/npm/l/css-calipers.svg)](./LICENSE.txt)
5
6
 
6
- CSS-Calipers is a tiny layer for typed CSS measurements. Stop parsing CSS
7
- strings and concatenating units. Do your math on real numbers, get
8
- compile-time unit safety, and output CSS only at the edges.
7
+ **CSS is code. Treat it that way.**
8
+ Compile-time unit safety for numeric, unit-bearing CSS values, with no surprises at runtime.
9
9
 
10
- This README is a general overview. Deeper module guides live in their own files.
11
-
12
- Module guides:
10
+ ```ts
11
+ // Before: pull the number AND the unit apart, do the math, glue them back
12
+ const match = base.match(/^(-?\d*\.?\d+)([a-z%]+)$/i);
13
+ if (!match) throw new Error(`Bad measurement: ${base}`);
14
+ const [, numStr, unit] = match;
15
+ const num = parseFloat(numStr);
16
+ const pad = `${num + 4}${unit}`; // and nobody checked that `unit` matches what the caller expects
17
+
18
+ // After: typed math, units enforced by the compiler
19
+ const base = m(8); // or m(8, "rem"), m(1.5, "em"), etc.
20
+ const pad = base.add(4).css(); // type error if units don't match
21
+ ```
13
22
 
14
- - Measurements core: README_MEASUREMENT.md
15
- - Media queries: README_MEDIAQUERIES.md
23
+ A small TypeScript library for **type-safe CSS measurements**. Do arithmetic on real numbers with the unit attached, let the compiler catch `px`-vs-`rem` mistakes, and emit a CSS string only at the edge.
16
24
 
17
25
  At a glance:
18
26
 
@@ -26,15 +34,6 @@ At a glance:
26
34
  npm install css-calipers
27
35
  ```
28
36
 
29
- ### Status & support
30
-
31
- > 🚧 Work in progress.
32
- > API surface and docs may change between `0.x` releases until the first stable version.
33
-
34
- - Status: early `0.x` release. Backwards compatibility is not guaranteed until `1.0.0`.
35
- - Questions or bugs: open an issue on GitHub (see the repository link at the top of this page or in `package.json`).
36
- - Tooling: tested primarily with TypeScript 5.6+ on Node 18+.
37
-
38
37
  ---
39
38
 
40
39
  ## Quick start
@@ -61,6 +60,16 @@ If you prefer, you can also import unit helpers from dedicated subpaths. For exa
61
60
 
62
61
  ---
63
62
 
63
+ ## Status & support
64
+
65
+ > API surface and docs may change between `0.x` releases until the first stable version.
66
+
67
+ - Status: early `0.x` release. Backwards compatibility is not guaranteed until `1.0.0`.
68
+ - Questions or bugs: open an issue on GitHub (see the repository link at the top of this page or in `package.json`).
69
+ - Tooling: tested primarily with TypeScript 5.6+ on Node 18+.
70
+
71
+ ---
72
+
64
73
  ## Media queries
65
74
 
66
75
  ```ts
@@ -125,8 +134,8 @@ CSS-Calipers is a good fit if:
125
134
  - You already use TypeScript (or plan to) and want compile-time guarantees around CSS units.
126
135
  - You have a design system or token layer where layout math and unit conversions matter.
127
136
  - You care about catching unit mismatches and layout invariants early, in dev or tests.
128
- This library is opinionated about types and emitting valid CSS at the edges,
129
- but intentionally loose about how you structure or apply styles in between.
137
+ This library is opinionated about types and emitting valid CSS at the edges,
138
+ but intentionally loose about how you structure or apply styles in between.
130
139
 
131
140
  It’s probably overkill if:
132
141
 
@@ -177,7 +186,7 @@ const columns = 3;
177
186
  if (process.env.NODE_ENV !== "production") {
178
187
  assertCondition(
179
188
  () => columns > 0,
180
- "cardGridStyles: columns must be greater than zero"
189
+ "cardGridStyles: columns must be greater than zero",
181
190
  );
182
191
  }
183
192
 
@@ -218,7 +227,7 @@ if (process.env.NODE_ENV !== "production") {
218
227
  assertMatchingUnits(
219
228
  formTokens.field.paddingBlock,
220
229
  formTokens.field.paddingInline,
221
- "Form control padding mismatch"
230
+ "Form control padding mismatch",
222
231
  );
223
232
  }
224
233
  ```
@@ -268,9 +277,11 @@ css-calipers.m: Non-finite measurement value: undefined [code=CALIPERS_E_NONFINI
268
277
  ```
269
278
 
270
279
  What it means
280
+
271
281
  - A measurement was constructed with undefined, NaN, or Infinity.
272
282
 
273
283
  How to fix
284
+
274
285
  - Provide a real numeric value and a unit (m(12), m(12, "px")).
275
286
  - Add a context label so the error points to the calling helper or token (m(12, { context: "tokens.cardWidth" })).
276
287
 
@@ -283,9 +294,11 @@ css-calipers.assertMatchingUnits: measurement unit mismatch: px vs em [code=CALI
283
294
  ```
284
295
 
285
296
  What it means
297
+
286
298
  - You mixed units without an explicit conversion.
287
299
 
288
300
  How to fix
301
+
289
302
  - Normalize units at the source (convert em to px or vice versa).
290
303
  - Add an assertMatchingUnits call where the values enter your system.
291
304
 
@@ -298,9 +311,11 @@ css-calipers.Measurement.divide: Cannot divide 10px by zero [code=CALIPERS_E_DIV
298
311
  ```
299
312
 
300
313
  What it means
314
+
301
315
  - You attempted to divide by zero in a measurement operation.
302
316
 
303
317
  How to fix
318
+
304
319
  - Guard inputs before dividing or replace zero with a safe fallback.
305
320
 
306
321
  ### Clamp bounds
@@ -312,9 +327,11 @@ css-calipers.Measurement.clamp: clamp: min (20px) must be <= max (12px) [code=CA
312
327
  ```
313
328
 
314
329
  What it means
330
+
315
331
  - The clamp minimum is greater than the clamp maximum.
316
332
 
317
333
  How to fix
334
+
318
335
  - Ensure min and max come from the same source or swap them before calling clamp.
319
336
 
320
337
  ### Stack hints and configuration
@@ -456,6 +473,13 @@ by your styling layer. That’s the intended scope: CSS will always be a mix of
456
473
  values, but the library gives you a tight, unit-safe boundary for the numeric
457
474
  parts inside a broader styling solution.
458
475
 
476
+ ### Module guides
477
+
478
+ Deeper guides live alongside this README:
479
+
480
+ - Measurements core: [README_MEASUREMENT.md](README_MEASUREMENT.md)
481
+ - Media queries: [README_MEDIAQUERIES.md](README_MEDIAQUERIES.md)
482
+
459
483
  ### Further examples in this repo
460
484
 
461
485
  The `examples/` folder contains a few non-published usage sketches:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-calipers",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Compile-time unit safety for numeric, unit-bearing CSS values via typed measurements.",
5
5
  "license": "MIT",
6
6
  "repository": {