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

mod-info

v1.0.2

Published

Get the latest version update prompt of the node module (npm).

Downloads

3,154

Readme

mod-info

Get the latest version update prompt of the node module (npm).

获取 node 模块最新版本更新提示

npm install size node-current (tag) GitHub license

使用

$ npm i mod-info --save

import mi from 'mod-info';

/*
@params module name <string>
@params module current version <string>
@params? config <IConfig> 详见类型定义

@return info <IResult> 详见类型定义
*/
const info = await mi('test-mode-info', '1.1.4');
/*
{
  update: true,     // 是否存在更新的版本
  version: '1.2.4'  // 更新的版本号
  tips: [           // 一些更新内容提示
    '一些更新内容提示'
  ]
}
*/

类型定义

IConfig

type ILevelConfig = 'major' | 'minor' | 'patch';
interface IConfig {
  // 配置更新提示等级
  // 配置为 major 时只有发布更高 major 版本了才认为更新
  // 配置为 minor 时只有发布了相同 major 版本,且 minor 版本更高才认为更新
  // 配置为 patch 时只有发布了相同 major 和 minor 版本,且 patch 版本更高才认为更新
  // 默认值为 ['major', 'minor', 'patch']
  level?: ILevelConfig[];

  // 检测更新间隔,单位为 毫秒,默认为 24 * 60 * 60 * 1000,即一天内只检测一次
  timeout?: number;

  // 是否忽略非正式版本的更新,例如 1.2-beta.3 这种 beta 版本,默认为 true
  ignoreInformalVersion?: boolean;
}

IResult

interface IResult {
  // 是否存在(当前检测规则 level 下的)最新版本
  update: boolean;

  // 如果存在最新版本,它的版本号是
  version: string;
  
  // 当前版本匹配到的 更新提示信息 列表
  tips: string[];
}

更新提示信息配置

在模块的 package.json 中通过 module-info-tips 可以配置 更新提示信息,使用 mod-info 检测版本时会获取到这些提示信息。

更新提示信息可以通过 matchignore 两个字段来匹配或忽略在某些版本下提示,同时支持使用 *x 来匹配任意版本,例如:

{
  "name": "test-mode-info",
  "version": "1.2.4",
  "module-info-tips": [
    {
      "match": "0",
      "ignore": "0.1.*",
      "tip": "0.x tip"
    },
    {
      "match": ["1.2", "1.3"],
      "ignore": ["1.2.3"],
      "tip": "1.x tip"
    },
    {
      "match": "*",
      "ignore": "*.1",
      "tip": "x tip"
    }
  ]
}

MIT LICENSE