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

fallback-version

v0.1.2

Published

[![Build Status](https://travis-ci.org/sleagon/fallback-version.svg?branch=master)](https://travis-ci.org/sleagon/fallback-version)

Downloads

8

Readme

Version Fallback

Build Status

英文版

匹配最适合的版本号

我们有时候会有需求去根据现在的版本集合选择合适的版本去干某件任务。比如,我们有三个版本的Chrome浏览器,40、50、60版本,这时候我们接到一个任务:需要在不高于52的Chrome版本上跑一些脚本。这时候我们就可以用这个包来进行匹配了。这个包就是被设计来解决类似的场景下的问题的。

用法

npm install fallback-version --save
# or
yarn add fallback-version

简单用法

const { Version } = require('fallback-version');
const V = new Version();
V.loadVersionSet(new Set(['Chrome/10', 'Chrome/50', 'Chrome/60', 'Chrome/65']));
const test = 'Chrome/62';
const result = V.match(test); // result [ 'Chrome', 60]

没匹配到合适的版本

const { Version } = require('fallback-version');
const V = new Version();
V.loadVersionSet(new Set(['Chrome/10', 'Chrome/50', 'Chrome/60', 'Chrome/65']));
const test = 'Safari/62';
const result = V.match(test); // result [ 'Unknown', 60]

复杂场景

const { Version } = require('fallback-version');
const V = new Version();
V.loadVersionSet(
  new Set([
    "Jimmy's favorite browser is Chrome and version 40 is the best.",
    "Tom's favorite browser is Chrome and version 55 is the best.",
    "John's favorite browser is Safari and version 11 is the best.",
    "Cate's favorite browser is Edge and version 15 is the best.",
  ]),
  /\w+\'s favorite browser is (\w+) and version (\d+) is the best./
);
const test = "Shanyy's favorite browser is Safari and version 13 is the best.";
const result = V.match(test); // ['Safari', 11]

带参初始化

const { Version } = require('fallback-version');
const V = new Version('Fake', new Set(['Chrome/10', 'Chrome/50', 'Chrome/60', 'Chrome/65']), /(\w+)\/(\d+)/);
const test = 'Chrome/9';
const result = V.match(test); // ['Fake', 0]

更多用法可以看测试用例或者直接看源码。

License

MIT. See LICENSE for details.