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

dson.js

v1.3.1

Published

declarative operation encapsulation for json

Downloads

5

Readme

dson.js

declarative operation encapsulation for json
DSL for json

功能

just to it

npm i --save dson.js

var DSONJS= require('dson.js')
var d = D = DSON = dson = DSONJS.DSON
var j = J = jvd = JVD = DSONJS.JVD

var v = null
//define dson
v =	dson('games').count()
v = dson().get('name') 
//v = dson('name') 
//v = dson().get('games[0].name') 
//v = dson().select('games[0].name') 
//v = dson().draw('games[0].name') 
//v = dson().get('games[].name'))
v = dson('games[0]').test({
  		name : "='fate stay night'",
    	masters : DSON().count().test('=6')
  	})

// here your json
var json = {
  "name": "圣杯战争",
  "about": "Fate",
  "games": [
    {
      "name": "fate stay night",
      "masters": [
        {
          "name": "Shirou Emiya",
          "cnName": "卫宫士郎"
        }
      ],
      "servants": [
        {
          "rank": "saber",
          "name": "Arutoria Pendoragon",
          "cnName": "阿尔托莉雅·潘德拉贡",
          "cv": "川澄绫子",
          "height": 154,
          "weight": 42,
          "BWH": "B73 W53 H76",
          "remark": "古不列颠传说中的亚瑟王,性格忠诚正直,谦逊有礼,个性认真。"
        }
      ]
    }
  ]
}

(async ()=>{
    //do select
    var result = await v.doSelect(json)

    // do test
    var isSuccess = await v.doTest(json)
})

如何扩展dson

to extend one instance of DSON

var DSONJS= require('dson.js')
var d = D = DSON = dson = DSONJS.DSON
var di1 = d('name')
var di2 = d()

var json = {"name": "圣杯战争"}
//reg new method for dsonInstance 
di1.reg('hello',  (context, yourParam1,yourParam2) => {
  // your function can be async  or sync, here is sync
  //context is inner context object for dson
  // yourParam1 yourParam2 ... is your params

  //here to set result
  context.currentData = context.tempData = `${context.tempData},hello ${yourParam1} ${yourParam2}`
  //more details in document
})

di1.hello('world' , '!!!!')

//here error
di2.hello('ni','hao')

di1.doSelect(json).then(d=>{ console.log(d)})
//圣杯战争,hello world !!!!

to extend DSON globally

var DSONJS= require('dson.js')
var d = D = DSON = dson = DSONJS.DSON

var json = {"name": "圣杯战争"}

//reg new method for DSON
d.reg('hi', async (context, yourParam1,yourParam2) => {
  context.currentData = context.tempData = `${context.tempData},hello ${yourParam1} ${yourParam2}`
})

var di3 = d('name')
var di4 = d('name')

di3.hi('ni','hao')
di4.hi(1,2,3)

di3.doSelect(json).then(d=>{ console.log(d)})
di4.doSelect(json).then(d=>{ console.log(d)})
//圣杯战争,hi ni hao
//圣杯战争,hi 1 2

examples:

  1. api.dson.js 扩展dson,使其支持api调用

to extend method preExe

var DSONJS= require('dson.js')
var d = D = DSON = dson = DSONJS.DSON

D.reg('$test', function(dsonObj, p1){
    console.log(p1)
})

d('test2').set('abc' , {hello : 1}).$test('yesyes')

常用场景

  1. 对json校验
  2. format json
  3. 不固定json结构的抽取和校验
  4. 支持扩展,对非编程场景的二次封装使用
  5. 支持嵌套、模板嵌套等,支持复杂的声明式数据查询、渲染、校验,类sql,可以动态拼接实现动态逻辑
  6. 可以支持序列化,支持网络传播(待实现)
  7. 声明式及模板方式实现逻辑,使逻辑可视化,提高可读性,提高可修改性
  8. 解析excel
  9. 解析html

todos

  1. 执行的服务器客户端模式 dson server
  2. servants saber
  3. 语言嵌套
  4. [ok] serialize https://github.com/apporoad/dson.parser.js.git
  5. format jvd 如 '>${a.b}'
  6. webdrive 自动化测试
  7. [ok] render ' asdf ${a}sdf'
  8. add dson verbose 打出每一步的执行结果
  9. 支持cross 、x ,表示dson穿越,加载全局dson, 支持global,全局注册dson
  10. 在cross中需要支持远程调用和缓存,需要找到默认实现 mini.req.js lisa.cache.js

细节场景

  1. 抽出数据
  2. 复杂抽出数据
  3. 对数据做校验
  4. format json
  5. 神奇的使用