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

jsonmodify

v1.0.6

Published

Reactive JSON framework and solution to serialize JSON to typescript-class

Downloads

35

Readme

JsonModify

Solution about Typescript in JsonSerializable

Version 1.0.1

  • Fix修复了转formdata 数组对象不支持的问题
  • Add 添加了JsonList 接口类型 用来扩展序列化问题
  • Add 添加了支持对Array<JsonSerializable>数组对象的支持批量序列化 和 批量对象还原

代码环境

  • 需要配置NG2的core和Rxjs 加载环境进行npm i/install 恢复代码依赖

推荐插件

  • typescript-toolbox alt+shift+G 自动生成getter/setter 选择器

文件结构

_base

  • jsonModify.ts 核心操作类

demo

  • responseModel.ts 实例响应实体
  • demo.ts 操作类操作响应实体,实现实例代码

工具使用说明

抽象类

JsonSerializable

  • $call 默认每一个Json序列化对象都有一个观察者事件,改变通过set访问器触发$call.emit()
  • $watch 订阅后提交触发自己的回调函数 若为null 则不触发。
  • $check() 手动触发$call的提交事件,PS一般作用在数组属性或递归子数组属性 有长度内容变化时手动提交对象自检。
  • json_object.Serializable() 转化装饰器构建的JSON字符串 PS: json_object instanceof JsonSerializable ==true
  • ModelClass.InstanceOf<ModelClass>(json,ModelClass) 用于还原JSON对象包含JS原型 静态方法
  • 调用实例 还原类型.InstanceOf(json字符串,还原类型)=>ModelClass.InstanceOf(json,ModelClass)
  • 注意:ModelClass extends JsonSerializable<ModelClass> 还原类型必须继承本抽象类!

抽象类使用实例代码

responseModel.ts

装饰器

包含4种装饰器:

  • JSON对象简值装饰器 JsonProp(check) =>check默认为true 可以设置false
  • 用来控制属性的改变是否触发对象的原有的$watch事件 (PS:一般设在string number 这种值类型非结构化属性访问器上)

responseModel.ts

  • JSON对象引用装饰器 @JsonModel(T,check,recursion) => 装饰器要求传入引用对象的Class类型

  • 该 T 必须继承 JsonSerializable

  • check默认为true 可以设置false 用来控制属性的改变是否触发对象的原有的$watch事件 object.json_object = new jsonClass() 触发

  • recursion 递归 默认为true修改子属性对象上的属性值则会触发父对象的$watch

    example:

      test.inner = new TestMoel();
      test.inner.name = "666"; //触发test.$watch
      test.inner.age = 888; //触发test.$watch

    (PS:一般设在object 这种引用类型结构化属性访问器上)

responseModel.ts

  • JSON简值数组引用装饰器 @JsonPropArray() => 数组修改必须手动调用object.$check()方法 目前尚待改进 (PS: 一般作用在简单的string[] / number[])

responseModel.ts

  • JSON对象引用数组装饰器 @JsonModelArray(T)
  • 该 T 必须继承 JsonSerializable
  • 目前只支持单一类型对象的数组 数组内容有修改时,同样需要工程师手动调用 object.$check()

responseModel.ts

生成JSON字符串/还原对象

example:

demo.ts

数组生成JSON字符串/还原对象数组

example:

demo.ts