Skip to content

Commit

Permalink
Merge pull request #66 from MichealWayne/feat-utils-npm
Browse files Browse the repository at this point in the history
feat update ai utils & links
  • Loading branch information
MichealWayne authored May 14, 2024
2 parents 6bc522e + 2c917d4 commit 119cd96
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 更新信息

- 2024.05.14:ai utils增加单测prompt;主页链接调整
- 2024.04.27:web utils资源加载方法、ua环境判断优化
- 2024.04.07:utils 增加 env环境判断、web utils 增加资源加载相关方法
- 2024.03.10:修改 utils & web util functions(部分方法类型声明及参数处理优化, Storage)
Expand Down
1 change: 1 addition & 0 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ A schema declaration and verification library headed by TypeScript, which can be
| http://lab.ejci.net/favico.js/ | favicojs | A plugin for animating the pc website icon. |
| https://alvarotrigo.com/fullPage/ | fullpagejs | A plugin for quickly building full-screen scrolling pages. |
| https://github.com/buuing/lucky-canvas | lucky-canvas | A lottery plugin that supports web and cross-platform compatibility with mini-programs (large turntables/nine-square grids/slot machines). |
| https://mattboldt.com/demos/typed-js/ | typed.js | A js UI library that simulates typewriter effects. |

### Video/Audio

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<a href="https://www.typescriptlang.org/docs/handbook/intro.html" target="_blank">TypeScript官方手册</a> | `typescript` | TypeScript官方手册。
<a href="https://github.com/type-challenges/type-challenges" target="_blank">TypeScript Challenges</a> | `ts-challenges` | TypeScript Challenges,在线学习/检验自己的ts类型编程水平。
<a href="https://www.ecma-international.org/publications-and-standards/standards/" target="_blank">ECMA standards | `ecma` | ECMAScript 协议标准。
<a href="http://www.ecma-international.org/ecma-262/6.0/" target="_blank">ECMA International(6)</a> | `ES6` | ECMAScript6官方文档。
<a href="https://www.ecma-international.org/ecma-262/6.0/" target="_blank">ECMA International(6)</a> | `ES6` | ECMAScript6官方文档。
<a href="https://ecma262.docschina.org/" target="_blank">ECMA International(6) 汉化 | `ES6` | ECMAScript6官方文档的中文翻译版(只有少部分且挺久没更新了)。
<a href="http://es6-features.org/" target="_blank">ECMA6 features | `ES6` | 通俗易懂的ECMAScript6特性demos。
<a href="https://es6.ruanyifeng.com/" target="_blank">ES6入门(阮一峰)</a> | `ES6` | 国内使用频率最高的ECMAScript6文档,特别适合新手。
Expand Down Expand Up @@ -209,6 +209,7 @@
<a href="http://lab.ejci.net/favico.js/" target="_blank">favico.js</a> | `favicojs` | 一款让pc网站图标动起来的插件。
<a href="https://alvarotrigo.com/fullPage/" target="_blank">fullPage.js</a> | `fullpagejs` | 一款快速搭建全屏滚动页面的插件。
<a href="https://github.com/buuing/lucky-canvas" target="_blank">Lucky Canvas</a> | `lucky-canvas` | 一款支持web、小程序跨平台的 ( 大转盘 / 九宫格 / 老虎机 ) 抽奖插件。
<a href="https://mattboldt.com/demos/typed-js/" target="_blank">Typedjs</a> | `typed.js` | 一款模拟打字机效果的js UI库。

##### 视/音频
地址 | 标签 | 说明
Expand All @@ -217,7 +218,7 @@
<a href="https://videojs.com/" target="_blank">video.js</a> | `videojs` | 一款视频控制插件。
<a href="https://github.com/bilibili/flv.js" target="_blank">flv.js</a> | `flvjs` | 一款无需flash的flv播放插件。
<a href="https://github.com/goldfire/howler.js#documentation" target="_blank">howler.js</a> | `howlerjs` | 视、音频控制插件。
<a href="http://jplayer.org/" target="_blank">jplayer</a> | `jplayer` | jQuery的视、音频控制插件。
<a href="https://jplayer.org/" target="_blank">jplayer</a> | `jplayer` | jQuery的视、音频控制插件。
<a href="https://github.com/zohararad/audio5js" target="_blank">audio5.js</a> | `audio5js` | 一款音频控制插件。

##### 图片
Expand All @@ -236,7 +237,7 @@
地址 | 标签 | 说明
---- | ---- | ----
<a href="https://vocajs.com/" target="_blank">Voca.js</a> | `vocajs` | 字符串的驼峰/修饰/填充/截断/转义/大小写更改等等。
<a href="http://alexcorvi.github.io/anchorme.js/" target="_blank">anchorme.js</a> | `anchormejs` | 自动将文本中的链接/URL/电子邮件转化为可点击的锚点链接。
<a href="https://alexcorvi.github.io/anchorme.js/" target="_blank">anchorme.js</a> | `anchormejs` | 自动将文本中的链接/URL/电子邮件转化为可点击的锚点链接。
<a href="https://github.com/jprichardson/string.js" target="_blank">String.js</a> | `stringjs` | 字符串的截取删除等操作库(很久没维护了)。
<a href="https://github.com/ljharb/qs" target="_blank">qs.js</a> | `qsjs` | URL参数处理库。
<a href="https://zelark.github.io/nano-id-cc/" target="_blank">nano-id</a> | `nanoid` | 小型(130 字节)、安全、URL友好、唯一的字符串 ID 生成器。
Expand All @@ -248,9 +249,9 @@
#### 1.4.5 工具
地址 | 标签 | 说明
---- | ---- | ----
<a href="http://requirejs.org/" target="_blank">RequireJs</a> | `requirejs` | js模块化工具(webpack后很少有项目会用到)。
<a href="https://requirejs.org/" target="_blank">RequireJs</a> | `requirejs` | js模块化工具(webpack后很少有项目会用到)。
<a href="http://yslove.net/seajs/" target="_blank">SeaJs</a> | `seajs` | js模块化工具(webpack后很少有项目会用到)。
<a href="http://browserify.org/" target="_blank">Browserify</a> | `browserify` | 浏览器端使用类似于 node 的 require() 方式。
<a href="https://browserify.org/" target="_blank">Browserify</a> | `browserify` | 浏览器端使用类似于 node 的 require() 方式。
<a href="https://github.com/rickharrison/validate.js" target="_blank">validate.js</a> | `validate.js` | form表单校验工具。
<a href="https://github.com/validatorjs/validator.js" target="_blank">validator.js</a> | `validator.js` | 有名的内容校验工具,比如邮箱验证、数值验证等。
<a href="https://cn.rx.js.org/" target="_blank">RxJS中文官网</a> | `RxJS` | ReactiveX编程理念的js异步编程库。
Expand Down Expand Up @@ -319,7 +320,7 @@
#### 1.4.10 加载
地址 | 标签 | 说明
---- | ---- | ----
<a href="http://pazguille.github.io/aload/" target="_blank">aload.js</a> | `aload.js` | 异步图片/js/css加载工具。
<a href="https://pazguille.github.io/aload/" target="_blank">aload.js</a> | `aload.js` | 异步图片/js/css加载工具。
<a href="http://callmecavs.com/layzr.js/" target="_blank">layzr.js</a> | `layzr.js` | 轻量图片懒加载工具。
<a href="https://github.com/aFarkas/lazysizes" target="_blank">lazysizes.js</a> | `lazysizes` | 高性能的图片/iframe懒加载工具。
<a href="https://infinite-scroll.com/" target="_blank">infinite-scroll.js</a> | `infinite-scroll` | “无限”滚动的加载插件。
Expand Down
6 changes: 6 additions & 0 deletions datas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# fe-tools datas

供 chrome 插件进行搜索和查询的数据。
- `moo-css.json`:样式查询
- `regex.json`:正则规则查询
- `tools.json`:各常用链接查询
1 change: 1 addition & 0 deletions datas/moo-css.json

Large diffs are not rendered by default.

247 changes: 247 additions & 0 deletions datas/regex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
[{
"id": "mail",
"name": "邮箱",
"description": "只允许英文字母、数字、下划线、英文句号、以及中划线组成",
"regexStr": "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$"
},
{
"id": "phone",
"name": "手机号",
"description": "",
"regexStr": "^1(3|4|5|6|7|8|9)\\d{9}$"
},
{
"id": "tel",
"name": "电话",
"description": "固定电话",
"regexStr": "(\\(\\d{3,4}\\)|\\d{3,4}-|\\s)?\\d{8}"
},
{
"id": "url",
"name": "URL地址",
"description": "",
"regexStr": "^((http:\/\/)|(https:\/\/))?([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}(\/?)"
},
{
"id": "ipv4",
"name": "IP",
"description": "符合IPV4",
"regexStr": "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
},
{
"id": "ipv6",
"name": "IP",
"description": "符合IPV6",
"regexStr": "^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$"
},
{
"id": "userName",
"name": "用户名",
"description": "字母开头,允许5-16字节,允许字母数字下划线",
"regexStr": "^[a-zA-Z][a-zA-Z0-9_]{4,15}$"
},
{
"id": "chinese",
"name": "中文",
"description": "",
"regexStr": "^[\u4e00-\u9fa5]{1,}$"
},
{
"id": "Integer",
"name": "整数数字",
"description": "",
"regexStr": "^-?[1-9]\\d*$"
},
{
"id": "PositiveInteger",
"name": "正整数数字",
"description": "",
"regexStr": "^[1-9]\\d*$"
},
{
"id": "NegativeInteger",
"name": "负整数数字",
"description": "",
"regexStr": "^-[1-9]\\d*$"
},
{
"id": "number4",
"name": "非负整数数字",
"description": "",
"regexStr": "^[1-9]\\d*|0$"
},
{
"id": "number5",
"name": "非正整数数字",
"description": "",
"regexStr": "^-[1-9]\\d*|0$"
},
{
"id": "Positivenumber",
"name": "零和正数",
"description": "",
"regexStr": "^\\d*\\.?\\d+$"
},
{
"id": "Negativenumber",
"name": "负数",
"description": "",
"regexStr": "^-\\d*\\.?\\d+$"
},
{
"id": "number6",
"name": "浮点数",
"description": "不能为整数",
"regexStr": "^-?([1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*|0?\\.0+|0)$"
},
{
"id": "number7",
"name": "正浮点数",
"description": "不能为整数",
"regexStr": "^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$"
},
{
"id": "number8",
"name": "负浮点数",
"description": "不能为整数",
"regexStr": "^-([1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*)$"
},
{
"id": "number9",
"name": "非负浮点数",
"description": "不能为整数",
"regexStr": "^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*|0?\\.0+|0$"
},
{
"id": "number10",
"name": "非正浮点数",
"description": "不能为整数",
"regexStr": "^(-([1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*))|0?\\.0+|0$"
},
{
"id": "englishAndNumber",
"name": "英文和数字",
"description": "",
"regexStr": "^[A-Za-z0-9]+$"
},
{
"id": "englishAndNumberAndLine",
"name": "中文英文数字或下划线",
"description": "由中文、数字、26个英文字母或者下划线组成的字符串",
"regexStr": "^[\u4E00-\u9FA5A-Za-z0-9_]+$"
},
{
"id": "chineseAndEnglishAndNumberAndLine",
"name": "中文英文数字或下划线",
"description": "中文、英文、数字包括下划线",
"regexStr": "^\\w+$"
},
{
"id": "chineseAndEnglishAndNumberNotLine",
"name": "中文英文数字无符号",
"description": "中文、英文、数字但不包括下划线等符号",
"regexStr": "^[\u4E00-\u9FA5A-Za-z0-9]+$"
},
{
"id": "lengthExample",
"name": "长度限制",
"description": "长度为6~8,任意字符",
"regexStr": "^.{6,8}$"
},
{
"id": "english",
"name": "英文",
"description": "由26个英文字母组成的字符串",
"regexStr": "^[A-Za-z]+$"
},
{
"id": "english2",
"name": "英文",
"description": "由26个大写英文字母组成的字符串",
"regexStr": "^[A-Z]+$"
},
{
"id": "english3",
"name": "英文",
"description": "由26个小写英文字母组成的字符串",
"regexStr": "^[a-z]+$"
},
{
"id": "noSymbol1",
"name": "禁止符号",
"description": "禁止输入含有%&\",;=?$\"等字符",
"regexStr": "[^%&\",;=?$\\x22]+"
},
{
"id": "noWave",
"name": "禁止~符号",
"description": "禁止输入含有~的字符",
"regexStr": "[^~\\x22]+"
},
{
"id": "dateFormat",
"name": "日期格式",
"description": "日期格式符合mm/dd/yyyy规范",
"regexStr": "^(0?[1-9]|[12][0-9]|3[01])([\/\\-])(0?[1-9]|1[012])\\2([0-9][0-9][0-9][0-9])(([-])([0-1]?[0-9]|2[0-3]):[0-5]?[0-9]:[0-5]?[0-9])?$"
},
{
"id": "timeFormat",
"name": "时间格式hh:mm",
"description": "时间格式符合24小时格式规范",
"regexStr": "^([01]?[0-9]|2[0-3]):[0-5][0-9]$"
},
{
"id": "md5",
"name": "MD5",
"description": "32位MD5字符串",
"regexStr": "^[a-f0-9]{32}$"
},
{
"id": "base64",
"name": "BASE64",
"description": "BASE64字符串",
"regexStr": "^\\s*data:(?:[a-z]+\/[a-z0-9-+.]+(?:;[a-z-]+=[a-z0-9-]+)?)?(?:;base64)?,([a-z0-9!$&',()*+;=\\-._~:@\/?%\\s]*?)\\s*$"
},
{
"id": "hexColor",
"name": "十六进制颜色",
"description": "",
"regexStr": "^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$"
},
{
"id": "video",
"name": "视频文件",
"description": "",
"regexStr": ".*?(?:swf|avi|flv|mpg|rm|mov|wav|asf|3gp|mkv|rmvb|mp4)$"
},
{
"id": "image",
"name": "图片文件",
"description": "",
"regexStr": ".*?(?:gif|png|jpg|jpeg|webp|svg|psd|bmp|tif)$"
},
{
"id": "newEnergyLicense",
"name": "新能源车牌",
"description": "",
"regexStr": "[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(([0-9]{5}[DF])|([DF][A-HJ-NP-Z0-9][0-9]{4}))$"
},
{
"id": "license",
"name": "普通车牌",
"description": "新能源车+非新能源车",
"regexStr": "^(?:[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(?:(?:[0-9]{5}[DF])|(?:[DF](?:[A-HJ-NP-Z0-9])[0-9]{4})))|(?:[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9 挂学警港澳]{1})$"
},
{
"id": "A-SHARE",
"name": "股票-A股",
"description": "股票代码",
"regexStr": "^(s[hz]|S[HZ])(000[\\d]{3}|002[\\d]{3}|300[\\d]{3}|600[\\d]{3}|60[\\d]{4})$"
},
{
"id": "wechatId",
"name": "微信号",
"description": "",
"regexStr": "^[a-zA-Z][-_a-zA-Z0-9]{5,19}$"
}
]
1 change: 1 addition & 0 deletions datas/tools.json

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions utils/packages/ai-utils/src/applications/createUnitTestCases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @author Wayne
* @Date 2024-05-11 10:40:18
* @LastEditTime 2024-05-11 10:47:53
*/
import { estimateTokenLength } from '../llm/prompts';
const MAX_TOKEN_LEN = 4000; // GPT3.5 4096

export function getCreateUnitTestCases(patch: string) {
return `### Unit Test ###
You are an expert software tester tasked with thoroughly testing a given piece of code, you are proficient in JavaScript/TypeScript.
Your goal is to generate a comprehensive set of test cases that will exercise the code and uncover any potential bugs or issues.
First, carefully analyze the provided code. Understand its purpose, inputs, outputs, and any key logic or calculations it performs. Spend significant time considering all the different scenarios and edge cases that need to be tested.
Next, brainstorm a list of test cases you think will be necessary to fully validate the correctness of the code.
Your current role is: UnitTest code generator
##
- use jest test framework
- use typescript
- the test environment is Node.js
- only generate code with no explain
- write the\`prepareChatMessages\` and \`getFirstAnswerMsg\` and \`setChatMessages\` and \`setModel\` method's unit test cases
Here is your target code to generate tests:
\`\`\`
{{your_code_here}}
\`\`\`
`;
}

export function genUnitTestCasesPrompt(codeStr: string, maxLen = MAX_TOKEN_LEN) {
const promptTxt = getCreateUnitTestCases(codeStr);

if (estimateTokenLength(promptTxt) > maxLen) {
return '';
}
return promptTxt;
}
3 changes: 2 additions & 1 deletion utils/packages/ai-utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/**
* @author Wayne
* @Date 2023-09-05 09:38:19
* @LastEditTime 2023-11-11 10:17:13
* @LastEditTime 2024-05-11 10:54:24
*/
// gpt application
export * from './applications/codeReview';
export * from './applications/sql';
export * from './applications/createUnitTestCases';

// llm utils
export * from './llm/prompts';
Expand Down
Loading

0 comments on commit 119cd96

Please sign in to comment.