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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pms-saas-common

v1.1.3

Published

Readme

PMS前端公共库

安装

仓库地址:

https://git.coding.net/JJJason/pms-saas-common.git

目录

HTTP

  • Fetch

本地存储

  • SetLocalStorage
  • GetLocalStorage
  • RemoveLocalStorage
  • RemoveAllLocalStorage
  • SetSessionStorage
  • GetSessionStorage
  • RemoveSessionStorage
  • RemoveAllSessionStorage
  • SetCacheStorage
  • GetCacheStorage
  • RemoveCacheStorage
  • ClearCacheStorage

浏览器工具

  • IsWxEnv

常用工具

  • MergeObject
  • IsEmptyObject
  • CloneObject
  • Object2Url
  • Url2Object
  • KeysOfObject
  • ValuesOfObject
  • Blob2Base64
  • UrlParams
  • UrlParams2Object

其他

  • FormatAmount

微信JS-SDK-API

  • WxAuth4Vendor
  • WxAuth4Public
  • WxConfig
  • WxShareTimeline
  • WxShareAppMessage
  • WxChooseImage
  • WxPreviewImage
  • WxOpenLocation
  • WxGetLocation
  • WxQRCode
  • WxPay
  • WxCloseWindow

API

1. HTTP

1.1 Fetch请求:

方法:
Fetch(url, method, headers, body)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|---------| | url | String | 空字符串 | 请求地址 | | method | String | POST | 请求方法 | | headers | Object | 空对象 | 请求头部 | | body | Object | 空对象 | 请求体 |

返回:

| 类型 | 描述 | |---------|----------------| | Promise | 返回Promise对象 |

实例:
import { Fetch } from 'pms-saas-common';

let url = 'http://api.xxx.com';
let method = 'POST';
let headers = { 'Content-Type': 'application/json' };
let body = { a: 1, b: 2 };

Fetch(url, method, headers, body)
  .then(result => {
    //	resolve
  })
  .catch(error => {
	//	reject
  });

2. 本地存储

2.1 保存到localStorage:

方法:
SetLocalStorage(key, value)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | key | String | 无 | 保存的标示/键 | | value | String | 空字符串 | 保存的数据/值 |

返回:

| 类型 | 描述 | |---------|----------------| | Void | 无返回值 |

实例:
import { SetLocalStorage } from 'pms-saas-common';

SetLocalStorage('token', '123')

2.2 从localStorage获取

方法:
GetLocalStorage(key)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | key | String | 无 | 获取的标示/键 |

返回:

| 类型 | 描述 | |---------------|----------------| | String/Object | 返回获取的值/对象 |

实例:
import { GetLocalStorage } from 'pms-saas-common';

let token = GetLocalStorage('token');

console.log(token); => '123';

2.3 删除localStorage

方法:
RemoveLocalStorage(key)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | key | String | 无 | 删除的标示/键 |

返回:

| 类型 | 描述 | |---------|----------------| | Void | 无返回值 |

实例:
import { RemoveLocalStorage } from 'pms-saas-common';

RemoveLocalStorage('token');

2.4 删除全部localStorage

方法:
RemoveAllLocalStorage()
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | 无 | 无 | 无 | 无 |

返回:

| 类型 | 描述 | |---------|----------------| | Void | 无返回值 |

实例:
import { RemoveAllLocalStorage } from 'pms-saas-common';

RemoveAllLocalStorage();

2.5 保存到sessionStorage:

方法:
SetSessionStorage(key, value)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | key | String | 无 | 保存的标示/键 | | value | String | 空字符串 | 保存的数据/值 |

返回:

| 类型 | 描述 | |---------|----------------| | Void | 无返回值 |

实例:
import { SetLocalStorage } from 'pms-saas-common';

SetLocalStorage('userInfo', { name: 'Jason' })

2.6 从sessionStorage获取

方法:
GetSessionStorage(key)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | key | String | 无 | 获取的标示/键 |

返回:

| 类型 | 描述 | |---------------|----------------| | String/Object | 返回获取的值/对象 |

实例:
import { GetSessionStorage } from 'pms-saas-common';

let userInfo = GetSessionStorage('userInfo');

console.log(userInfo); => { name: 'Jason' };

2.7 删除sessionStorage

方法:
RemoveSessionStorage(key)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | key | String | 无 | 删除的标示/键 |

返回:

| 类型 | 描述 | |---------|----------------| | Void | 无返回值 |

实例:
import { RemoveSessionStorage } from 'pms-saas-common';

RemoveSessionStorage('userInfo');

2.8 删除全部sessionStorage

方法:
RemoveAllSessionStorage()
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | 无 | 无 | 无 | 无 |

返回:

| 类型 | 描述 | |---------|----------------| | Void | 无返回值 |

实例:
import { RemoveAllSessionStorage } from 'pms-saas-common';

RemoveAllSessionStorage();

2.9 保存到缓存

方法:
SetCacheStorage(key, value, expireTime)
参数:

| 字段 | 类型 | 默认值 | 描述 | |------------|---------|---------|--------------| | key | String | 无 | 保存的标示/键 | | value | String | 空字符串 | 保存的数据/值 | | expireTime | String | 0 | 多少时间后自动过期,0为不过期 |

返回:

| 类型 | 描述 | |---------|----------------| | Void | 无返回值 |

实例:
import { SetCacheStorage } from 'pms-saas-common';

SetCacheStorage('userInfo', { name: 'Jason' }, 60 * 60 * 1000);

2.10 从获取缓存

方法:
GetCacheStorage(key)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | key | String | 无 | 获取的标示/键 |

返回:

| 类型 | 描述 | |---------------|----------------| | String/Object | 返回获取的值/对象 |

实例:
import { GetCacheStorage } from 'pms-saas-common';

let userInfo = GetCacheStorage('userInfo');

console.log(userInfo); => { name: 'Jason' };

2.11 删除缓存

方法:
RemoveCacheStorage(key)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | key | String | 无 | 删除的标示/键 |

返回:

| 类型 | 描述 | |---------|----------------| | Void | 无返回值 |

实例:
import { RemoveCacheStorage } from 'pms-saas-common';

RemoveCacheStorage('userInfo');

2.12 删除全部缓存

方法:
ClearCacheStorage()
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | 无 | 无 | 无 | 无 |

返回:

| 类型 | 描述 | |---------|----------------| | Void | 无返回值 |

实例:
import { ClearCacheStorage } from 'pms-saas-common';

ClearCacheStorage();

3. 浏览器工具

3.1

  • MergeObject
  • IsEmptyObject
  • CloneObject
  • Object2Url
  • Url2Object
  • KeysOfObject
  • ValuesOfObject
  • Blob2Base64
  • UrlParams
  • UrlParams2Object

4. 常用工具

4.1 合并对象

方法:
MergeObject(objArr)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|-----------------| | objArr | Array | 空数组 | 需要合并的对象数组 |

返回:

| 类型 | 描述 | |---------|----------------| | Object | 重新组合的新对象 |

实例:
import { MergeObject } from 'pms-saas-common';

let arr = [
  { a: 1 },
  { b: 2 },
  { c: 3 }
];

let obj = MergeObject(arr);

console.log(obj); => { a: 1, b: 2, c: 3 };

4.2 判断对象是否为空

方法:
IsEmptyObject(obj)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|-----------------| | obj | Object | 空对象 | 需要判断的对象 |

返回:

| 类型 | 描述 | |---------|-----------------------------| | Boolean | true为空对象,false为非空对象 |

实例:
import { IsEmptyObject } from 'pms-saas-common';

let obj = {};

let result = IsEmptyObject(obj);

console.log(result); => true;

4.3 拷贝对象

方法:
CloneObject(obj, isDeep)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------------------| | obj | Object | 空对象 | 需要判断的对象 | | isDeep | Boolean | false | true为深拷贝,false为浅拷贝 |

返回:

| 类型 | 描述 | |---------|------------| | Object | 拷贝后的对象 |

实例:
import { CloneObject } from 'pms-saas-common';

let obj1 = {
  a: 1
};

let obj2 = CloneObject(obj1);

console.log(obj2); => { a: 1 };

4.4 将Object转化为Url

方法:
Object2Url(obj)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|--------------| | obj | Object | 空对象 | 需要转化的对象 |

返回:

| 类型 | 描述 | |---------|-------------------| | String | 转化后的UrlParams |

实例:
import { Object2Url } from 'pms-saas-common';

let obj = {
  a: 1,
  b: 2,
  c: 3
};

let result = Object2Url(obj);

console.log(result); => 'a=1&b=2&c=3';

4.5 将Url转化为Object

方法:
Url2Object(url)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|---------------| | url | String | 空字符串 | 需要转化的字符串 |

返回:

| 类型 | 描述 | |---------|------------| | Object | 转化后的对象 |

实例:
import { Url2Object } from 'pms-saas-common';

let str = 'a=1&b=2&c=3';

let result = Url2Object(str);

console.log(result); => { a: 1, b: 2, c: 2 };

4.6 将Url转化为Object

方法:
Blob2Base64(blob)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|------------------| | blob | Blob | null | 需要转化的Blob对象 |

返回:

| 类型 | 描述 | |---------|----------------| | Promise | 返回Promise对象 |

实例:
import { Blob2Base64 } from 'pms-saas-common';

let blob = <Blob>{};

Blob2Base64(blob).then(result => {
  console.log(result); => base64格式数据
});

4.7 获取urlParams字符串

方法:
UrlParams(url)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|-----------------| | url | String | 空字符串 | 需要处理的url地址 |

返回:

| 类型 | 描述 | |---------|----------------| | String | UrlParams字符串 |

实例:
import { UrlParams } from 'pms-saas-common';

let url = 'https://www.example.com/?a=1&b=2&c=3';

let result = UrlParams(url);

console.log(result); => 'a=1&b=2&c=3';

4.8 获取urlParams并转化成对象

方法:
UrlParams2Object(url)
参数:

| 字段 | 类型 | 默认值 | 描述 | |---------|---------|---------|-----------------| | url | String | 空字符串 | 需要处理的url地址 |

返回:

| 类型 | 描述 | |---------|---------------------| | Object | UrlParams转化后的对象 |

实例:
import { UrlParams2Object } from 'pms-saas-common';

let url = 'https://www.example.com/?a=1&b=2&c=3';

let result = UrlParams2Object(url);

console.log(result); => { a: 1, b: 2, c: 3 };

5.其他

5.1 金额格式处理

方法:
FormatAmount(value, hidePrefix)
参数:

| 字段 | 类型 | 默认值 | 描述 | |------------|---------|---------|------------------------------------| | value | Number | 0 | 需要格式处理的金额 | | hidePrefix | Boolean | false | true为隐藏货币符号, false为显示货币符号 |

返回:

| 类型 | 描述 | |---------|-----------------| | String | 格式化后的金额数据 |

实例:
import { FormatAmount } from 'pms-saas-common';

let amount1 = 10000;
let amount2 = 20000;

let result1 = FormatAmount(amount1, true);
let result2 = FormatAmount(amount2, false);

console.log(result1); => '10,000.00';
console.log(result2); => '¥10,000.00';

6.微信JS-SDK-API

6.1 微信第三方授权配置

方法:
WxAuth4Vendor(appId, redirectUri, type, payload, componentAppId)
参数:

| 字段 | 类型 | 默认值 | 描述 | |--------------- |---------|---------|---------------------| | appId | String | 空字符串 | 微信公众号appId | | redirectUri | String | 空字符串 | 微信授权回调地址 | | type | String | 'base' | 微信授权类型,'base'为'snsapi_base', 'userInfo'为'snsapi_userinfo' | | payload | Object | null | 微信透传参数 | | componentAppId | String | 空字符串 | 第三方componentAppId |

返回:

| 类型 | 描述 | |---------|---------| | Object | 配置参数 |

实例:
import { WxAuth4Vendor } from 'pms-saas-common';

let appId = 'wx123';
let redirectUri = 'http://www.example.com';
let type = 'base';
let payload = '123';
let componentAppId = 'wx456';

let result = WxAuth4Vendor(appId, redirectUri, type, payload, componentAppId);

console.log(result); => 
{ 
	appid: 'wx123',
	redirect_uri: 'http://www.example.com',
	response_type: 'code',
	scope: 'snsapi_base',
	state: '123',
	component_appid: 'wx456'
};

6.2 微信公众号授权配置

方法:
WxAuth4Public(appId, redirectUri, type, payload)
参数:

| 字段 | 类型 | 默认值 | 描述 | |--------------- |---------|---------|---------------------| | appId | String | 空字符串 | 微信公众号appId | | redirectUri | String | 空字符串 | 微信授权回调地址 | | type | String | 'base' | 微信授权类型,'base'为'snsapi_base', 'userInfo'为'snsapi_userinfo' | | payload | Object | null | 微信透传参数 |

返回:

| 类型 | 描述 | |---------|---------| | Object | 配置参数 |

实例:
import { WxAuth4Public } from 'pms-saas-common';

let appId = 'wx123';
let redirectUri = 'http://www.example.com';
let type = 'base';
let payload = '123';

let result = WxAuth4Public(appId, redirectUri, type, payload);

console.log(result); => 
{ 
	appid: 'wx123',
	redirect_uri: 'http://www.example.com',
	response_type: 'code',
	scope: 'snsapi_base',
	state: '123'
};