🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

sr-utils-web

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sr-utils-web

电商场景下,常用基础工具函数集合。

latest
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

电商场景下,常用基础工具函数集合。

sr-utils-base 文档地址{target=_blank}

1、web 版方法

1.1 storage (memory ,localStorage,sessionStorage)

  说明:数据存储
  例子

\_.storage.localStorage.get('key');
// =>value

\_.storage.localStorage.set('key','value');

1.2 genClassFactory

  说明:方便写前缀 class
  使用说明

const genClass = genClassFactory('card');
export const CardName = () => <div className={genClass('name')} />; // <div className='card-name' />
export const CardBody = () => <div className={genClass('head', 'bold')} />; // <div className='card-head card-bold' />

1.3 getImageSize

  说明:获取图片的宽高
  参数
    url (string): 图片地址
  返回
    (obj): 图片的宽高数据
  例子

\_.getImageSize(srcUrl).then(({ width, height }) => {console.log(width, height)})
// => 300,400

1.4 isMobile

  说明:是否是移动设备
  参数
    无
  返回
    (boolean): 是否是移动涉笔
  例子

\_.isMobile();
// => true

1.5 getFeatureFromCookie

  说明:根据 cookieStr 获取 value
  参数
     (string) name 需要获取的 cookie
  返回
    (string): 获取到的值
  例子

\_.getFeatureFromCookie('key');
// => value

1.6 setValueByCookie

  说明:设置 cookie 某个值的过期时间
  参数
     (string) name 需要设置的 cookie
     (string) value 设置的 cookie 的值
     (number) [time = 30] 过期时间
  例子

\_.setValueByCookie('key','value',20);

1.7 getExpiresTime

  说明:获取 n 天前后的 cookie 过期时间
  参数
     (number) time 多少天
     (string) [type='after'] time 天前还是后 after|before
  返回
    (string): 过期时间
  例子

\_.getExpiresTime(2);
// => 'Sat, 31 Dec 2022 02:49:38 GMT'

FAQs

Package last updated on 29 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts