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

@frampton/style

v0.0.6

Published

A library for working with CSS selectors in JS

Downloads

1

Readme

Frampton Style

Frampton-style is a library for working with CSS selectors in JavaScript. This is widely used by the frampton-events library to filter events.

Instalation

> npm install --save-dev @frampton/core
> npm install --save-dev @frampton/style

Usage

import * as Style from '@frampton/style';

All exported functions of >1 arguments is curried.

For example the addClass function could be used as such.

import { addClass } from '@frampton/style';

const addActive = addClass('active');
addActive(document.getElementById('my-id'));

addClass

Adds class to element.

import { addClass } from '@frampton/style';

// Add class to element
addClass('my-class', element);

applyStyles

Apply a hash of styles to a given element.

The applyStyles function will apply vendor prefixes if needed for the current browser.

import { addClass } from '@frampton/style';

applyStyles({
  'box-shadow': '1px 1px 5px rgba(0,0,0,0.5)',
  'padding': '10px 20px',
  'color': 'red'
}, element);

closest

Returns the closest parent to given element matching selector.

import { closest } from '@frampton/style';

const closestElement: HTMLElement =
  closest('.my-class', element);

contains

Returns a boolean indicating if the given element, or one of its children, matches the given selector.

import { contains } from '@frampton/style';

const doesContain: boolean =
  contains('.my-class', element);

currentValue

Returns the current value of the given CSS property on given element. Uses getComputedStyle under the hood.

import { currentValue } from '@frampton/style';

const currentHeight: string =
  currentValue('height', element);

hasClass

Returns a boolean indicating if given element has given class.

import { hasClass } from '@frampton/style';

const doesHaveClass: boolean =
  hasClass('my-class', element);

matches

Returns a boolean indicating the element matches the given selector.

import { matches } from '@frampton/style';

const doesMatch: boolean =
  matches('.my-class', element);

removeClass

Removes given class from element.

import { removeClass } from '@frampton/style';

removeClass('my-class', element);

removeStyle

Removes given style from element.

import { removeStyle } from '@frampton/style';

removeStyle('height', element);

selectorContains

Returns a boolean indicating if the given element is contained inside of an element matching given selector. Returns true if the element itself matches selector.

import { selectorContains } from '@frampton/style';

selectorContains('.my-class', element);

setStyle

Set value of a style on a given element.

import { setStyle } from '@frampton/style';

setStyle('height', '100px', element);

supported

Returns a string indicating the supported version of a given CSS property on the current browser (vendor prefix applied if needed);

import { supported } from '@frampton/style';

const transformOnBrowser: string =
  supported('transform');

supportedProps

Given a hash of CSS name/value pairs returns a new hash where the property names have any needed vendor prefixes applied.

import { supportedProps } from '@frampton/style';

const browserOpenState =
  supportedProps({
    transform: 'translate(100px)',
    opacity: '0.8',
    perspective: '300px'
  });