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

prefix-json

v1.0.6

Published

除了JSON本身的特性之外,还支持这样的一些特性: * 允许为json字符串增加前缀,例如: 可以使用`D"../static"`来表示目录(*前缀可以自定义*)。 * 支持注释,支持“//”注释。 * Object类型或Array类型的最后一个元素允许以“`,`”结束。 * json中键不用加引号

Downloads

4

Readme

带前缀的JSON

除了JSON本身的特性之外,还支持这样的一些特性:

  • 允许为json字符串增加前缀,例如: 可以使用D"../static"来表示目录(前缀可以自定义)。
  • 支持注释,支持“//”注释。
  • Object类型或Array类型的最后一个元素允许以“,”结束。
  • json中键不用加引号

配置实例

// 服务器配置
{
    // 服务器监听的端口
    listen: 3000,
    // 视图目录
    viewDir: D"../views",
    // 静态资源目录
    staticDir: D"../static",
    // 缓存目录
    tempDir: D:"../tmp",
    //数据库配置
    database: {
        //... ...
    }
}

安装

npm install --save prefix-json

使用

使用方法很简单,请看下面的例子。

import * as parser from 'prefix-json'
const config = parser.parse(path_of_config_file, {
    //当遇到D前缀时,会使用这里的函数进行转换
    D: ({file, val}) => path.resolve(path.dirname(file), val)
})
console.log(config)

使用AST

如果默认的parse函数不能满足需求,也可以自己对AST进行处理。

使用parseAst函数可以将给定的内容解析为抽象语法树。

自定义错误

可以导入系统现有的文件进行设置,也可以自行设置。

  • 如果使用现有的,可以这样做
    import 'prefix-json/dist/locale/zh-cn'
  • 如果要自定义,可以这样做
    import {setError} from 'prefix-json'
    setError({
    	EOF_IN_OBJECT:'这是错误信息',
    	//... 其他错误,具体请查阅.d.ts文件。
    })