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

com.iflytek.clst.transformation

v1.0.1

Published

clst questionbank transformation

Downloads

1

Readme

1.构建过程

简单构建

执行 build脚本命令 `node build.js`,产物位于dist/路径下

指定版本号构建

1. 修改build.js 脚本中的version 字段值
2. 执行node build.js 命令

2.使用方法

调用js transform(json) 函数获取标准题型json字符串
参数:待解析的非标准题型json字符串
返回: 解析后的标准题型json字符串
返回结构 :
```
{
  "code":[0或1], //int 1代表转换成功,其他代表转换失败
  "message":"transform success", //转换成功或失败的信息
  "data": json, //转换成功后的标准 题型结构。
}
```

三端(Android/iOS/Web集成方案)

Android:WebView、Google V8(J2V8)、Rhino、JsCore等,推荐用J2V8执行js脚本

iOS:在iOS7 提供了原生JavaScriptCore Api 用来执行js脚本

Web/小程序: 略

3.开发规范

需要新曾题型的转换需求时,要遵循以下开发规范:

1. 命名规范-强制:每个题型对应一个名为[题型编码]_transformer 转换类(比如xk题型对应的转换类名为xk_transformer)。

2. 转换逻辑需要实现在名为transform(json) 函数中:入参为需要转换的题型json数据,返回
转换后的标准题型json结构。如果需要解析其他题型,可以通过调用
function getTransformer(code)函数获取对应的解析器进行解析(注意,当SDK库中没有code对应的解析器时,调用该函数会返回null)。

3.transform类的构造函数必须是无参的


附加说明

项目的目的是方便快速开发题型转换脚本并部署共享,对项目结构的要求是结构简单,无需复杂框架;对构建方法的要求是简单快速;对构建产物的要求是轻量。因此在选型构建方案时,pass掉了webpack以及rollup,使用仅引入Terser插件对js脚本文件合并压缩与混淆。

1.项目结构

dist      --构建产物目录
src       --js脚本目录
build.js  --构建脚本
README.md --项目说明文档

2.新增题型自动注册原理

  1. 维护一个全部map用于保存所有转换器

  2. 打包时遍历src 路径下的所有js类,找到以"_transformer"结尾的类,生成transformer对象并保存到map中。

  3. 将map 追加到合并的js中间产物,最后交给Terser 打包文件。

  4. 关键代码保存在打包脚本build.js中:

    function _generateAllTransformers(sourceCode) {
    // 使用正则表达式匹配以 _transformer 结尾的类名
    const classNames = sourceCode.match(/class\s+([^\s{]+)_transformer\s*{/g);
    
    // 提取类名
    const transformerClassNames = classNames.map(name => name.match(/class\s+([^\s{]+)_transformer\s*{/)[1]);
    
    console.log("enabled transformers:" + transformerClassNames);
    
    var placeHolder = ""
    transformerClassNames.forEach((item, index, arr) => {
        if (index == 0) { placeHolder += '{' } else { placeHolder += "," }
        placeHolder += "\"" + item + "\": new " + item + "_transformer()"
        if (index == arr.length - 1) { placeHolder += "}" }
    });
    
    console.log('transformer map: ' + placeHolder);
    
    let result = sourceCode + "\ntransformers=" + placeHolder
    
    console.log("Result:\n" + result);
    
    return result;
    }
      

  5. 项目创建过程

     项目初始化:npm install terser --save-dev
     创建脚本文件:创建'build.js',用于运行Tenser
     创建src文件目录:创建源码目录用于编写转换脚本