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 🙏

© 2024 – Pkg Stats / Ryan Hefner

imitate-symbol

v1.1.7

Published

模拟 Symbol 的功能

Downloads

11

Readme

NPM version NPM Weekly Downloads License

imitate-symbol

简单的模拟 Symbol 的功能,与 Symbol 的逻辑比较类似,但是 imitate-symbol 返回的是一个随机的唯一 uuid。

实例

import iSymbol from "imitate-symbol";

var val = iSymbol("val");
console.log(val); // 8039bc24-52f0c187-1fd1-4695-99a1-3f0657e61642
console.log(iSymbol.for("val")); // 8039bc24-52f0c187-1fd1-4695-99a1-3f0657e61642
console.log(iSymbol.keyFor(val)); // val

API

iSymbol(name?);

生成一个 uuid

var val = iSymbol("val");

name

Type: String

一个标识 uuid 的名字,可以不输入

iSymbol.for(name);

查找标识为 name 的 uuid,如果没有就返回一个新生成的 uuid,并将其标识为 name

iSymbol.for("val");

name

Type: String

一个标识 uuid 的名字,必须输入

iSymbol.keyFor(val);

查找 uuid 的标识名,如果没有就返回空字符串

iSymbol.keyFor(val);

val

Type: String

uuid 的值,必须输入

iSymbol.is(val);

判断 uuid 是否由 iSymbol 生成

iSymbol.is(val);

val

Type: String

uuid 的值,必须输入

iSymbol.setVal(obj, key, value);

将对象 obj 的 key 属性的值设置为 value, 和原生 Symbol 属性一样, key 属性不可以枚举,但可以删除和重新赋值

iSymbol.setVal({}, "val", "some value");

obj

Type: Object

要设置值的对象

key

Type: String

要设置的属性名

value

Type: any

要设置的属性值

例子

var obj = {
    key: "key value",
};
iSymbol.setVal(obj, "val", "val value");
console.log(obj[iSymbol.for("val")]); // val value
console.log(JSON.stringify(obj)); // {"key":"key value"}