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

@jovercao/config-loader

v0.1.6

Published

该工具用于自动加载不同级别的配置文件,并将其合并成运行所需的配置文件。

Downloads

4

Readme

配置加载器

该工具用于自动加载不同级别的配置文件,并将其合并成运行所需的配置文件。

配置文件

配置文件均采用JSON的格式,配置共有以下四个:

  • default,默认配置,通过对象传递
  • appfile, 放在应用程序所在目录的配置文件,加载器会自动查找,存放在可执行文件目录(如果通过pkg打包),或者项目源码主目录
  • userfile, 放在用户主目录的配置文件
  • cwdfile, 放在工作目录配置文件

加载配置覆盖优先级: cwdfile > userfile > appfile

使用方式

安装:

npm install @jovercao/config-loader

调用:

import load from '@jovercao/config-loader'

const defaultConfig = {
  settings1: '这是设置1',
  settings2: '这是设置2'
}

const variants = {
  var1: '这是变量1的值',
  var2: '这是变量2的值'
}

let config
if (process.env.NODE_ENV === 'developement') {
  config = load({
    default: defaultConfig,
    variants,
    appfile: 'app.config.dev.json',
    pwdfile: '.appname.config.dev.json',
    userfile: '.appname.config.dev.json'
  })
} else {
  config = load({
    default: defaultConfig,
    variants,
    appfile: 'app.config.json',
    pwdfile: '.appname.config.json',
    userfile: '.appname.config.json'
  })
}

查看范例

api

load(options, defaultConfig)

加载配置文件中的配置

options

选项

options.default

默认配置,通过对象传递,而非路径

options.variants

object 类型,存放变量的对象,加载器将用该对象中的属性varName替换值为字符串的配置项中格式为${varName}的内容。

options.appfile

string 类型,指定应用程序配置文件的文件名,默认文件名为app.config.json

options.userfile

string 类型,指定用户配置文件的文件名,不指定时将不加载用户配置文件

options.cwdfile

string 类型,指定工作路径配置文件的文件名,不指定时将不加载,不指定时将不加载工作路径配置文件

defaultConfig

object 类型,默认参数,可空,同options.default

版本历史

  • 0.1.6
    • 解决当有项为null或undefined时,环境变量替换时报错问题