npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@glitz/length-transformer

v4.0.3

Published

Transforms numeric values from properties like `height` and `left` to a length with unit.

Downloads

1,161

Readme

Glitz

Transforms numeric values from properties like height and left to a length with unit.

import { GlitzClient } from '@glitz/core';
import numberToLength from '@glitz/length-transformer';
const glitz = new GlitzClient({ transformer: numberToLength });

const className = glitz.injectStyle({
  height: 10,
  width: [100, 'max-content'],
  // Will be transformed into:
  // {
  //   height: '10px',
  //   width: ['100px', 'max-content'],
  // }
});

The default length unit is px for length safe properties. You can create a new transformer using createNumberToLengthTransformer(options) with the defaultUnit option if you prefer another unit or override units for any other property.

Numeric time value for animationDelay, animationDuration, transitionDelay and transitionDuration are also supported and has ms as default unit.

Getting started

$ npm install @glitz/length-transformer

Options

options.defaultUnit

defaultUnit: string;

Default: "px"

Unit used for length safe properties (that doesn't accept number and length the same time like lineHeight).

import { GlitzClient } from '@glitz/core';
import { createNumberToLengthTransformer } from '@glitz/length-transformer';
const glitz = new GlitzClient({ transformer: createNumberToLengthTransformer({ defaultUnit: 'rem' }) });

const className = glitz.injectStyle({
  height: 10,
  width: [100, 'max-content'],
  // Will be transformed into:
  // {
  //   height: '10rem',
  //   width: ['100rem', 'max-content'],
  // }
});

options.[cssProperty]

[cssProperty]: string;

Default: undefined

Override any CSS property with unit. Works with properties that excepts both number and length.

import { GlitzClient } from '@glitz/core';
import { createNumberToLengthTransformer } from '@glitz/length-transformer';
const glitz = new GlitzClient({
  transformer: createNumberToLengthTransformer({ lineHeight: 'em', fontSize: 'rem' }),
});

const className = glitz.injectStyle({
  paddingLeft: 10,
  lineHeight: 2,
  fontSize: 1.5,
  // Will be transformed into:
  // {
  //   paddingLeft: '10px',
  //   lineHeight: '2em',
  //   fontSize: '1.5rem',
  // }
});

Safe properties

The default length unit will only transform a specific set of properties because some properties e.g. lineHeight accepts both length and numbers. Here's the full list of length safe properties it will transform:

  • bottom
  • flexBasis
  • fontSize
  • height
  • left
  • marginBottom
  • marginLeft
  • marginRight
  • marginTop
  • maxHeight
  • maxWidth
  • minHeight
  • minWidth
  • paddingBottom
  • paddingLeft
  • paddingRight
  • paddingTop
  • right
  • top
  • width

For these, 'ms' is used as unit instead:

  • animationDelay
  • animationDuration
  • transitionDelay
  • transitionDuration

Shorthand objects like margin: { left: 10 } will be resolved to marginLeft: 10 before reaching the transformer, so these values will be transformed as well.

Less common properties, but still included: background, backgroundPosition, backgroundPositionX, backgroundPositionY, backgroundSize, blockSize, border, borderBlockEnd, borderBlockEndWidth, borderBlockStart, borderBlockStartWidth, borderBottom, borderBottomLeftRadius, borderBottomRightRadius, borderBottomWidth, borderInlineEnd, borderInlineEndWidth, borderInlineStart, borderInlineStartWidth, borderLeft, borderLeftWidth, borderRadius, borderRight, borderRightWidth, borderSpacing, borderTop, borderTopLeftRadius, borderTopRightRadius, borderTopWidth, borderWidth, boxShadow, columnGap, columnRule, columnRuleWidth, columnWidth, gridAutoColumns, gridAutoRows, gridColumnGap, gridGap, gridRowGap, gridTemplateColumns, gridTemplateRows, inlineSize, letterSpacing, lineHeightStep, margin, marginBlockEnd, marginBlockStart, marginInlineEnd, marginInlineStart, mask, maskPosition, maskSize, maxBlockSize, maxInlineSize, minBlockSize, minInlineSize, offset, offsetBlockEnd, offsetBlockStart, offsetDistance, offsetInlineEnd, offsetInlineStart, offsetPosition, outline, outlineOffset, outlineWidth, padding, paddingBlockEnd, paddingBlockStart, paddingInlineEnd, paddingInlineStart, perspective, perspectiveOrigin, scrollSnapCoordinate, scrollSnapDestination, shapeMargin, textIndent, textShadow, transformOrigin, verticalAlign and wordSpacing.