npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@yuliqi/node-red-contrib-qmapping

v0.0.2

Published

Node-RED 节点,用于字段映射和数据转换,支持数组/对象映射、函数处理、默认值、动态 key 等

Downloads

6

Readme

用于字段映射和数据转换,支持数组/对象映射、函数处理、默认值、动态 key 等。

安装

npm install @yuliqi/node-red-contrib-qmapping

🧩 mapping 配置说明文档

🎯 作用

用于把原始数据转换为目标结构,支持字段提取、函数处理、默认值、数组/对象映射、忽略特定值等。


🧱 基本写法

const mapping = {
  key1: 'a.b.c',                    // 等价于 { path: 'a.b.c' }
  key2: {
    path: 'x.y',
    func: 'v => v.trim()',
    default: '未知',
    omitValues: [null, ''],
    fallbackToPathString: true
  }
}

🔁 数组映射

const mapping = {
  list: {
    path: 'data.items[]',
    mapping: {
      id: 'id',
      name: {
        path: 'info.name',
        func: 'v => v.toUpperCase()'
      }
    }
  }
}

🔗 对象嵌套映射

const mapping = {
  user: {
    path: 'userInfo',
    mapping: {
      name: 'name',
      age: {
        path: 'details.age',
        default: 0
      }
    }
  }
}

💡 特殊写法:_ 占位符

用于动态 key 的场景,例如字段名未知,但值结构确定:

const mapping = {
  "_": {
    path: "userList",
    mapping: {
      _: {
        path: "*",  // 表示遍历对象的每个 key
        mapping: {
          name: "name",
          age: "age"
        }
      }
    }
  }
}

也支持单个对象中仅保留特定字段:

const mapping = {
  "_": {
    ke: "value"
  }
}
// 等价于从整个对象中提取 key 为 "ke",值为 "value"

⚙️ 配置字段说明

| 字段名 | 类型 | 说明 | | ---------------------- | ------------ | -------------------------------- | | path | string | 数据路径,如 a.b.c,数组用 path[] 表示 | | func | string 或数组 | 对取到的值进行处理,支持 async | | default | any | 当取值为空时,使用默认值 | | omitValues | any[] | 如果值等于这些内容,将被忽略 | | fallbackToPathString | boolean | 如果找不到 path,用 path 自身作为值(可用于常量注入) | | "_" | object | 特殊字段,用于动态 key 或保留 key-value 结构 |


🧪 输入输出示例

输入:

{
  "data": {
    "users": {
      "u1": { "name": "Tom" },
      "u2": { "name": "Jerry" }
    }
  }
}

mapping:

{
  users: {
    path: 'data.users',
    mapping: {
      _: {
        path: '*',
        mapping: {
          name: 'name'
        }
      }
    }
  }
}

输出:

{
  "users": {
    "u1": { "name": "Tom" },
    "u2": { "name": "Jerry" }
  }
}