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

jaw

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jaw - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

.idea/codeStyleSettings.xml

6

build/jaw.js

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

var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0.default:_0}();
var serialize=function(){var _1=require('./serialize');return _1.hasOwnProperty("serialize")?_1.serialize:_1.hasOwnProperty("default")?_1.default:_1}();
var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0["default"]:_0}();
var serialize=function(){var _1=require('./serialize');return _1.hasOwnProperty("serialize")?_1.serialize:_1.hasOwnProperty("default")?_1["default"]:_1}();

@@ -27,2 +27,2 @@ var Token = homunculus.getClass('token', 'css');

exports.default=new Jaw();
exports["default"]=new Jaw();

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

var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0.default:_0}();
var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0["default"]:_0}();

@@ -35,3 +35,3 @@ var Token = homunculus.getClass('token', 'jsx');

exports.default=function(node, excludeLine) {
exports["default"]=function(node, excludeLine) {
res = '';

@@ -38,0 +38,0 @@ recursion(node, excludeLine);

@@ -1,4 +0,4 @@

var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0.default:_0}();
var join=function(){var _1=require('./join');return _1.hasOwnProperty("join")?_1.join:_1.hasOwnProperty("default")?_1.default:_1}();
var sort=function(){var _2=require('./sort');return _2.hasOwnProperty("sort")?_2.sort:_2.hasOwnProperty("default")?_2.default:_2}();
var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0["default"]:_0}();
var join=function(){var _1=require('./join');return _1.hasOwnProperty("join")?_1.join:_1.hasOwnProperty("default")?_1["default"]:_1}();
var sort=function(){var _2=require('./sort');return _2.hasOwnProperty("sort")?_2.sort:_2.hasOwnProperty("default")?_2["default"]:_2}();

@@ -83,7 +83,163 @@ var Token = homunculus.getClass('token', 'css');

}
case Token.PSEUDO:
case Token.SIGN:
now[s] = now[s] || {};
now = now[s];
break;
case Token.PSEUDO:
var list = [s.replace(/^:+/, '')];
var prev = t.prev();
while(prev && prev.type() == Token.PSEUDO) {
_p += priority(prev);
list.push(prev.content().replace(/^:+/, ''));
prev = prev.prev();
i--;
}
//省略*
if(prev.type() != Token.SELECTOR) {
now['*'] = now['*'] || {};
now = now['*'];
}
else {
s = prev.content();
now[s] = now[s] || {};
now = now[s];
i--;
_p += priority(prev, s);
}
//伪类都存在_:对象下,是个数组
//每项为长度2的数组,第1个是伪类组合,第2个是对应的值
now['_:'] = now['_:'] || [];
var pseudos = now['_:'];
var pseudo = [];
list.forEach(function(item) {
//防止多次重复
if(pseudo.indexOf(item) == -1) {
pseudo.push(item);
}
});
//排序后比对,可能重复,合并之如a:hover{...}a:hover{...}会生成2个hover数组
sort(pseudo, function(a, b) {
return a < b;
});
var isExist = -1;
for(var j = 0, len = pseudos.length; j < len; j++) {
if(pseudos[j][0].join(',') == pseudo.join(',')) {
isExist = j;
break;
}
}
if(isExist > -1) {
now = pseudos[isExist][1];
}
else {
var arr = [];
arr.push(pseudo);
now = {};
arr.push(now);
pseudos.push(arr);
}
break;
case Token.SIGN:
switch(s) {
case '>':
case '+':
case '~':
now['_' + s] = now['_' + s] || {};
now = now['_' + s];
i--;
var prev = t.prev();
//省略*
if(prev.type() != Token.SELECTOR) {
now['*'] = now['*'] || {};
now = now['*'];
}
else {
s = prev.content();
now[s] = now[s] || {};
now = now[s];
_p += priority(prev, s);
}
break;
case ']':
var list = [];
var item;
var prev = t;
//可能有多个属性
while(prev.content() == ']') {
i--;
item = [];
prev = prev.prev();
while(prev) {
i--;
s = prev.content().replace(/^(['"'])(.*)\1/, '$2');
prev = prev.prev();
if(s == '[') {
break;
}
item.unshift(s);
}
list.push({
v: item,
s: item.join('')
});
_p += 10;
}
//省略*
if(prev.type() != Token.SELECTOR) {
now['*'] = now['*'] || {};
now = now['*'];
}
else {
s = prev.content();
now[s] = now[s] || {};
now = now[s];
i--;
_p += priority(prev, s);
}
//属性都存在_[对象下,是个数组
//每项为长度2的数组,第1个是属性组合,第2个是对应的值
now['_['] = now['_['] || [];
var attrs = now['_['];
var attr = [];
var attrTemp = {};
list.forEach(function(item) {
if(!attrTemp.hasOwnProperty(item.s)) {
attr.push(item.v);
attrTemp[item.s] = true;
}
});
//排序后比对,可能重复
sort(list, function(a, b) {
return a.s < b.s;
});
var isExist = -1;
for(var j = 0, len = attrs.length; j < len; j++) {
var s1 = '';
s1 += attrs[j][0].map(function(item) {
return item.join('');
});
var s2 = '';
s2 += attr.map(function(item) {
return item.join('');
});
if(s1 == s2) {
isExist = j;
break;
}
}
if(isExist > -1) {
now = attrs[isExist][1];
}
else {
var arr = [];
arr.push(attr);
now = {};
arr.push(now);
attrs.push(arr);
}
break;
//TODO: CSS3伪类
case ')':
break;
}
break;
}

@@ -93,6 +249,3 @@ }

styles.forEach(function(style) {
now._v.push({
i: idx,
v: style
});
now._v.push([idx, style]);
});

@@ -125,3 +278,3 @@ now._p = _p;

if(keys.length) {
var i = 1;
var i = 0;
keys.forEach(function(k) {

@@ -131,3 +284,5 @@ var item = res[k];

});
res._d = i;
if(i) {
res._d = i;
}
return i + 1;

@@ -140,2 +295,2 @@ }

exports.default=parse;
exports["default"]=parse;
{
"name": "jaw",
"version": "0.0.2",
"version": "0.0.3",
"description": "Parasitize CSS to JSX",

@@ -33,3 +33,4 @@ "maintainers": [

"dependencies": {
"homunculus": "~0.9.5"
"es6-shim": "*",
"homunculus": "~0.9.6"
},

@@ -46,3 +47,3 @@ "devDependencies": {

"through2": "^0.6.1",
"jsdc": "^0.6.2"
"jsdc": "^0.6.3"
},

@@ -49,0 +50,0 @@ "main": "./index",

@@ -12,4 +12,16 @@ # Parasitize CSS into JSX for migi

## 文档
https://github.com/migijs/jaw/wiki/%E6%96%87%E6%A1%A3
## API
* parse(code:String):Object 传入要解析的css代码,返回格式化好的json对象
* tokens():Array<Token> 返回css的token列表
* ast():Object 返回css的语法树
## Demo
* demo目录下是一个web端的实时转换例子,本地浏览需要`npm install`安装依赖
* 依赖的语法解析器来自于`homunculus`:https://github.com/army8735/homunculus
* 在线地址:http://army8735.me/migijs/jaw/demo/
# License
[MIT License]

@@ -83,7 +83,163 @@ import homunculus from 'homunculus';

}
case Token.PSEUDO:
case Token.SIGN:
now[s] = now[s] || {};
now = now[s];
break;
case Token.PSEUDO:
var list = [s.replace(/^:+/, '')];
var prev = t.prev();
while(prev && prev.type() == Token.PSEUDO) {
_p += priority(prev);
list.push(prev.content().replace(/^:+/, ''));
prev = prev.prev();
i--;
}
//省略*
if(prev.type() != Token.SELECTOR) {
now['*'] = now['*'] || {};
now = now['*'];
}
else {
s = prev.content();
now[s] = now[s] || {};
now = now[s];
i--;
_p += priority(prev, s);
}
//伪类都存在_:对象下,是个数组
//每项为长度2的数组,第1个是伪类组合,第2个是对应的值
now['_:'] = now['_:'] || [];
var pseudos = now['_:'];
var pseudo = [];
list.forEach(function(item) {
//防止多次重复
if(pseudo.indexOf(item) == -1) {
pseudo.push(item);
}
});
//排序后比对,可能重复,合并之如a:hover{...}a:hover{...}会生成2个hover数组
sort(pseudo, function(a, b) {
return a < b;
});
var isExist = -1;
for(var j = 0, len = pseudos.length; j < len; j++) {
if(pseudos[j][0].join(',') == pseudo.join(',')) {
isExist = j;
break;
}
}
if(isExist > -1) {
now = pseudos[isExist][1];
}
else {
var arr = [];
arr.push(pseudo);
now = {};
arr.push(now);
pseudos.push(arr);
}
break;
case Token.SIGN:
switch(s) {
case '>':
case '+':
case '~':
now['_' + s] = now['_' + s] || {};
now = now['_' + s];
i--;
var prev = t.prev();
//省略*
if(prev.type() != Token.SELECTOR) {
now['*'] = now['*'] || {};
now = now['*'];
}
else {
s = prev.content();
now[s] = now[s] || {};
now = now[s];
_p += priority(prev, s);
}
break;
case ']':
var list = [];
var item;
var prev = t;
//可能有多个属性
while(prev.content() == ']') {
i--;
item = [];
prev = prev.prev();
while(prev) {
i--;
s = prev.content().replace(/^(['"'])(.*)\1/, '$2');
prev = prev.prev();
if(s == '[') {
break;
}
item.unshift(s);
}
list.push({
v: item,
s: item.join('')
});
_p += 10;
}
//省略*
if(prev.type() != Token.SELECTOR) {
now['*'] = now['*'] || {};
now = now['*'];
}
else {
s = prev.content();
now[s] = now[s] || {};
now = now[s];
i--;
_p += priority(prev, s);
}
//属性都存在_[对象下,是个数组
//每项为长度2的数组,第1个是属性组合,第2个是对应的值
now['_['] = now['_['] || [];
var attrs = now['_['];
var attr = [];
var attrTemp = {};
list.forEach(function(item) {
if(!attrTemp.hasOwnProperty(item.s)) {
attr.push(item.v);
attrTemp[item.s] = true;
}
});
//排序后比对,可能重复
sort(list, function(a, b) {
return a.s < b.s;
});
var isExist = -1;
for(var j = 0, len = attrs.length; j < len; j++) {
var s1 = '';
s1 += attrs[j][0].map(function(item) {
return item.join('');
});
var s2 = '';
s2 += attr.map(function(item) {
return item.join('');
});
if(s1 == s2) {
isExist = j;
break;
}
}
if(isExist > -1) {
now = attrs[isExist][1];
}
else {
var arr = [];
arr.push(attr);
now = {};
arr.push(now);
attrs.push(arr);
}
break;
//TODO: CSS3伪类
case ')':
break;
}
break;
}

@@ -93,6 +249,3 @@ }

styles.forEach(function(style) {
now._v.push({
i: idx,
v: style
});
now._v.push([idx, style]);
});

@@ -125,3 +278,3 @@ now._p = _p;

if(keys.length) {
var i = 1;
var i = 0;
keys.forEach(function(k) {

@@ -131,3 +284,5 @@ var item = res[k];

});
res._d = i;
if(i) {
res._d = i;
}
return i + 1;

@@ -134,0 +289,0 @@ }

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

define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0.default:_0}();
var serialize=function(){var _1=require('./serialize');return _1.hasOwnProperty("serialize")?_1.serialize:_1.hasOwnProperty("default")?_1.default:_1}();
define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0["default"]:_0}();
var serialize=function(){var _1=require('./serialize');return _1.hasOwnProperty("serialize")?_1.serialize:_1.hasOwnProperty("default")?_1["default"]:_1}();

@@ -27,2 +27,2 @@ var Token = homunculus.getClass('token', 'css');

exports.default=new Jaw();});
exports["default"]=new Jaw();});

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

define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0.default:_0}();
define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0["default"]:_0}();

@@ -35,3 +35,3 @@ var Token = homunculus.getClass('token', 'jsx');

exports.default=function(node, excludeLine) {
exports["default"]=function(node, excludeLine) {
res = '';

@@ -38,0 +38,0 @@ recursion(node, excludeLine);

@@ -1,4 +0,4 @@

define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0.default:_0}();
var join=function(){var _1=require('./join');return _1.hasOwnProperty("join")?_1.join:_1.hasOwnProperty("default")?_1.default:_1}();
var sort=function(){var _2=require('./sort');return _2.hasOwnProperty("sort")?_2.sort:_2.hasOwnProperty("default")?_2.default:_2}();
define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0["default"]:_0}();
var join=function(){var _1=require('./join');return _1.hasOwnProperty("join")?_1.join:_1.hasOwnProperty("default")?_1["default"]:_1}();
var sort=function(){var _2=require('./sort');return _2.hasOwnProperty("sort")?_2.sort:_2.hasOwnProperty("default")?_2["default"]:_2}();

@@ -83,7 +83,163 @@ var Token = homunculus.getClass('token', 'css');

}
case Token.PSEUDO:
case Token.SIGN:
now[s] = now[s] || {};
now = now[s];
break;
case Token.PSEUDO:
var list = [s.replace(/^:+/, '')];
var prev = t.prev();
while(prev && prev.type() == Token.PSEUDO) {
_p += priority(prev);
list.push(prev.content().replace(/^:+/, ''));
prev = prev.prev();
i--;
}
//省略*
if(prev.type() != Token.SELECTOR) {
now['*'] = now['*'] || {};
now = now['*'];
}
else {
s = prev.content();
now[s] = now[s] || {};
now = now[s];
i--;
_p += priority(prev, s);
}
//伪类都存在_:对象下,是个数组
//每项为长度2的数组,第1个是伪类组合,第2个是对应的值
now['_:'] = now['_:'] || [];
var pseudos = now['_:'];
var pseudo = [];
list.forEach(function(item) {
//防止多次重复
if(pseudo.indexOf(item) == -1) {
pseudo.push(item);
}
});
//排序后比对,可能重复,合并之如a:hover{...}a:hover{...}会生成2个hover数组
sort(pseudo, function(a, b) {
return a < b;
});
var isExist = -1;
for(var j = 0, len = pseudos.length; j < len; j++) {
if(pseudos[j][0].join(',') == pseudo.join(',')) {
isExist = j;
break;
}
}
if(isExist > -1) {
now = pseudos[isExist][1];
}
else {
var arr = [];
arr.push(pseudo);
now = {};
arr.push(now);
pseudos.push(arr);
}
break;
case Token.SIGN:
switch(s) {
case '>':
case '+':
case '~':
now['_' + s] = now['_' + s] || {};
now = now['_' + s];
i--;
var prev = t.prev();
//省略*
if(prev.type() != Token.SELECTOR) {
now['*'] = now['*'] || {};
now = now['*'];
}
else {
s = prev.content();
now[s] = now[s] || {};
now = now[s];
_p += priority(prev, s);
}
break;
case ']':
var list = [];
var item;
var prev = t;
//可能有多个属性
while(prev.content() == ']') {
i--;
item = [];
prev = prev.prev();
while(prev) {
i--;
s = prev.content().replace(/^(['"'])(.*)\1/, '$2');
prev = prev.prev();
if(s == '[') {
break;
}
item.unshift(s);
}
list.push({
v: item,
s: item.join('')
});
_p += 10;
}
//省略*
if(prev.type() != Token.SELECTOR) {
now['*'] = now['*'] || {};
now = now['*'];
}
else {
s = prev.content();
now[s] = now[s] || {};
now = now[s];
i--;
_p += priority(prev, s);
}
//属性都存在_[对象下,是个数组
//每项为长度2的数组,第1个是属性组合,第2个是对应的值
now['_['] = now['_['] || [];
var attrs = now['_['];
var attr = [];
var attrTemp = {};
list.forEach(function(item) {
if(!attrTemp.hasOwnProperty(item.s)) {
attr.push(item.v);
attrTemp[item.s] = true;
}
});
//排序后比对,可能重复
sort(list, function(a, b) {
return a.s < b.s;
});
var isExist = -1;
for(var j = 0, len = attrs.length; j < len; j++) {
var s1 = '';
s1 += attrs[j][0].map(function(item) {
return item.join('');
});
var s2 = '';
s2 += attr.map(function(item) {
return item.join('');
});
if(s1 == s2) {
isExist = j;
break;
}
}
if(isExist > -1) {
now = attrs[isExist][1];
}
else {
var arr = [];
arr.push(attr);
now = {};
arr.push(now);
attrs.push(arr);
}
break;
//TODO: CSS3伪类
case ')':
break;
}
break;
}

@@ -93,6 +249,3 @@ }

styles.forEach(function(style) {
now._v.push({
i: idx,
v: style
});
now._v.push([idx, style]);
});

@@ -125,3 +278,3 @@ now._p = _p;

if(keys.length) {
var i = 1;
var i = 0;
keys.forEach(function(k) {

@@ -131,3 +284,5 @@ var item = res[k];

});
res._d = i;
if(i) {
res._d = i;
}
return i + 1;

@@ -140,2 +295,2 @@ }

exports.default=parse;});
exports["default"]=parse;});

Sorry, the diff of this file is not supported yet

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