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

@icreate/ics-chromely-js-sdk

v0.0.8

Published

import icsChromelyRequest from '@icreate/ics-chromely-js-sdk' ## 对错误做统一处理 errorFn

Downloads

48

Readme

引入

import icsChromelyRequest from '@icreate/ics-chromely-js-sdk'

对错误做统一处理 errorFn

icsChromelyRequest.errorFn = (response) => {
  console.log(response, 'error')
  Message({
    message: response.message || 'Error',
    type: 'error',
    duration: 5  1000
  })
}
注意:由于多个sdk包会引用此包,故错误处理应该在主应用使用,而不是在sdk包中使用,为保证多个sdk使用的为同一个类的引用,在sdk打包时应去掉此包的依赖,在rollup.config.ts中添加以下配置,其余打包工具方法请自行查找
external: ['@icreate/ics-chromely-js-sdk']

使用

icsChromelyRequest.command

icsChromelyRequest.command(opts: { url: string; data?: any }): void

icsChromelyRequest.function

icsChromelyRequest.function(opts: { url: string; method?: 'POST' | 'GET'; data?: any })
注意:参数需要根据C#文件来定义,以下面的C#文件为例, url为RouteKey关键字对应值;request.Parameters["key"]对应的则为GET方法,且参数为key;_jsonSerializer.Deserialize<CacheModel>(request.PostData.ToString())对应的则为POST方法,参数为CacheModel对应的数据类型。
{
    /// <summary>
    /// Memory Caching Controller
    /// </summary>
    [ControllerProperty(Name = "MemoryCachingController")]
    public class MemoryCachingController : IcsChromelyController
    {
        private readonly IJsonSerializer _jsonSerializer;
        private readonly IMemoryCache _memoryCache;

        /// <summary>
        /// 构造函数
        /// </summary>
        public MemoryCachingController(IJsonSerializer jsonSerializer, IMemoryCache memoryCache)
        {
            _jsonSerializer = jsonSerializer;
            _memoryCache = memoryCache;
        }

        /// <summary>
        /// 设置缓存(POST)
        /// </summary>
        /// <param name="queryParameters">查询参数</param>
        [RequestAction(RouteKey = "Caching/Memory/Set")]
        public IIcsChromelyResponse Set(IIcsChromelyRequest request)
        {
            try
            {
                Check.NotNull(request.PostData, "缓存对象");
                var cacheModel = _jsonSerializer.Deserialize<CacheModel>(request.PostData.ToString());
                _memoryCache.Set(cacheModel.Key, cacheModel.Value);
                return Success("Ok");
            }
            catch (Exception ex)
            {
                return InternalError(ex.Message);
            }
        }

        /// <summary>
        /// 获取缓存(GET)
        /// </summary>
        /// <param name="queryParameters">查询参数</param>
        [RequestAction(RouteKey = "Caching/Memory/Get")]
        public IIcsChromelyResponse Info(IIcsChromelyRequest request)
        {
            try
            {
                if (!request.Parameters.ContainsKey("key"))
                    throw new ArgumentNullException("key");
                string key = request.Parameters["key"];
                Check.NotNull(key, "缓存键");
                string value = _memoryCache.Get<string>(key);
                return Success(value);
            }
            catch (Exception ex)
            {
                return InternalError(ex.Message);
            }
        }


        /// <summary>
        /// 删除缓存(GET)
        /// </summary>
        /// <param name="queryParameters">查询参数</param>
        [RequestAction(RouteKey = "Caching/Memory/Remove")]
        public IIcsChromelyResponse Remove(IIcsChromelyRequest request)
        {
            try
            {
                if (!request.Parameters.ContainsKey("key"))
                    throw new ArgumentNullException("key");
                string key = request.Parameters["key"];
                Check.NotNull(key, "缓存键");
                _memoryCache.Remove(key);
                return Success("ok");
            }
            catch (Exception ex)
            {
                return InternalError(ex.Message);
            }
        }
    }
}