
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
纯 js 迷你表单核心,包含值管理与简单的错误校验,基于 Proxy 实现表单关联功能
npm install formini --save
# or
yarn add formini
import createForm from 'formini'
const form = createForm({
fields: [
{
name: 'key1',
defaultValue: 1,
rules: [
(value) => (typeof value === 'undefined' ? 'key1 必填' : undefined),
],
},
{ name: 'key2', defaultValue: 2 },
{
name: 'key3',
rules: [
(value) => (typeof value === 'undefined' ? 'key3 必填' : undefined),
],
},
],
// 关联参数,基于 Proxy 响应式数据自动收集依赖,定向更新
relatives: {
hasKey1: (values) => typeof values.key1 !== 'undefined',
hasKey2: (values) => 'key2' in values,
hasKey5: (values) => 'key5' in values,
hasError: (values, errors) => Object.values(errors).some(Boolean),
// 可用作表单项关联控制
showField2: (values) => values.key1 === 'magic'
},
})
// 写值与校验
form.setValue({
key1: undefined
})
await form.validate()
form.getErrors() // { key1: 'key1 必填', key2: undefined, key3: 'key3 必填' }
form.reset() // 重置
// 定向写值与校验
form.setValue('key1', undefined)
await form.validate('key1')
form.getError('key1') // key1 必填
const stop0 = form.watch(() => { // 监听 form 的所有变化,包括 values、errors、relatives
console.log('form 发生了变化')
})
const stop1 = form.watchValues((values) => { // 监听全部 values
console.log(values)
})
const stop2 = form.watchValue('key1', (value) => { // 监听指定 value
console.log(value)
})
const stop3 = form.watchErrors((errors) => { // 监听全部 errors
console.log(errors)
})
const stop4 = form.watchError('key1', (error) => { // 监听指定 error
console.log(error)
})
const stop5 = form.watchRelatives((relatives) => { // 监听全部 relatives(关联)
console.log(relatives)
})
const stop6 = form.watchRelative('hasKey1', (relative) => { // 监听指定 relative(关联)
console.log(relative)
})
FAQs
mini form core with vanilla js
We found that formini demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.