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

cdm-plugin

v1.1.0

Published

<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

Downloads

10

Readme

cdm-plugin

Table of Contents generated with DocToc

install:

    npm install cdm-plugin --save

use:

    import {Http, WebSocketClient, FileUtil, 
    BaseUtil, BaseDBUtil, Business, 
    LOGLEVEL, MODE_TYPE, FILE_TYPE, Log} from 'cdm-plugin';

Http:

method

| method | description | params | params detail | | ------ | ------ | ------ | ------ | | ajaxPromise | ajax with promise | {Object} |{url, data, async, type} default: type='get', async=true,data = '' | | ajaxPromiseUpload | upload file | {Object} |{url, formData} |

use
    // post
    let data = await Http.ajaxPromise({url: `www.xxx.com/entity?id=1`}); // get
    let data = await Http.ajaxPromise({
        url: `www.xxx.com/entity`,
        type: 'post',
        data: data,
    });
    // upload file
    const export_blob = new Blob([data]);
    const file = new File([export_blob], fileName);
    const formData = new FormData();
    formData.append("file", file);
    Http.ajaxPromiseUpload({
        url,
        formData,
    });

WebSocketClient:

method

| method | description | params | | ------ | ------ | ------ | | constructor | init with ip, port | ip, port | | addEventListener | - | type, callback | | removeEventListener | - | type | | removeAllEventListener | - | - | | waitConnect | - | - | | send | - | data | | close | - | - |

use
    let client = new WebSocketClient(ip, port);
    client.addEventListener('devicelist', (e) => {
        console.log(e.data);
    });
    await client.waitConnect();
    client.removeEventListener('devicelist');
    client.removeAllEventListener();
    client.send(JSON.stringify(data));
    client.close();

FileUtil:

method

| method | description | params | params detail | | ------ | ------ | ------ | ------ | | XMLtoString | - | xmlElement | - | | toFile | generate file | fileName, fileText | - | | getZipFiles | get a zip package all files | file | - | | saveZip | generate zip file | fileName, content | - | | uploadFiles | - | url, files | - |

use
    const str = FileUtil.XMLtoString(xmlElement);
    cosnt file1 = FileUtil.toFile(str);
    cosnt file2 = FileUtil.toFile(str);
    const [logics, modes, zip] = await FileUtil.getZipFiles(file);
    const files = [file1, file2];
    FileUtil.uploadFiles(url, files);
    let zip = new JSZip();
    let logic = zip.folder('lua');
    cosnt file1 = FileUtil.toFile(str);
    logic.file(`${fileName}.${fileType}`, file1);
    const content = await zip.generateAsync({type: 'blob'});
    FileUtil.saveZip(`fileName.zip`, content);

BaseUtil:

method

| method | description | params | params detail | | ------ | ------ | ------ | ------ | | notEmptyArray | - | [Array] | return boolean | | notEmptyObject | - | {Object} | return boolean | | fileNameFormat | - | String | return String | | fileExtFormat | - | String | return String |

use
    let array1;// false
    let array2 = [];// false
    let array3 = [0];// true
    BaseUtil.notEmptyArray(array1);
    
    let object1;// false
    let object2 = {};// false
    let object3 = {'key': 'value'};// true
    BaseUtil.notEmptyObject(object1);
    const fileName = 'index.json';
    BaseUtil.fileNameFormat(fileName);// index
    BaseUtil.fileExtFormat(fileName);// json

BaseDBUtil:

method

| method | description | params | params detail | | ------ | ------ | ------ | ------ | | setConfig | ------ | [Array] | return boolean | | setTimeout | ------ | number | return boolean | | getTimeout | ------ | - | return number | | getInstance | ------ | - | return number | | save2Idb | ------ | tableName, data | - | | findDataByCondition | ------ | tableName, condition | return [Array] | | deleteData | ------ | tableName, condition | - | | customOperation | ------ | tableName, operation | callback return instance |

use
import dbc from '@/js/db_config';

    const baseDBUtil = new BaseDBUtil();
    baseDBUtil.setConfig(dbc);
    baseDBUtil.setTimeout(5000);
    await baseDBUtil.getInstance();
    await baseDBUtil.save2Idb(tableName,{'key':'value'});
    const data = await baseDBUtil.findDataByCondition(tableName, (item) => {
        return item.programName === name
            && item.programType === type;
    });
    const data2 = await baseDBUtil.findAll(tableName);
    await baseDBUtil.deleteData(tableName, (item) => {
        return item.name === key && item.type === FILE_TYPE.JSON;
    });
    await baseDBUtil.customOperation(tableName, (instance) => {
        instance.query({
            tableName,
            condition,
        });
    });
    await baseDBUtil.clearIdbTable(tableName);
reference

when you use customOperation, you can get idb-js instance

db_config file reference idb-js

idb-js doc url: https://github.com/verybigorange/idb-js

Business:

method

| method | description | params | params detail | | ------ | ------ | ------ | ------ | | getZipData | zip to data | File | return [Array] | | generateZipContent | data to zip | data | return content | | uploadAllFiles | - | config, logicFiles, modeFiles | config = {fileServer, params} | | deleteAllFiles | - | config, logicFiles, modeFiles | config = {fileServer, params} |

use
    const rows = Business.getZipData(file);
    rows.forEach((item) => {
        baseDBUtil.save2Idb(tableName, item);
    });
    
    const content = Business.generateZipContent(rows);
    FileUtil.saveZip(fname, content);
    const config = {
        fileServer: 'www.xxx.com/entity', 
        params: '?id=1',
    };
    await Business.uploadAllFiles(config, logicFiles, modeFiles);
    await Business.deleteAllFiles(config, logicFiles, modeFiles);

Log:

method

| method | description | params | params detail | | ------ | ------ | ------ | ------ | | init | - | logLevel | number[0-4] | | setLevel | - | logLevel | number[0-4] |

use
    Log.init(LOG_LEVEL.WARN);
    Log.setLevel(LOG_LEVEL.INFO);

DICT:

define

| object| key | value | | ------ | ------ | ------ | | LOG_LEVEL | TRACE | 0 | | LOG_LEVEL | LOG | 1 | | LOG_LEVEL | INFO | 2 | | LOG_LEVEL | WARN | 3 | | LOG_LEVEL | ERROR | 4 | | MODE_TYPE | LOGIC | 'logic' | | MODE_TYPE | MODE | 'mode' | | FILE_TYPE | JSON | 'json' | | FILE_TYPE | JSON | 'lua' | | FILE_TYPE | JSON | 'xml' |

use
    Log.init(LOG_LEVEL.WARN);