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

@imgcook/dsl-helper

v0.0.1

Published

dsl helper for davinci system(www.imgcook.com)

Downloads

236

Readme

@imgcook/dsl-helper

Helper for davinci dsl developer.

Usage

printer

 代码打印

// TEST CODE
const partsJson = [
  {
    type: 'line',
    parts: ["'use strict';"]
  },
  {
    type: 'line',
    parts: ['']
  },
  {
    type: 'line',
    parts: ["import styles from './lib/style.js';"]
  }
];

helper.printer(partsJson);

// RESULT
('use strict');

import styles from './lib/style.js';

parser

代码解析

// ORIGIN FILE
'use strict';

import styles from './lib/style.js';

// CODE
helper.parser(fileString);

// RESULT
[
  {
    type: 'line',
    parts: ["'use strict';"]
  },
  {
    type: 'line',
    parts: ['']
  },
  {
    type: 'line',
    parts: ["import styles from './lib/style.js';"]
  }
];

utils

代码打印工具函数

helper.utils.isArray([1,2,3]);
// ture

helper.utils.line(['hello');
// {
//   type: 'line',
//   parts: ['hello']
// }

helper.utils.string(['hello']);
// {
//   type: 'string',
//   parts: ['hello']
// }

helper.utils.indentTab();
// 对parts缩进

helper.utils.setIndentTab();
// 设置parts缩进

helper.utils.countIndent('        hello');
// 计算字符串缩进
// RESULT

// {
//   indent: {
//     tab: 2,
//     space: 3
//   },
//   pureStr: 'hello',
//   originStr: '        hello',
// }

weexProcessor

weex 下的样式处理器

let styles = helper.weexProcessor.filter({
  width: '100px',
  left: '0px',
  lines: 0,
  'margin-bottom': '0px', // 可忽略默认值
  hehehee: 'hehehe' // 非法属性
});
console.log(styles);

// RESULT

// { width: '100px', left: '0px', lines: 0 }

webProcessor

web 下的样式处理器

let styles = helper.weexProcessor.filter({
  width: '100px',
  left: '0px',
  lines: 0, // web下的非法属性,weex下并非非法属性
  'margin-bottom': '0px', // 可忽略默认值
  hehehee: 'hehehe' // 非法属性
});
console.log(styles);

// RESULT

// { width: '100px', left: '0px' }

processLayoutData

对 layout 的样式整体过滤一次

let layoutData = {
	style: {
		'width': '100px',
    'left': '0px',
    'lines': 0,
    'margin-bottom': '0px', // 可忽略默认值
    'hehehee': 'hehehe', // 非法属性
	},
	children: [
		{
			style: {
				'width': '100px',
				'left': '0px',
				'lines': 0,
				'margin-bottom': '0px', // 可忽略默认值
				'hehehee': 'hehehe', // 非法属性
			},
		},
		{
			style: {
				'width': '100px',
				'left': '0px',
				'lines': 0,
				'margin-bottom': '0px', // 可忽略默认值
				'hehehee': 'hehehe', // 非法属性
			},
		}
	]
};
let styles = helper.processLayoutData(layoutData, helper.weexProcessor);
console.log(styles);

// RESULT
{
	"style":{
		"width":"100px",
		"left":"0px",
		"lines":0
	},
	"children":[
		{
			"style":{
				"width":"100px",
				"left":"0px",
				"lines":0
			}
		},{
			"style":{
				"width":"100px",
				"left":"0px",
				"lines":0
			}
		}
	]
}

syntactic

分析函数,优先使用 acorn 分析,如果异常则使用原来的正则分析。 DSL 引擎,后端,前端都可使用。

helper.syntactic.parseFunction( `/**
 * @author 卡狸
 * @version 1.0
 * @param
 * @return
 */
export default function(args1, args2 = {}){
  let text = 'hello world';
  return {
    arg1,
    args2: text,
  }
};
` );

// RESULT
{
  "success": true,
  "message": "",
  "data": {
    "parser": "Acorn", // Acorn 解析 或 正则解析
    "args": [
      "args1",
      "args2"
    ], // 入参简写
    "params": [
      {
        "argsName": "args1",
        "argsContent": "args1",
        "argsType": "Identifier"
      },
      {
        "argsName": "args2",
        "argsContent": "args2 = {}",
        "argsType": "AssignmentPattern"
      }
    ], // 更多入参信息
    "content": "\tlet text = 'hello world';\n\treturn {\n\t\targ1,\n\t\targs2: text,\n\t}", // 原始内容
    "genContent": "  let text = 'hello world';\n  return {\n    arg1,\n    args2: text\n  };", // 去除注释内容
    "return": [
      {
        "key": "arg1",
        "valueType": "Identifier"
      },
      {
        "key": "args2",
        "valueType": "Identifier"
      }
    ] // 当return一个对象时,此数组会有值
  }
}

Unit Test

mocha ./test/index.js