New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aiot-toolkit/card-expression

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aiot-toolkit/card-expression

快应用卡片表达式解析库

  • 1.0.6
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
0
Weekly downloads
 
Created
Source

快应用卡片表达式解析

用于

  1. JS表达式 转换为 快应用卡片表达式
  2. 模板表达式 转换为 快应用卡片表达式

快应用卡片表达式是一种类似 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"]]]

快速上手

模板代码转换为 Card 代码

import { templateValueToCardCode } from '@aiot-toolkit/card-expression';

const result = templateValueToCardCode('a+b{{a+b}}');
console.log(result); // ["+","a+b",["+",["$","a"],["$","b"]]]

js 代码转为 Card 代码

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 表达式

快应用卡片支持的js 表达式如下。需要注意的是,各表达式之间可递归使用,例 如 data[a+b] data.x + (a?1:2)

表达式源码产物示例
字面量
literal
valuevalue123 --> 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]
模板字符串str-${js}相当于加法二元表达式 "str" + js

FAQs

Package last updated on 29 Sep 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc