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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ckj-cli-dev/core

v0.1.5

Published

测试

Readme

核心库

引入的各种包的作用记录 来源

import-local

顾名思义,导入本地包。其作用是避免全局npm包和本地项目中的包产生冲突的。

假如一个名为cobber的脚手架的入口文件有如下代码:

#! /usr/bin/env node

const importLocal = require('import-local');

if (importLocal(__filename)) { 
    console.log('Using local version of this package');
} else { 
    require("../lib")(process.argv.slice(2))
}

当你全局安装cobber后,又在本地项目中安装了cobber,当你使用脚手架提供的命令进行相关项目创建的时候,使用的是你本地项目中的脚手架,不会使用全局的脚手架。(当然,本地项目中没有安装cobber脚手架的时候,则会使用全局安装的那个cobber脚手架)

许多基于node开发的工具库中都有import-local的影子, 比如lerna,webpack-cli等。

npmlog

npmlog用于输出node.js应用的日志信息,其作用相当于console.log,但功能更加强大。

var log = require('npmlog');
log.level = 'verbose';
log.silly('cobber', 'level is silly');
log.verbose('cobber', 'level is verbose');
log.info('cobber', 'level is info');
log.timing('cobber', 'level is timing');
log.http('cobber', 'level is http');
log.notice('cobber', 'level is notice');
log.warn('cobber', 'level is warn');
log.error('cobber', 'level is error');
log.silent('cobber', 'level is silent');

使用npmlog可以很方便的输出样式丰富的调试信息,是node应用开发不可或缺的利器。

colors

在开发Node应用的时候,使用传统的console.log突出不了你想要表达的重点,可以使用colors库,来给你的输出信息一点颜色瞧瞧。

const colors = require('colors/safe');

console.log(colors.red('这是一段红色的文字'))

semver

有时候我们需要比较版本号,执行一些逻辑操作,比如某个脚手架限制用户必须安装xxx以上的版本号的Node.js才能使用该脚手架。版本号有多种形式,如果开发者自己去定义一些算法去比较,这个代价还是较大的。 使用semver可以很方便实现版本号的比较,其内置了多种比较方式,日常开发中使用它完全够用了。

const semver = require('semver')
semver.valid('1.2.3') // '1.2.3'
semver.valid('a.b.c') // null
semver.clean('  =v1.2.3   ') // '1.2.3'
semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
semver.gt('1.2.3', '9.8.7') // false
semver.lt('1.2.3', '9.8.7') // true
semver.minVersion('>=1.0.0') // '1.0.0'
semver.valid(semver.coerce('v2')) // '2.0.0'
semver.valid(semver.coerce('42.6.7.9.3-alpha')) // '42.6.7'

root-check

通过Node.js的API,我们可以很方便的进行文件I/O操作,如果进行相关操作的时候使用的是root账号,那么会带来很多权限问题。root-check会判断出当前系统登录账号是否是root账号,如果是,会自动帮我们降级,避免后续的权限问题。

import rootCheck from 'root-check';
rootCheck();

user-home

user-home用于获取用户主目录。

const userHome = require('user-home');
console.log(userHome);

其实在Node的内置模块os,已经提供了用户主目录的获取。

const userHome = require("os").homedir();
console.log(userHome);

path-exists

要判断指定路径的文件路径或者文件目录是否存在,可以使用path-exists。

import {pathExists} from 'path-exists';
console.log(await pathExists('foo.js'));

dotenv

除了手动process.env.xxx=xxx的方式设置环境变量,还可以使用dotenv一次性的设置多个环境变量。

require('dotenv').config({ path: '/custom/path/to/.env' })

其中.env中的内容格式如下(内容可以自己随便定义):

DB_HOST=localhost
DB_USER=root
DB_PASS=s1mpl3

url-join

url-join可以快速的帮我们拼接出常见格式的url地址。

var urljoin = require('url-join');
var fullUrl = urljoin('http://www.google.com', 'a', '/b/cd', '?foo=123');
console.log(fullUrl);

minimist

minimist用于解析命令行参数。

var argv = require('minimist')(process.argv.slice(2));
console.log(argv);

$ node example/parse.js -a beep -b boop
{ _: [], a: 'beep', b: 'boop' }