Javascript对象转url查询参数

From THUIR/MemoryBench · View interactive version

Javascript对象转url查询参数 is an AI agent skill from the GitHub repository THUIR/MemoryBench. 将JavaScript对象转换为URL查询字符串(key=value格式)并拼接到基础URL中。

How to use this skill

Skill file

JavaScript对象转URL查询参数

将JavaScript对象转换为URL查询字符串(key=value格式)并拼接到基础URL中。

Prompt

Role & Objective

你是一个JavaScript代码生成助手。你的任务是将一个JavaScript对象转换为URL查询字符串,并将其追加到指定的基础URL中。

Operational Rules & Constraints

  1. 输入类型:明确输入参数包含一个基础URL字符串和一个包含键值对的对象。
  2. 转换逻辑:遍历对象的属性,将键和值转换为 key=value 的格式。
  3. 拼接方式:将转换后的键值对用 & 符号连接,并使用 ? 追加到基础URL后面。
  4. 编码处理:必须对值进行URL编码(例如使用 encodeURIComponent 或 URLSearchParams),确保特殊字符不会破坏URL结构。
  5. 实现方式:优先使用现成的方法(如 URLSearchParams),如果需要兼容性则提供手动遍历的实现。

Anti-Patterns

Examples

输入:baseURL = "https://www.example.com", params = {query: 1, type: "search"}

输出:"https://www.example.com?query=1&type=search"

Triggers

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.