【OpenHarmony】二维码的库:js-tokens

59 阅读2分钟

介绍

本库是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.

DD一下:欢迎大家关注工粽号<程序猿百晓生>,可以了解到以下知识点。

`欢迎大家关注工粽号<程序猿百晓生>,可以了解到以下知识点学习。`
1.OpenHarmony开发基础
2.OpenHarmony北向开发环境搭建
3.鸿蒙南向开发环境的搭建
4.鸿蒙生态应用开发白皮书V2.0 & V3.0
5.鸿蒙开发面试真题(含参考答案) 
6.TypeScript入门学习手册
7.OpenHarmony 经典面试题(含参考答案)
8.OpenHarmony设备开发入门【最新版】
9.沉浸式剖析OpenHarmony源代码
10.系统定制指南
11.【OpenHarmony】Uboot 驱动加载流程
12.OpenHarmony构建系统--GN与子系统、部件、模块详解
13.ohos开机init启动流程
14.鸿蒙版性能优化指南
.......

限制描述

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

软件架构

|-ets
|   |-Application
|           |-AbilityStage.ts
|   |-MainAbility
|           |-MainAbility.ts
|   |-pages
|           |-index.ets            #主页demo