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

boke-useful

v0.1.9

Published

boke useful js

Downloads

32

Readme

boke 前端的一些常用的方法的封装,文档&源码

NPM JavaScript Style Guide

安装&使用

  • 安装
// npm
npm i boke-useful --save

//yarn
yarn add boke-useful
  • 使用
import {getCookies} from 'boke-useful'
  • 非模块项目使用
  1. 下载源码;
  2. 解压并找到lib目录以及和lib同目录下的index.js,拷贝lib和index.js文件到项目目录(保持lib目录和index.js在同一目录下,可根据需求修改index.js 的文件名)。
  3. 在需要使用的地方引入index.js文件;

Api列表

cookie处理

|参数 | 说明 | 参数 | 返回值 | |---- |-----|----|---|----| |getCookies| 获取cookie| — | Obj| |setCookie|设置cookie|[name(cookieName),value(cookieValue),time(cookieExpires) ]| - | |delCookie|删除cookie|[name(cookieName)]| - |

字符串处理

|参数 | 说明 | 参数 | 返回值 | |---- |-----|----|---|----| |query| 把对象转换成get请求query参数|[Object]| string("?id=123&name=demo") |

errPass(data,empty[,usePosition])

errPass是一个错误通行证,用于解决在页面渲染的时候,因为数据格式不一致导致整个页面报错的问题;用于逻辑处理一定要加入第三个参数错误定位,方便后期的bug定位和维护

  • data <any> 元数据
  • empty <any> 期望的元数据的同类型数据的希望返回值(如果data不符和期望返回empty)
  • usePosition <number>|<string> 错误定位(调用该函数的当前位置)
import {errPass} from 'boke-useful'

let data = {a:'b'};

data.list.map(() => {

})
// 报错 list为undefined 找不到map方法

errPass(data.list,[]).map(() => {

})
// 通过

let renderText = data.name   // undefined 

let renderText = errPass(data.name,"-")  // -

jsonErrPass(data,items,hopeValue[,usePosition])

jsonErrPass是errPass对多层Json对象的一个补充;

import {jsonErrPass} from 'boke-useful'

let data = {}

let renderText = data.language['zh-CN'] ; // 报错,  language 为 undefined 不能使用language[]

let renderText = jsonErrPass(data,'language.zh-CN','-' ) // 输出 ‘-’