![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@aiot-toolkit/card-expression
Advanced tools
用于
JS表达式
转换为 快应用卡片表达式
模板表达式
转换为 快应用卡片表达式
快应用卡片表达式是一种类似 lisp的语法树表达式
示例
js 表达式 | 转换后 |
---|---|
a+123 | ["+", ["$", "a"], 123] |
!a | ["!", ["$", "a"]] |
a[1].x.y | [".",[".", ["[]", ["$", "a"], 1], "x", "y" |
fun(a, b, 124) | ["()", ["$", "fun"], ["$", "a"], ["$", "b"], 124] |
模板表达式 | 转换后 |
---|---|
a+b{{a+b}} | ["+","a+b",["+",["$","a"],["$","b"]]] |
import { templateValueToCardCode } from '@aiot-toolkit/card-expression';
const result = templateValueToCardCode('a+b{{a+b}}');
console.log(result); // ["+","a+b",["+",["$","a"],["$","b"]]]
import jsToCardCode from '@aiot-toolkit/card-expression';
const result = jsToCardCode('a+b');
console.log(result); // '["+", ["$", "a"], ["$", "b"]]'
模板表达式是快应用使用的字符串和 js 混合的表达式,双大括号中的内容为 js,其 它为字符串
示例:aaaa{{x+y}}bbbb
等于 js 代码 "aaaa" + (x + y) + "bbbb"
快应用卡片支持的js 表达式如下。需要注意的是,各表达式之间可递归使用,例
如 data[a+b]
data.x + (a?1:2)
表达式 | 源码 | 产物 | 示例 |
---|---|---|---|
字面量 literal | value | value | 123 --> 123 |
标识符 Identifier | value | ["$", "value"] | a -->["$", "a"] |
数组表达式 ArrayExpression | [value1, value2, value3] | ["~", "value1", "value2", "value3"] | [a, 1, 2] -->["~", ["$", "a"], 1, 2] |
一元表达式 UnaryExpression | operator value | ["operator", value] | !a -->["!", ["$", "a"]] |
二元表达式 BinaryExpression | value1 operator value1 | ["operator", value1, value2] | a+1 --> ["+", ["$", "a"], 1] |
属性表达式 MemberExpression | 1. value1[value2] 2. value1.value2 | [".", value1, value2] | a[1] --> [".", ["$", "a"], 1] |
逻辑表达式 LogicalExpression | value1 operator value1 | ["operator", value1, value2] | a || 1 --> ["||", ["$", "a"], 1] |
条件表达式 ConditionalExpression | condition? value1 : value2 | [":?", "$condition" value1, value2] | a?x:1 --> [":?", ["$", "a"], ["$", "x"], 1] |
调用表达式 CallExpression | fun(arg1, args2, ...) | ["()", ["$", "fun"], arg1, arg2, ...] | fun(a, 123) --> ["()", ["$", "fun"], ["$", "a"], 123] |
无前缀调用表达式 (可自定义,默认["$t", "$tc"]) | noPrefixFun(arg1) | ["()", "noPrefixFun", arg1, arg2, ...] | $t("abc") --> ["()", "$t", "abc"] |
模板字符串 | str-${js} | 相当于加法二元表达式 "str" + js | |
对象表达式 ObjectExpression | {key1: value1, key2: value2} | ["{}", {key1: value1, key2: value2} | {x:1, y:"2", z:a+b} -->['{}',{x: 1, y: '2', z: ['+', ['$', 'a'], ['$', 'b']]}] |
如果希望“函数调用的生成结果中,函数名去掉'$'
前缀”, 可使用
noPrefixFunctionList
参数.
import { templateValueToCardCode } from '@aiot-toolkit/card-expression';
// 默认有 '$' 前缀
const result = templateValueToCardCode(`{{myfun("hello", a)}}`);
console.log(result); // '['()', ['$', 'myfun'], 'hello', ['$', 'a']]'
// 去掉 'myfun' 的前缀
const result = templateValueToCardCode(`{{myfun("hello", a)}}`, {
noPrefixFunctionList: ['myfun'],
});
console.log(result); // '['()', 'myfun', 'hello', ['$', 'a']]'
默认值:['$t', '$tc']
如果期望“属性表达式的属性名合并到函数的第 1 个参数”,可使用
functionsForMemberNameToParam
参数
const code = `myfun("hello", a)[1]`;
// 普通函数 + 属性表达式
const result = jsToCardCode(code);
console.log(result); // "["[]",["()","myfun","hello",["$","a"]],1]"
// 属性名合并到函数的第 1 个参数
const result = jsToCardCode(item.source, {
functionsForMemberNameToParam: ['myfun'],
});
console.log(result); // "["()","myfun","hello.1",["$","a"]]"
默认值:['$t', '$tc']
jsToCardCode(code, { noPrefixFunctionList: [] });
templateValueToCardCode(code, { noPrefixFunctionList: [] });
参数名 | 类型 | 默认值 | 说明 |
---|---|---|---|
noPrefixFunctionList | string[] | ['$t', '$tc'] | 不需要添加 $ 前缀的函数名列表 |
functionsForMemberNameToParam | string[] | ['$t', '$tc'] | 属性表达式合并到函数的第 1 个参数的函数名列表 |
FAQs
The npm package @aiot-toolkit/card-expression receives a total of 3 weekly downloads. As such, @aiot-toolkit/card-expression popularity was classified as not popular.
We found that @aiot-toolkit/card-expression demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.