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

yu-common-function

v1.0.0

Published

Common methods used in daily development

Downloads

4

Readme

Installation (安装)

npm install yu-common-function

也可下载/dist/yu-common-function.min.js中的文件使用

TS 项目 引入文件

  • 在项目中找到后缀 .d.ts 的文件(vue3中是shims-vue.d.ts);如果没有就自行创建
  • 将 declare module 'yu-common-function'; 引入其中即可

示列

// ./src/shims-vue.d.ts
declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default componen
}
declare module 'yu-common-function'; // 示列

API (方法)

日常开发中所需要的方法

引入插件库

import meansJs from 'yu-common-function';

| 1 | means(方法) :wrench: | 功能 :dragon_face: | | means(方法) :wrench: | 功能 :dragon_face: | |:--- | :--- | :--- | :--- | :--- | :--- | | 2 | meAscii | ASCII排序 | 16 | meDate | 年月日 | | 3 | meSort | 排序 | 17 | meTime | 年月日时分秒 | | 4 | meSortSize | 字符长度排序 | 18 | meUnix | 时间戳 | | 5 | meCharacterSize | 字符长度 | 19 | meJstype | 判断数据类型 | | 6 | meDeepClone | 深拷贝 | | | | | 7 | meAntiShake | 防抖 | | | | | 8 | meThrottle | 节流 | | | | | 9 | meDeWeight | 数组去重 | | | | | 10 | meGetUrl | 获取url的值 | | | | | 11 | meTerminal | 终端判断 | | | | | 12 | meToBase64 | 图片链接转为base64 | | | | | 13 | meBase64File | base64转为file文件 | | | | | 14 | meMin | 获取最小值 | | | | | 15 | meMax | 获取最大值 | | | |

meAscii

  • meAscii方法必须传递一个对象;

示列

const params = {
  name:'means',
  id:1
};
const meAscii = meansJs.meAscii(params); // id1namemeans

meSort

  • 第一个值 arr: 排序数组
  • 第二个值 type: asc 升序 ; desc 降序 --- 非必填
  • 第三个值 key: 排序字段 --- 非必填

示列

const arr = [
  {id:56},{id:98},{id:65}
];
const size = meansJs.meSort(arr,type:'asc',key:'id');

meSortSize

示列

const arr = ['meansjs','js-yyds','我最厉害','zh']
const size = meansJs.meSortSize(arr); // ['zh', 'meansjs', 'js-yyds', '我最厉害']

meCharacterSize

示列

const size = means.meCharacterSize('meansjs还不错'); // 13

meDeepClone

  • 对象或者数组都可以进行深拷贝

示列

let arr = [{id:1,name:'我不是meansjs'}]
let deep = meansJs.meDeepClone(arr);
deep[0].name = '你不是meansjs,那你是个啥?'
console.log(deep); // name : "你不是meansjs,那你是个啥?"
console.log(arr); // name : "我不是meansjs"

meAntiShake

  • 第一个值 : 函数
  • 第二个值 : 时间 --- 默认值 500

示列

meansJs.meAntiShake(()=>{
  console.log('我是meansjs');
},500) // or

meansJs.meAntiShake(()=>{
  test() // 方法
},500)

meThrottle

  • 第一个值 : 函数
  • 第二个值 : 时间 --- 默认值 500

示列

meansJs.meThrottle(()=>{
  console.log('我是meansjs');
},500) // or

meansJs.meThrottle(()=>{
  test() // 方法
},500)

meDeWeight

  • arr: 数组
  • key: 去重字段, 默认为空(一维数组)

示列

let arr = [{id:10},{id:10},{id:2},{id:3},{id:2}];
// let arr = [1,2,1,2,3];
const meDeWeight = meansJs.meDeWeight(arr,'id');

meGetUrl

  • 默认值-空(获取当前页面url);非空时:获取传递链接url的值
  • 返回对象

示列

meansJs.meGetUrl("http://localhost:8080/#/about?id=12&name='wode'&dsj='dsajk'") // or
meansJs.meGetUrl() // 获取当前页面url的值

meTerminal

示列

meansJs.meTerminal() // or
meansJs.meTerminal()['weixin']

返回参数

ali: false
android: false
gecko: true
iPad: false
iPhone: false
ios: false
mobile: false
presto: false
trident: false
webApp: true
webKit: false
weixin: false

meToBase64

  • 第一个值:图片链接
  • 第二个值:回调函数
  • 第三个值:图片质量 --- 默认值 0.92
  • 第四个值:图片格式 --- 默认值 webp(可以不填,但是不能填空字符串)

示列

meansJs.meToBase64('https://img0.baidu.com/it/u=2692044174,3628684553&fm=253&fmt=auto&app=138&f=JPEG?w=450&h=780',(base64)=>{
  console.log(base64);
  this.base64 = base64;
},0.82,'png',)

meBase64File

  • 第一个值:base64
  • 第二个值:文件名字 --- 默认值 时间戳

示列

meansJs.meToBase64('https://img0.baidu.com/it/u=2692044174,3628684553&fm=253&fmt=auto&app=138&f=JPEG?w=450&h=780',(base64)=>{
  const file = meansJs.meBase64File(base64,'meansjs');
  console.log(file);
},0.82,'png',)

meMin

  • 第一个值:数组
  • 第二个值:key值--最小值字段

示列

const arr = [
  {id:12},{id:45},{id:6}
];
const size = meansJs.meMin(arr,'id'); // 6 or
const arr = [12,45,2,34,5,3];
const size = meansJs.meMin(arr); // 2

meMax

  • 第一个值:数组
  • 第二个值:key值--最小值字段

示列

const arr = [
  {id:12},{id:45},{id:6}
];
const size = meansJs.meMax(arr,'id'); // 45 or
const arr = [12,45,2,34,5,3];
const size = meansJs.meMax(arr); // 45

meDate

示列

const date = meansJs.meDate();
console.log(date); // 2023-01-06

meTime

示列

const time = meansJs.meTime();
console.log(time); // 2023-01-06 16:16:58

meUnix

示列

const unix = meansJs.meUnix();
console.log(unix); // 1672993084067

meJstype

  • 第一个值:被判断数据
  • 第二个值:是否首字母大写 -- 默认值 false

示列

// let b = '123'; // String
// let b =  12; // Number
// let b = true; // Boolean
// let b = {id:'sda',name:'dsa'}; // Object
// let b = [{id:1},{id:2}]; // Array
// let b = null; // Null
let b = undefined; // Undefined
// let b = function() {}; // Function
// let b = new Date(); // Date
// let b = Symbol(1); // Symbol
const type = meansJs.meJstype(b,true);
console.log(type); //