Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

css-rule-stream

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-rule-stream - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

.travis.yml

45

lib/match.js
var through = require('through2');
var newline = '\n'.charCodeAt(0);
// object mode transform stream takes tokenized css and yields complete,
// parseable rules or at-rules as strings.
module.exports = function match() {
var current = null, depth = 0;
var current = null; // buffer for the current incoming rule.
var depth = 0; // track depth to handle rules nested in at-rules.
var line = 1, column = 1; // track this and pass it downstream for source mapping.
function write(token, enc, next) {
var type = token[0], buf = token[1];
if(depth === 0 && current) {
this.push({content: Buffer.concat(current).toString()});
current = null;
}
if(('rule_start' === type || 'atrule_start' === type))
depth++;
if(depth > 0 && !current)
current = [];
current = {location: [line, column], buffers:[]};
if('rule_end' === type || 'atrule_end' === type)
depth--;
if(current) current.push(buf);
if(current) {
current.buffers.push(buf);
if(depth === 0) pushRule.call(this);
}
updatePosition(buf);
next();

@@ -26,7 +33,29 @@ }

function end(next) {
if(current) this.push({content: Buffer.concat(current).toString()});
if(current) pushRule.call(this);
this.push(null);
next();
}
function pushRule() {
this.push({
line: current.location[0],
column: current.location[1],
content: Buffer.concat(current.buffers).toString()
});
current = null;
}
function updatePosition(buf) {
for(var i = 0; i < buf.length; i++) {
if(buf[i] === newline) {
line ++;
column = 1;
}
else {
column++;
}
}
}
return through.obj(write, end);
}

2

package.json
{
"name": "css-rule-stream",
"version": "1.0.3",
"version": "1.1.0",
"description": "transform stream to cut css into rule-sized chunks",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,2 +0,2 @@

css-rule-stream
css-rule-stream [![Build Status](https://travis-ci.org/anandthakker/css-rule-stream.svg?branch=master)](https://travis-ci.org/anandthakker/css-rule-stream)
===============

@@ -3,0 +3,0 @@

@@ -10,12 +10,12 @@

var expected = [
{"content":"div {\n background: red;\n}"},
{"content":".cls {\n color: green;\n}"},
{"content":"#id {\n font-size: 10px;\n}"},
{"content":"@media screen and (min-width: 1000px) {\n a {\n text-decoration: underline;\n }\n}"},
{"content":"a:hover {\n font-weight: bold; \n}"},
{"content":"section \n\n\n{\n margin: 0;\n /* comment wthin a rule */\n padding: 5px;\n}"},
{"content":"body > * {\n \n}"}
{"line": 2, "column": 1, "content":"div {\n background: red;\n}"},
{"line": 4, "column": 2, "content":".cls {\n color: green;\n}"},
{"line": 8, "column": 1, "content":"#id {\n font-size: 10px;\n}"},
{"line": 14, "column": 1, "content":"@media screen and (min-width: 1000px) {\n a {\n text-decoration: underline;\n }\n}"},
{"line": 20, "column": 1, "content":"a:hover {\n font-weight: bold; \n}"},
{"line": 24, "column": 1, "content":"section \n\n\n{\n margin: 0;\n /* comment wthin a rule */\n padding: 5px;\n}"},
{"line": 34, "column": 1, "content":"body > * {\n \n}"}
]
t.plan(expected.length);
t.plan(expected.length + 1);

@@ -26,2 +26,6 @@ var rs = rules();

next();
},
function(next) {
t.ok(true);
next();
}));

@@ -28,0 +32,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc