Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Easily create and manipulate CSSStyleDeclarations
with javascript:
import { StyleSheet } from 'sheetjs';
// or
const { StyleSheet } = window.sheetjs;
const styleSheet = new StyleSheet();
const s = styleSheet.stylesForSelector;
// changes background color for all current and future matching elements
s('#content .my-selector').backgroundColor = 'green';
Good for when you have a dynamic number of elements that need dynamic styling.
Imagine a web page with 1000 elements with class my-el
, and you want to change their background-color
to green
.
Using jQuery:
// changes background color for all current matching elements
$('.my-el').css('background-color', 'green');
// took ~10ms
// new elements will not be green
Using SheetJS:
// changes background color for all current and future matching elements
s('.my-el').backgroundColor = 'green';
// took <1ms
// new elements will be green
http://codepen.io/jshanson7/pen/Jdpdga?editors=001
npm install sheetjs
Then reference either dist/sheet.js
or dist/sheet.min.js
in your html, or import 'sheetjs'
. If a module environment is not detected, sheetjs
will be exported to window.sheetjs
.
import StyleSheet from 'sheetjs/StyleSheet';
const styleSheet = new StyleSheet({
'html, body': {
margin: 0,
padding: 0
},
'.my-el': {
backgroundColor: 'green'
},
'.my-el:hover': {
backgroundColor: 'blue'
}
});
import StyleSheet from 'sheetjs/StyleSheet';
const styleSheet = new StyleSheet();
const s = styleSheet.stylesForSelector;
// stylesForSelector - get CSSStyleDeclaration for selector (or create if it doesn't exist)
const styleDeclaration = styleSheet.stylesForSelector('.my-el');
styleDeclaration.backgroundColor = 'green';
// deleteStylesForSelector - delete CSSStyleDeclaration for selector
styleSheet.deleteStylesForSelector('.my-el'); // 'backgroundColor' is no longer green
// getStylesForSelector - get existing CSSStyleDeclaration for selector
const styleDeclaration2 = styleSheet.getStylesForSelector('.doesnt-exist');
styleDeclaration2 === undefined; // true
// disable - disables the stylesheet (and all generated styles)
styleSheet.disable();
// enable - enables the stylesheet (and all generated styles)
styleSheet.enable();
Clone repo, cd into it.
npm install && npm start
npm run build
Run the tests on your browser here.
npm test && npm run test-browser
MIT
FAQs
Placeholder package for SheetJS
The npm package sheetjs receives a total of 1,955 weekly downloads. As such, sheetjs popularity was classified as popular.
We found that sheetjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.