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

typejs6

v0.3.2

Published

一个简单的类型判断工具

Downloads

19

Readme

typejs6

js 数据类型检查支持自定义类。

version

  • 0.3.0

    • 同时支持 es、cjs
    • isFalse 支持对无字符 string 判断
    • isEmpty 支持空对象判断。注意:不支持 DOM , 0=fasle
  • 0.3.1

    • fix: isEmpty 对于 null 判断异常
  • 0.3.1

    • fix: 补包

Installation

npm install typejs6

API

type.configWarn

代码压缩混淆会串改 class 名称。typejs6 会检查类型安全,并输出warn提示。

您可以使用typeTag修复漏洞,如果你确认安全可全局忽略该警告。

type.configWarn = false; //关闭提示

type

type(value) >String

import { type, typeTag } from "typejs6";

// js内置对象 & 自定义对象
type("foo"); // "String"
type([1, 2]); // "Array"
type(3); // "Number"
type(true); // "Boolean"
type(undefined); // "Undefined"
type(null); // "Null"
type(new Map()); // "Map "
type(function* () {}); // "GeneratorFunction "
type(Promise.resolve()); // "Promise "
type(Math); // "Math "
type(new Set()); // "Set "
type(new WeakMap()); // "WeakMap "
type(new WeakSet()); // "WeakSet "
type(Symbol()); // "Symbol "
...

type.is...

type.is{Type}(value) > Boolean

import { type, typeTag } from "typejs6";

// 扩展
type.isInteger(100.1); // false
type.isNaN(NaN); //  true
type.isFalse(" "|0|NaN|null|undefined|false); //  true
type.isEmpty({}|[]|set|map|isFalse()); // true; 注意:0=fasle,不支持DOM

// js内置对象 & 自定义对象
type.isString("foo"); // true
type.isArray([1, 2]); // true
type.isNumber(3); // true
type.isBoolean(true); // true
type.isUndefined(undefined); // true
type.isNull(null); // true
type.isMap(new Map()); // true
type.isGeneratorFunction(function* () {}); // true
type.isPromise(Promise.resolve()); // true
type.isMath(Math); // true
type.isSet(new Set()); // true
type.isWeakMap(new WeakMap()); // true
type.isWeakSet(new WeakSet()); // true
type.isSymbol(Symbol()); // true
type.isArrayBuffer(new ArrayBuffer(32)); // true
type.isDataView(new DataView(new ArrayBuffer(32))); // true
...

typeTag

使用 typeTag 标记类型,保证混淆代码下的类型安全

import { type, typeTag } from "typejs6";

function MyClass() {}
typeTag(MyClass, "MyClass");

let a = new MyClass();

type(a); // MyClass
type.isMyClass(a); // true

也可以手动添加 get [Symbol.toStringTag](){} 和 typeTag 效果一样。

class MyClass {
  get [Symbol.toStringTag]() {
    return "MyClass";
  }
}