更新时间:2024-04-10 GMT+08:00
        
          
          
        
      
      
      
      
      
      
      
      
  
      
      
      
        
使用JS类库
内置类库列表
   断言
   
  - chai (v4.2.0):用于断言BDD/TDD断言。
 
加密解密库
- jsrsasign(10.3.0):用于RSA加密/解密。
 
   Encode、Decode 库
   
  
  
   JSONSchema校验库
   
  - ajv(v6.6.2):校验JSONSchema。
 
   实用工具
   
  - postman-collection( v3.4.0):Postman Collection库。
 - cheerio(v0.22.0):jQuery的子集。
 - lodash (v4.17.11):JS实用工具库。
 - uuid :生成UUID。
 - moment(v2.22.2):日期处理库 (不含 locales)。
 - mockjs:模拟数据生成,拦截Ajax请求。
 - csv-parse/lib/sync( v1.2.4):处理CSV格式数据。
 - iconv-lite:用于字符编码转换,支持数十种字符编码格式的转换。
 
   内置NodeJS模块
   
  
  
   通过require方法可以直接使用CodeArts API内置的JS类库。
   
 var cryptoJs = require("crypto-js");
console.log(cryptoJs.SHA256("Message"));
  使用方式
/**
 * 示例一:该示例引入加密算法模块 crypto-js,并使用其中 AES 对 message 进行加解密 
 * @param message 需要加密的文本
 * @param key 秘钥
 */
function cryptoJSTest(message, key) {
    const CryptoJS = require('crypto-js');
    // 加密
    const ciphertext = CryptoJS.AES.encrypt(message, key).toString();
    // 解密
    const bytes  = CryptoJS.AES.decrypt(ciphertext, key);
    const originalText = bytes.toString(CryptoJS.enc.Utf8);
    console.log(originalText);
}
cryptoJSTest('test message', 'secret key');
/**
 * 示例二:该示例引入 uuid 模块生成一段 uuid,并引入 btoa 模块进行 Base64 编码
 */
function uuidBtoaTest() {
    const uuid = require('uuid');
    const btoa = require('btoa');
    const id = uuid.v4();
    const base64EncodedId = btoa(id);
    console.log(id);
    console.log(base64EncodedId);
}
uuidBtoaTest();
/**
 * 示例三:该示例引入 lodash 模块,并测试了其中的 uniq 对数组去重
 */
function lodashUniqTest() {
    const lodash = require('lodash');
    const arr =[1, 2, 1, 5, 1, 9]
    const uniqArr = lodash.uniq(arr);
    console.log(uniqArr.toString())
}
lodashUniqTest();
 
   父主题: 脚本能力