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

@qppq54s/js-utils

v0.0.3

Published

<!-- toc -->

Downloads

3

Readme

@qppq54s/js-utils 项目中常用js方法抽取

Table of Contents

clearCookies

删除指定的cookie及其所有子域的cookie。

有时候,仅仅删除一个cookie并不足够,因为某些cookie可能在多个子域中设置。 这个函数旨在彻底删除指定名称的cookie及其在所有子域中的副本。 它首先尝试直接删除cookie,然后按从具体到通用的顺序遍历子域,逐一删除。

Parameters

  • tokenName string 需要删除的cookie的名称。

parseUrlParam

解析URL参数字符串为对象

Parameters

  • paramString string URL参数字符串,例如:"key1=value1&key2=value2"

Returns Object 包含参数键值对的对象,例如:{ key1: 'value1', key2: 'value2' }

getHashParams

获取URL的哈希参数部分。

该函数用于解析当前页面URL中哈希(#)部分之后的参数。它首先从URL中提取哈希部分, 然后将这个哈希字符串传递给parseUrlParam函数进行解析,最终返回解析后的参数对象。 这对于在单页面应用中根据URL的哈希部分动态改变页面内容非常有用。

Returns Object 返回一个对象,包含解析后的哈希参数键值对。

getUrlParamByKey

获取URL查询参数的值

该函数用于从当前页面的URL中获取指定查询参数的值。它通过解析URL的查询字符串来实现。

Parameters

  • key string 需要获取值的查询参数的名称

Returns (string | undefined) 返回查询参数的值,如果参数不存在,则返回undefined

handleLogin

处理登录逻辑。 根据传入的tokenName和isDev参数,清除相关cookie,尝试从URL参数或hash参数中获取token。 如果获取到token,则将其保存到cookie中并重定向到登录后的页面。 如果在开发环境且未获取到token,则跳转到开发环境的登录页面。 如果在生产环境且未获取到token,则根据全局设置跳转到相应的登录页面。

Parameters

  • tokenName string 用于保存token的cookie名称。
  • isDev boolean 是否为开发环境,用于决定登录失败时的跳转行为。

transcoding

对代码进行编码转换。

该函数通过先对代码使用encodeURIComponent进行URL编码,然后将编码后的结果使用btoa进行Base64编码, 从而实现代码的转码。这一过程对于某些需要对代码进行安全传输或存储的场景十分有用。

Parameters

  • code string 需要进行转码的原始代码。

Returns string 返回经过URL编码和Base64编码后的字符串。

extractAddress

根据给定的完整地址字符串,提取出省、市、区和详细地址.

Parameters

  • fullAddress string 完整的地址字符串,例如"北京市朝阳区某街道123号".

Returns (object | null) 返回一个包含省、市、区和详细地址的对象,如果地址无法匹配则返回null.