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

huafua-configparser

v1.0.3

Published

A configparser based on nodejs

Downloads

7

Readme

基于node的configparser

有时候想在项目中以app.conf的形式引入我们的配置,但是里头的都是字符窜,想要单独处理下又觉得浪费时间,这时候本模块就起作用了。

配置文件为如下格式:

[section]
optionName=optionValue
optionName1=optionValue1

1. 几个Api

该模块向外提供了ConfigOptionConfigSectionConfigParser类:

支持config.section.option的形式获取配置项的值

ConfigParser提供的Api:

  • addSection(section:ConfigSection):添加节点
  • addSections(sections:Array<ConfigSection>):批量添加节点
  • addOption(sectionName:string,option:ConfigOption):添加配置项
  • addOptions(sectionName:string,options:Array<ConfigOption>):批量添加配置项
  • readAsync(configpath:string):异步形式读取配置文件,配置文件路径必须为绝对路径
  • read(configpath:string):同步形式读取配置文件,配置文件路径必须为绝对路径
  • get(sectionName?:string,optionName?:string):获取指定节点或配置项的值,当没有给定参数则直接返回该配置的json数据
  • getInt(sectionName:string,optionName:string):获取指定配置项的int
  • getString(sectionName:string,optionName:string):获取指定配置项的string
  • getJson(sectionName?:string):获取指定节点的json对象,若没有指定参数则获取当前配置的json对象
  • set(sectionName:string,optionName:string,optionValue:string|number):设置指定节点的配置项
  • save(distPath:string):保存当前配置到指定文件,文件路径须为绝对路径
  • saveAsJson(distPath?:string):保存当前配置json数据到指定文件,文件路径须为绝对路径
  • clear():清空配置
  • remove(sectionName:string,optionName?:string):删除指定节点或配置项

ConfigSection提供的Api

  • ConfigSection(sectionName:string):构造方法,传递节点名称实例化对象
  • init(options:Array<ConfigOption>):通过配置项数组初始化配置节点
  • addOption(option:ConfigOption):添加配置项
  • addOptions(options:Array<ConfigOption>):批量添加配置项
  • get(optionName:string):获取当前节点指定配置项的值
  • getInt(optionName:string):获取当前节点指定的配置项int
  • getString(optionName:string):获取当前节点指定配置项的string
  • getJson():获取配置节点的json数据
  • set(optionName:string,optionValue:string|number):该节点设置一个配置项
  • remove(optionName:string):删除指定配置项

2. 使用

  1. 导入
    var ConfigParser=require("huafua-configparser");
  2. 实例化
    var config=new ConfigParser();
  3. 指定配置文件
    config.read(path.resolve(__dirname,"app.conf"));
  4. 使用Api