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

@naturefw/nf-tool

v0.1.0

Published

JavaScript 的小工具,验证 JavaScript 的数据类型,输出调试信息等。

Downloads

4

Readme

nf-typeof-验证 JavaScript 的类型

源码目录:https://naturefw.gitee.io/

介绍

使用 Object.prototype.toString.call(val) 验证 JavaScript 的各种数据类型。
封装一下 console.log,console.time、console.timeEnd

虽然采用了 Typescript,但是基本上是 anyscript。

目录结构

  • lib 源码
  • src 使用demo
  • distp 在线演示的代码

安装教程

  1. npm i @naturefw/nf-tool 或者
  2. yarn add @naturefw/nf-tool

CDN 的使用方法

引入

  <script src="https://unpkg.com/@naturefw/nf-tool"></script>

然后

nfTool.isPromise(()=>{})

这样就可以访问到了。

使用说明


import tool from '@naturefw/nf-tool'

const {
  log, // 打印调试信息
  logTime, // 计时
  toTypeString, // Object.prototype.toString.call(val)
  typeName, // 获取可以识别的名称

  hasOwnProperty,
  hasOwn,

  isFunction, // 验证普通函数
  isAsync, // 验证 async 的函数
  isPromise, // 验证 Promise
  isObject, // 验证 Object
  isArray, // 验证数组
  isString, // 验证字符串
  isNumber, // 验证 number
  isBigInt, // 验证 BigInt
  isBoolean, // 验证 布尔
  isRegExp, // 验证正则类型
  isDate, // 验证日期
  isMap, // 验证 map
  isSet, // 验证 set
  isSymbol, // 验证 Symbol
 
  isNullOrUndefined // null 或者 undefined 返回 true
} = tool

async function testAsyncFun(params) {
  
}

function myPromise(params) {
  return new Promise((f1, f2) => {
    f1()
  })
}

window.__showlog = 2 // 设置后才会打印调试信息

// 开始测试
const start = () => {

  log(' ============ 验证数据类型 ============')

  let t = logTime('验证 Function 用时')
  log('\n() => {}:', isFunction(() => {}))
  t.end()

  t = logTime('验证 Async 用时')
  log('\nasync () => {}:', isAsync(async () => {}))
  log('async function () {}:', isAsync(testAsyncFun))
  t.end()
  
  t = logTime('验证 isPromise 用时')
  log('\nPromise:', isPromise(myPromise))
  log('Promise:', isPromise(myPromise()))
  t.end()

  t = logTime('验证 Object 用时')
  log('\n对象:', isObject({}))
  t.end()

  t = logTime('验证 Array 用时:')
  log('\n数组:', isArray([]))
  t.end()

  t = logTime('验证 isString 用时:')
  log('\n‘123’:', isString('123'))
  t.end()

  t = logTime('验证 isNumber 用时:')
  log('\n123:', isNumber(123))
  t.end()
  
  t = logTime('验证 isBigInt 用时:')
  log('\n123:', isBigInt(123))
  t.end()
  
  t = logTime('验证 isBoolean 用时:')
  log('\ntrue:', isBoolean(true))
  t.end()
  
  t = logTime('验证 isRegExp 用时:')
  log('\nRegExp:', isRegExp(new RegExp(/123/g)))
  t.end()
  
  t = logTime('验证 isDate 用时:')
  log('\nDate:', isDate(new Date()))
  t.end()
  
  t = logTime('验证 isMap 用时:')
  log('\nMap:', isMap(new Map()))
  t.end()
  
  t = logTime('验证 isSet 用时:')
  log('\nSet:', isSet(new Set()))
  t.end()
  

  t = logTime('验证 isPromise 用时:')
  // log('\nPromise:', isPromise(() => {return new Promise(()=>{},()=>{}))})
  t.end()

  t = logTime('验证 isSymbol 用时:')
  log('\nSymbol(‘123’):', isSymbol(Symbol('123')))
  t.end()
  
  var un
  t = logTime('验证 isNullOrUndefined 用时:')
  log('\nnull:', isNullOrUndefined(null))
  log('未定义:', isNullOrUndefined(un))
  log('字符串:', isNullOrUndefined('qwe'))
  t.end()
  
  const arr = [
    '字符串',
    123,
    ['数组', 123],
    new Date(),
    new Date().valueOf(),
    new Map(),
    new Set()
  ]

  t = logTime('typeName 用时:')
  log('\n typeName 的测试')
  arr.forEach(element => {
    log(typeName(element), ':', element.toString())
  })
  t.end()

源码

自然框架源码/nf-tool- JavaScript 常用函数库

在线演示

https://naturefw-code.gitee.io/nf-rollup-tool

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

特技

  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/