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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@trz/serialize

v0.4.5

Published

一个简单的字符串序列化操作工具

Readme

@trz/serialize

一个简单的JavaScript字符串序列化操作工具。

使用说明

导入

使用JavaScript的方式导入库方法:

const Serialize = require('@trz/serialize');
// do something yourself

使用 ES6 import 语法导入:

import Serialize from '@trz/serialize';
// do something yourself

API

  1. .get(name: strin): any

    • 获取序列指定键名的值,如果存在多个键值对,那么只会返回第一个(获取所有值,需要使用 Serialize.getAll())。

    • 演示代码:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
      console.log(serialize.get('a'))     // => 1
      console.log(serialize.get('b'))     // => 2
  2. .getAll(name: string): any[]

    • 获取序列指定键名的所有值。

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
      console.log(serialize.getAll('b'))  // => [2, "B"]
  3. .append(name: string, value: any): void

    • 添加一个指定的键/值对作为新的序列。

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
           
      serialize.append("x", "666");
      console.log(serialize.toString())  // => a=1&b=2&c=3&d=4&b=B&a=666
           
      serialize.append("a", "666");
      console.log(serialize.toString())  // => a=1&b=2&c=3&d=4&b=B&a=666
  4. .set(name: string, value: any): void

    • 将与给定序列键名相关的值设置为给定值。如果有多个值,则删除其他值。

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
           
      serialize.set("a", "666");
      console.log(serialize.toString())  // => a=666&b=2&c=3&d=4&b=B
           
      serialize.set("z", "777");
      console.log(serialize.toString())  // => a=666&b=2&c=3&d=4&b=B&z=777
  5. .delete(name1: string, ...): void

    • 从所有序列中删除给定的键及其相关值。

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
           
      serialize.delete("a", "b");
      console.log(serialize.toString())  // => c=3&d=4
  6. .has(name: string): boolean

    • 返回一个布尔值,表明是否存在这样的序列键名。

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
           
      console.log(serialize.has('a'))  // => true
      console.log(serialize.has('x'))  // => false
  7. .keys(): string[]

    • 返回序列中的键的列表。

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
      console.log(serialize.keys())  // => ["a", "b", "c", "d", "b"]
  8. .values(): any[]

    • 返回序列中的值的列表。

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
      console.log(serialize.values())  // => ["1", "2", "3", "4", "B"]
  9. .toString(): string

    • 返回一个包含序列字符串的字符串,适合在URL中使用。不包括问号。

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
           
      console.log('' + serialize.toString());    // => a=1&b=2&b=B&c=3&d=4
  10. .stringify(): string

    • 返回一个包含序列字符串的字符串,适合在URL中使用。不包括问号。

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
            
      console.log('' + serialize.stringify());    // => a=1&b=2&b=B&c=3&d=4
  11. .sort(): Serialize

    • 将序列的键按字母表的顺序进行排序

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('d=4&a=1&b=2&c=3&b=B');
      serialize.sort();
      console.log('' + serialize);    // => a=1&b=2&b=B&c=3&d=4
  12. .forEach(callback: (name: string, value: number, parent: Serialize) => void, thisArg?: any): void

    • 遍历所有的序列键值对

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');
      
      serialize.forEach((name, value) => {
        console.log('name:', name, 'value:', value);
      });
      /*
        name: a value: 1
        name: b value: 2
        name: c value: 3
        name: d value: 4
        name: b value: B
       */
  13. .entries(): IterableIterator<[string, any]

    • 迭代器

    • 代码演示:

      import Serialize from '@trz/serialize';
      const serialize = new Serialize('a=1&b=2&c=3&d=4&b=B');