hashids typescript lua 定义文件
定义
package.json
{
"name": "@dalongrong/myhashids",
"version": "1.0.0",
"main": "index.js",
"types": "hashids.d.ts",
"license": "MIT",
"devDependencies": {
"typescript": "^4.6.3"
}
}
hashids.d.ts
declare module "hashids" {
interface Hashids {
encode(
decode(hashid:string):number[]
}
let exports: {
new: (this: void, saltKey: string,length?:number) => Hashids;
};
export default {
}
export = {
}
}
使用
可以先将上边的发布为npm 包,可以使用本地模式 yarn link
- ts 配置
{
"tstl": {
"luaTarget": "JIT",
"buildMode": "library",
"noResolvePaths":["platformlogin","@dalongrong/platform-login/dalong","hashids"]
},
"compilerOptions": {
"typeRoots": ["./node_modules/@dalongrong"], // 配置自己的types 位置
"target": "esnext",
"outDir": "dist",
"module": "commonjs", /* Specify what module code is generated. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": true, /* Enable all strict type-checking options. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
ids.ts
// 注意使用 *
import * as hashids from "hashids"
let id = hashids.new("demoapp")
console.log(id.encode(3333))
编译效果
说明
以上是关于ts hashids 类型定义的一个实践,后期计划会创建一个关于openresty 模块的repo,对于常用模块实现一个共享,会复用
社区的一个实现
参考资料
https://github.com/leihog/hashids.lua
https://typescripttolua.github.io/docs/advanced/writing-declarations#operator-overloads
https://github.com/andrei-markeev/openresty-lua-types
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2021-04-26 cube.js 自定义日志处理
2021-04-26 tendis nodejs 连接问题
2021-04-26 nodejs 异步转同步整理
2020-04-26 fusionauth 通用sso 解决方案学习二 基本试用
2020-04-26 zeeqs 一个通用的zeebe 数据查询服务
2020-04-26 zeebe 0.23.1 变动说明
2020-04-26 fusionauth 通用sso 解决方案学习一 环境运行