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

@shilong521/fnc-method

v0.0.36

Published

js/ts方法库

Downloads

12

Readme

@shilong521/fnc-method

介绍

js/ts 通用方法库。

安装

yarn add @shilong521/fnc-method
# 或者npm install @shilong521/fnc-method --save
  1. 按需导入方法
import { getUrlSearchValueByKey } from '@shilong521/fnc-method';

Table of Contents

  • String

    • stringIsNumberAll (判断 string 是否都是数字\d,[0-9])
    • stringTrimBlank (过滤 string 中所有的空格)
    • stringEncodeChineseOnly (string 仅对汉字进行编码)
  • Number

    • numInRange (判断一个数字是否在指定范围内,包括 start,不包过 end,如果指定 start=null 那么就是 num<end,end=null 就是 num>=start)
  • Array

    • arrayOmitFake (过滤 array 中的假值 (NaN、null、""、undefind、{}、[]))
  • Object

    • objOmitFake (过滤 object 中的假值 (NaN、null、""、undefind、{}、[]))
    • objForArray (遍历 object,返回数组: {label:K,value:V}[],config.fieldNames 指定返回对象的两个 keyName,config.isFakeValue 是否过滤 value 是假值的数据)
  • window

    • getUrlSearchValueByKey (通过 key 获取 urlSeach 参数的 value)
    • urlSearchToObject (url 参数 search 转 object,numberKeys:需要转为 number 的 keys,valueNumberKeys:value 是否需要转为 number 的 keys,valueArrayKeys:value 是否需要转为数组的 keys)
    • addUrlSearchData (添加 url 的 Search 参数,search 支持 key-value,string(xxx=xx&xx=xx)和 object,如果存在则替换,不存在则添加)
    • delUrlSearchKey (清除 url 的 Search 参数,key 支持 string,string[])
    • historyReplace (无感更新 url)
    • replaceSearchValueByKey (替换 url 的 Search 参数 key 的 value,value 支持 string 和 string[])
    • delUrlAllSearch (一键清除 url 所有 Search 参数,无感更新)
  • Tree

    • treeFind (查找树形节点)
    • treeFilter (筛选出来符合条件的树形结构)
    • treeFindValues (返回树形结构指定的所有 key 的 value)
    • treeFindPaths (查找树形节点路径)
  • Is

    • isString
    • isNumber
    • isNull
    • isUndefined
    • isObject
    • isArray
    • isDev (判断是不是 dev 环境,process.env.NODE_ENV)
    • isFake (判断是不是假值 (null,NaN,"",undefind,{},[]))
  • Event

    • stopPropagation(阻止 js,React 事件冒泡)

treeFindPaths

import { treeFindPaths } from '@shilong521/fnc-method';

const treeData = [
  {
    id: '1',
    name: '1-c',
    children: [
      {
        id: '1-1',
        name: '1-1-c',
        children: [{ id: '1-1-1', name: '1-1-1-c' }],
      },
      { id: '1-2', name: '1-2-c' },
    ],
  },
  {
    id: '2',
    name: '2-c',
    children: [{ id: '2-1', name: '2-1-c' }],
  },
];

console.log(
  treeFindPaths(treeData, (data) => data.id === '1-1-1', 'id', 'children'), //[ '1', '1-1', '1-1-1' ]
  treeFindPaths(treeData, (data) => data.id === '2-1', 'name') // [ '2-c', '2-1-c' ]
  treeFindPaths(treeData, (data) => data.id === '2-3', 'id') // []
);

urlSearchToObject

import { urlSearchToObject } from '@shilong521/fnc-method';

console.log(
  //window.location.search = '?id=144&chinese=%E5%93%88%E5%93%88&chinese=%E4%BD%A0%E5%A5%BD&123=asd';
  urlSearchToObject(window), // { id: '144', chinese: [ '哈哈', '你好', '123': asd }
  urlSearchToObject(window, { numberKey: ['123'] }), // { id: '144', chinese: [ '哈哈', '你好', 123: asd }
  urlSearchToObject(window, { valueNumberKeys: ['id'] }), // { id: 144, chinese: [ '哈哈', '你好' ], '123': asd }
  urlSearchToObject(window, { valueArrayKeys: ['id'] }), // { id: ['144'], chinese: [ '哈哈', '你好', '123': asd ] }
  urlSearchToObject(window, {
    valueNumberKeys: ['id'],
    valueArrayKeys: ['id'],
  }) // { id: [144], chinese: [ '哈哈', '你好' ], '123': asd }
);