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

ticatec-enhanced-utils

v0.1.2

Published

an enhanced js utils

Downloads

4

Readme

Enhanced Array Functions

This library provides two function for the array; the function replace can replace the first match element with the new item.
the function remove can remove the first match element from the array.

replace

arguments

item, the new data you would set into the array;
match, the 'match' should be a function, with returns true of false to determine whether the element matches the criteria or not. you can use the lambda function with one argument element.
return, if the array successfully replaces the matched element, the return value should be the index of this element, otherwise, -1 will be the value.

usage:

int array.replace(item, match);

example:

let arr = [
    {id:1, name:"aa"}, 
    {id:2, name:"bb"}, 
    {id: '234234', name:"第三个"}
  ];
let idx = arr.replace({id:2, name:"新元素"}, element => element.id === 2); 

remove

arguments

match, the 'match' should be a function, with returns true of false to determine whether the element matches the criteria or not. you can use the lambda function with one argument element.
return, if the array successfully replaces the matched element, the return value should be the index of this element, otherwise, -1 will be the value.

usage:

bool array.remove(match);

example:

let arr = [
    {id:1, name:"aa"}, 
    {id:2, name:"bb"}, 
    {id: '234234', name:"第三个"}
  ];
let success = arr.remove(element => element.id === 2); 

数组增强功能

为数组增加了两个方法,替换和删除

替换

从数组中找到地一个匹配的元素替换成新的元素,并返回替换元素的索引,如果没有匹配的,则返回-1,表示替换失败。

使用方法:

let arr = [
    {id:1, name:"aa"}, 
    {id:2, name:"bb"}, 
    {id: '234234', name:"第三个"}
  ];
let idx = arr.replace({id:2, name:"新元素"}, item => item.id === 2); 

删除

从数组中找到地一个匹配的元素替删除,如果没有匹配的,则返回false,表示删除失败。

使用方法:

let arr = [
    {id:1, name:"aa"}, 
    {id:2, name:"bb"}, 
    {id: '234234', name:"第三个"}
  ];
let success = arr.remove(item => item.id === 2); 

对象增强功能

增加空属性

  let s = {};
  s.addAttrs(['name', 'code', 'address']);

TicatecUtils

使用方法和函数列表:

     import ticatecUtils from 'ticatec-enhanced-utils';
     
     /**
     * 判断参数是不是一个函数
     * @param fun
     * @returns {boolean}
     */
    function isFunction (fun)
    
    /**
     * 调用函数
     * @param fun
     * @param params
     */
    function invokeFunction (fun, ...params)
    
    /**
     * 判断字符串是不是空
     * @param s
     * @returns {boolean}
     */
    function isEmpty (s) 
    
    /**
     * 解析url中的queryString
     * @param qs
     * @returns {Array}
     */
    function parseQueryString (qs)