
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@mpxjs/template-engine
Advanced tools
小程序运行时渲染基础模板生成引擎。
Fork from @tarojs/shared for generating template.
npm install @mpxjs/template-engine
# or
yarn add @mpxjs/template-engine
# or
pnpm add @mpxjs/template-engine
const { createTemplateEngine } = require('@mpxjs/template-engine')
const templateEngine = createTemplateEngine('wx') // 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'dd' | 'web' | 'tenon'
const templateCode = templateEngine.buildTemplate({
baseComponents: ['view', 'button'] // 需要使用的小程序基础组件
})
将会输出
<template name="mpx_tmpl">
<element r="{{r}}" wx:if="{{r}}" />
</template>
<template name="t_0_view">
<view data-mpxuid="{{i.d.uid}}">
<block wx:for="{{i.c}}" wx:key="index">
<template is="t_1_container" data="{{i:item}}" />
</block>
</view>
</template>
<template name="t_0_button">
<button data-mpxuid="{{i.d.uid}}">
<block wx:for="{{i.c}}" wx:key="index">
<template is="t_1_container" data="{{i:item}}" />
</block>
</button>
</template>
<template name="t_0_#text" data="{{i:i}}">
<block>{{i.ct}}</block>
</template>
<template name="t_0_container">
<template is="t_0_{{i.nt}}" data="{{i:i}}" />
</template>
<template name="t_1_container">
<block wx:if="{{i.nt === '#text'}}">
<template is="t_0_#text" data="{{i:i}}" />
</block>
<block wx:else>
<element r="{{i}}" />
</block>
</template>
const fs = require('fs')
fs.writeFile('base.wxml', code)
<import src="base.wxml" />
<template is="t_0_container" data="{{ i: r }}" />
Component({
data: {
r: {
// 描述节点的vnode
nt: 'view', // 节点类型
d: {
class: "view-class" // 节点属性值
},
c: [ // 子节点
{
nt: 'button',
d: {},
c: [
{
nt: '#text',
ct: '运行时渲染'
}
]
}
]
}
}
})
除了基础组件外,模板引擎还支持自定义组件的渲染
const templateCode = templateEngine.buildTemplate({
normalComponents: [ 'custom-dialog' , 'custom-popup'], // 需要使用的自定义组件
})
如果需要自定义某个模板组件的属性,例如生成的组件需要一个class
属性。可以通过传入对象配置。
const templateCode = templateEngine.buildTemplate({
baseComponents: [
{
view: ['class']
}
] // 需要使用的小程序基础组件
})
如果想自定义class
从data
的取值。
const templateCode = templateEngine.buildTemplate({
baseComponents: [
{
view: {
class: 'c'
}
}
] // 需要使用的小程序基础组件
})
FAQs
template-engine for mpx runtime render
The npm package @mpxjs/template-engine receives a total of 192 weekly downloads. As such, @mpxjs/template-engine popularity was classified as not popular.
We found that @mpxjs/template-engine demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.