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

hys-data-class

v1.0.0

Published

data class

Downloads

13

Readme

hys-data-class

安装依赖

npm install --save hys-data-class

接口

/**
* 设置配置
* @param cfg 配置对象
*/
setCfg < T > (cfg: T): void;

/**
* 获取配置
*/
getCfg(): NSDataClass.IData;

/**
* 设置 getVal、getDataVal 默认值
* @param val 值
*/
setDefaultVal < T > (val: T): void;

/**
* 获取 getVal、getDataVal 默认值
*/
getDefaultVal(): NSDataClass.IData;

/**
* 设置 incVal、incDataVal、decVal、decDataVal 限制对象
* @param limitExt 限制对象
*/
setDefaultLimitExt(limitExt ? : NSDataClass.ILimitExt): void;

/**
* 获取 incVal、incDataVal、decVal、decDataVal 限制对象
*/
getDefaultLimitExt(): NSDataClass.ILimitExt;

/**
* 获取数据长度
* @param data 数据
*/
size(data: ISize): number;

/**
* 设置数据
* @param data 数据对象
* @param key 键
* @param val 值
* @param status 状态值: 0 默认值, 1 四舍五入, 2 向上取整, 3 向下取整
*/
setVal < T > (data: NSDataClass.IData, key: NSDataClass.IKey, val: T, status ? : number): void;

/**
* 获取数据
* @param data 数据对象
* @param key 键
* @param defaultVal 默认值
* @param bCreate 不存在时是否创建
* @returns 结果值
*/
getVal(data: NSDataClass.IData, key: NSDataClass.IKey, defaultVal ? : any, bCreate ? : boolean): any;

/**
* 数据自增
* @param data 数据对象
* @param key 键
* @param val 值
* @param limitExt 限制对象
* @returns 结果值
*/
incVal(data: NSDataClass.IData, key: NSDataClass.IKey, val ? : number, limitExt ? : { minVal: number, maxVal: number }): number;

/**
* 数据自减
* @param data 数据对象
* @param key 键
* @param val 值
* @param limitExt 限制对象
* @returns 结果值
*/
decVal(data: NSDataClass.IData, key: NSDataClass.IKey, val ? : number, limitExt ? : { minVal: number, maxVal: number }): number;

/**
* 对象中移除元素
* @param data 数据对象
* @param key 键
* @param val 值
* @returns 结果值
*/
unsetVal(data: NSDataClass.IData, key: NSDataClass.IKey, val: any, defaultVal ? : {}): boolean;

/**
* 数组中追加元素
* @param data 数据对象
* @param key 键
* @param val 值
*/
arrPushVal(data: NSDataClass.IData, key: NSDataClass.IKey, val: any, defaultVal ? : [], bCreate ? : boolean): void;

/**
* 数组中移除元素
* @param data 数据对象
* @param key 键
* @param val 值
* @returns 结果值
*/
arrPullVal(data: NSDataClass.IData, key: NSDataClass.IKey, val: any, defaultVal ? : []): Array < any > ;

/**
* 设置数据
* @param key 键
* @param val 值
* @param status 状态值: 0 默认值, 1 四舍五入, 2 向上取整, 3 向下取整
*/
setDataVal < T > (key: NSDataClass.IKey, val: T, status ? : number): void;

/**
* 获取数据
* @param key 键
* @param defaultVal 默认值
* @param bCreate 不存在时是否创建
* @returns 结果值
*/
getDataVal(key: NSDataClass.IKey, defaultVal ? : any, bCreate ? : boolean): any;

/**
* 数据自增
* @param key 键
* @param val 值
* @param limitExt 限制对象
* @returns 结果值
*/
incDataVal(key: NSDataClass.IKey, val ? : number, limitExt ? : { minVal: number, maxVal: number }): number;

/**
* 数据自减
* @param key 键
* @param val 值
* @param limitExt 限制对象
* @returns 结果值
*/
decDataVal(key: NSDataClass.IKey, val ? : number, limitExt ? : { minVal: number, maxVal: number }): number;

/**
* 对象中移除指定元素
* @param key 键
* @param val 值
* @returns 结果值
*/
unsetDataVal(key: NSDataClass.IKey, val: any, defaultVal ? : {}): boolean;

/**
* 数组中追加元素
* @param key 键
* @param val 值
*/
arrPushDataVal(key: NSDataClass.IKey, val: any, defaultVal ? : [], bCreate ? : boolean): void;

/**
* 数组中移除所有指定元素
* @param key 键
* @param val 值
* @returns 结果值
*/
arrPullDataVal(key: NSDataClass.IKey, val: any, defaultVal ? : []): Array < any > ;

测试代码

import { DataClass } from "hys-data-class";

class Test extends DataClass {
    constructor() {
        super();
        this._data = {};
    }
    getData() {
        return this._data;
    }
}

let test = new Test();
// 设置 getVal、getDataVal 默认值
let defaultVal = 0;
test.setDefaultVal(defaultVal);
console.log(`设置 getVal、getDataVal 默认值: ${defaultVal}`);
console.log(`获取当前数据对象值: ${JSON.stringify(test.getData())}`);
console.log(`获取当前配置对象值: ${JSON.stringify(test.getCfg())}`);

let key = ["num", "subItem"]; // "num"

let data = {};
let dataVal1 = 101;
test.setVal(data, key, dataVal1);
console.log(`临时数据 设置指定key值: ${dataVal1}`);
dataVal1 = test.getVal(data, key);
console.log(`临时数据 获取指定key值: ${dataVal1}`);
console.log(`获取临时数据对象值: ${JSON.stringify(data)}`);

let dataVal2 = 102;
test.setDataVal(key, dataVal2);
console.log(`成员数据 设置指定key值: ${dataVal2}`);
dataVal2 = test.getDataVal(key);
console.log(`成员数据 获取指定key值: ${dataVal2}`);
console.log(`获取成员数据对象值: ${JSON.stringify(test.getData())}`);