@abetomo/mask-value 中文文档教程

发布于 3年前 浏览 25 项目主页 更新于 3年前

node-mask-value

npm 版本Test

屏蔽对象的值。

Install

% npm i @abetomo/mask-value

Examples

import { mask, masks, Config } from '@abetomo/mask-value'

type User = {
  name: string
  address: string
}

const data: User[] = [
  {
    name: 'name1',
    address: 'address1'
  },
  {
    name: 'name2',
    address: 'address2'
  }
]

const config: Config = {
  path: '.[].name',
  action: () => Math.random()
}

console.log(mask<User[]>(data, config))
/*
Output:
[
  { name: 0.913236932864554, address: 'address1' },
  { name: 0.6970620876451457, address: 'address2' }
]
*/


const configs: Config[] = [
  {
    path: '.[].name',
    action: () => Math.random()
  },
  {
    path: '.[].address',
    action: (s: string) => s.length * Math.random()
  }
]

console.log(masks<User[]>(data, configs))
/*
Output:
[
  { name: 0.4253394097546368, address: 4.285149904757429 },
  { name: 0.7394228798993354, address: 6.334446902953465 }
]
*/

node-mask-value

npm versionTest

Mask the value of the object.

Install

% npm i @abetomo/mask-value

Examples

import { mask, masks, Config } from '@abetomo/mask-value'

type User = {
  name: string
  address: string
}

const data: User[] = [
  {
    name: 'name1',
    address: 'address1'
  },
  {
    name: 'name2',
    address: 'address2'
  }
]

const config: Config = {
  path: '.[].name',
  action: () => Math.random()
}

console.log(mask<User[]>(data, config))
/*
Output:
[
  { name: 0.913236932864554, address: 'address1' },
  { name: 0.6970620876451457, address: 'address2' }
]
*/


const configs: Config[] = [
  {
    path: '.[].name',
    action: () => Math.random()
  },
  {
    path: '.[].address',
    action: (s: string) => s.length * Math.random()
  }
]

console.log(masks<User[]>(data, configs))
/*
Output:
[
  { name: 0.4253394097546368, address: 4.285149904757429 },
  { name: 0.7394228798993354, address: 6.334446902953465 }
]
*/
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文