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

json-service-editor

v1.0.16

Published

用于启动一个json读写的配套程序。

Downloads

6

Readme

json-service-editor

用于启动一个json读写的配套程序。比如服务端还在开发中,但是你仍需要一个可以模拟本地读写的程序,那么 json-service-editor 是一个很好的选择。

  • core(跨域) - 1.0.11以及以后
  • 支持js配置文件 - 1.0.11以及以后
  • 支持自定义接口配置 - 1.0.11以及以后

Install

npm i json-service-editor -g

Quick Start

create .json-service.json

{
  "url": "demo.json",
  "port": 3000
}

run

json-service-editor

现在你已经启动了一个简单的json读写服务。

Interface

这里是最基本的json两个接口,get 和 set。

Get JSonValue

fetch('http://localhost:3000/get/demo.json', {
  method: 'GET',
})

Set JSonValue

fetch('http://localhost:3000/set/demo.json', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ message: 'hello world!' }),
})

Options

这里提供两种配置文件,一种是 .json-service.json 一种是 .json-service.js,如果运行目录同时存在js 与 json两种配置则js脚本优先。

| 配置 | .json-service.js | .json-service.json | description | | ---- | ---- | ---- | ---- | | url | ✅ | ✅ | 文件相对路径 | | port | ✅ | ✅ | 服务端口 | | service | ✅ | ❌ | 自定义服务列表 |

url与port定义相对简单,service这里做一些代码演示:

module.exports = () => {
  const url = "src/demo.json";
  const port = 3110;
  return {
    url,
    port,
    service: {
      // post请求
      '/post': {
        methods: 'post',
        handle: ({ json, params, res, req }) => {
          // json: 编辑json本身
          // params: 请求入参
          // res && req: 参考express官方文档
          res.json(200, { message: 'pass!' });
        }
      },

      // post请求
      '/get': {
        methods: 'get',
        handle: ({ json, params, res, req }) => {
          // json: 编辑json本身
          // params: 请求入参
          // res && req: 参考express官方文档
          res.json(200, { message: 'pass!' });
        }
      }
    }
  }
};

Simpler Browser API (Base on FetchAPI)

如果你不想直接通过 fetchAPI 实现读写,你可以直接在需要json的地方

First: npm install json-service-editor

Code:

import JsonServiceEditorCore from 'json-service-editor';

const serviceSDK = new JsonServiceEditorCore({
  baseUrl: 'http://localhost:3000',
  fileName: 'demo.json'
});

const { getValue, setValue } = serviceSDK;

getValue(
  // success callback
  () => {},
  // fail callback
  () => {}
)

TODO

  • Test
  • Website
  • BenchMark