【鸿蒙OH】二维码的库:js-tokens
本库是OpenHarmony系统下基于js-tokens库使用的开发示例,js-tokens 是一个微型JavaScript的分词器。小巧的、正则表达式驱动的、宽松的、几乎符合规范的 JavaScript 标记器。
📚往期推文全新看点(文中附带全新鸿蒙5.0全栈学习笔录)
🎯 鸿蒙(HarmonyOS)北向开发知识点记录~
🎯 鸿蒙(OpenHarmony)南向开发保姆级知识点汇总~
🎯 鸿蒙应用开发与鸿蒙系统开发哪个更有前景?
🎯 嵌入式开发适不适合做鸿蒙南向开发?看完这篇你就了解了~
🎯 对于大前端开发来说,转鸿蒙开发究竟是福还是祸?
🎯 鸿蒙岗位需求突增!移动端、PC端、IoT到底该怎么选?
🎯 记录一场鸿蒙开发岗位面试经历~
🎯 持续更新中……
介绍
本库是OpenHarmony系统下基于js-tokens库使用的开发示例,js-tokens 是一个微型JavaScript的分词器。小巧的、正则表达式驱动的、宽松的、几乎符合规范的 JavaScript 标记器
下载安装
1.如果已安装好nodejs后,输入以下命令
ohpm install js-tokens
2.在需要使用的页面导入js-tokens
import jsTokens from 'js-tokens'
var tokens = jsTokens.default
var matchToToken = jsTokens.matchToToken
使用说明
jsTokens
A regex with the g flag that matches JavaScript tokens.
The regex always matches, even invalid JavaScript and the empty string.
The next match is always directly after the previous.
var token = matchToToken(match)
import {matchToToken} from "js-tokens"
Takes a match returned by jsTokens.exec(string), and returns a {type: String, value: String} object. The following types are available:
- string
- comment
- regex
- number
- name
- punctuator
- whitespace
- invalid
Multi-line comments and strings also have a closed property indicating if the token was closed or not (see below).
Comments and strings both come in several flavors. To distinguish them, check if the token starts with //, /*, ', " or `.
Names are ECMAScript IdentifierNames, that is, including both identifiers and keywords. You may use [is-keyword-js] to tell them apart.
Whitespace includes both line terminators and other whitespace.
限制描述
1、Tokenizing JavaScript using regexes—in fact, one single regex—won’t be perfect. But that’s not the point either.
You may compare jsTokens with [esprima] by using esprima-compare.js. See npm run esprima-compare!
2、Template strings are matched as single tokens, from the starting to the ending , including interpolations (whose tokens are not matched individually).
Matching template string interpolations requires recursive balancing of { and }—something that JavaScript regexes cannot do. Only one level of nesting is supported.
3、Division and regex literals collision
Consider this example:
var g = 9.82
var number = bar / 2/g
var regex = / 2/g
接口说明
1、jsTokens.default; // 正在匹配表达式
2、jsTokens.matchToToken // 分词器 function
约束与限制
在下述版本验证通过: DevEco Studio: NEXT Beta1-5.0.3.806, SDK: API12 Release(5.0.0.66)
DevEco Studio: 4.0 Beta2(4.0.3.512), SDK: API10 (4.0.10.9)
DevEco Studio: 3.1.1 Release(3.1.0.501), SDK: API9 Release(3.2.12.5)
软件架构
|-ets
| |-Application
| |-AbilityStage.ts
| |-MainAbility
| |-MainAbility.ts
| |-pages
| |-index.ets #主页demo
更多推荐

所有评论(0)