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

brt-utils

v1.2.1

Published

bright beacon

Downloads

13

Readme

brt-utils

智石科技(bright beacon) javascript util库。

NPM 安装

# npm install brt-utils -g

CDN 引入

<script src="//map.brtbeacon.net/js-sdk/plugin/brt-utils.js"></script>

使用

import bUtil from 'brt-utils';


// 获取终端基本信息
bUtil.GetSystem();	// {platform, version, brand, env}

// 获取运行平台信息
bUtil.GetEnv()		// wechat、 alipay、 devapp

// 更多
...

API

  • request

    XMLHttpRequest 网络请求, 返回 Promise

    示例
    bUtil.request(options:Object).then(res => {}).catch(err => {});
    Options

    | 属性 | 类型 | 默认值 | 必填 | 说明 | | ------------ | ------- | ------ | ---- | -------------- | | url | String | | 是 | 服务器接口地址 | | data | Object | {} | 否 | 请求参数 | | method | String | GET | 否 | 请求方式 | | headers | Object | {} | 否 | 扩展请求头 | | responseType | String | text | 否 | 响应的数据类型 | | contentType | String | | 否 | 返回的数据格式 | | async | Boolean | true | 否 | 同步/异步 |

    全局配置 configs
    // 全局配置
    bUtil.request.configs = {
        // 服务器地址
        baseURL: '' 
        // 请求方式
        method: 'GET' 
    }
    全局拦截器
    // 准备 发送请求前
    bUtil.request.interceptors.before(config => {
        console.log('before =>', config);
        return config;
    });
    // 请求结束后
    bUtil.request.interceptors.after(res => {
        console.log('after =>', res);
        return res;
    });
    扩展 get/post/put/delete
        
    // GET
    bUtil.request.get(url:String, data:Object, params:Object).then(res => {}).catch(err => {});
        
    // POST
    bUtil.request.post(url:String, data:Object, params:Object).then(res => {}).catch(err => {});
        
    // PUT
    bUtil.request.put(url:String, data:Object, params:Object).then(res => {}).catch(err => {});
        
    // DELETE
    bUtil.request.delete(url:String, data:Object, params:Object).then(res => {}).catch(err => {});
        
  • EventListener

    自定义Event事件监听

    示例
    // 扩展 Event 事件
    class Test extends bUtil.EventListener {
        constructor () {
            super();
                
            // 绑定
            this.on('ready', msg => {
                console.log(msg); //log ->: brt utils
            });
                
            // 触发
            this.emit('ready', 'brt utils');
                
        }
    }
    方法

    | 名称 | 功能说明 | | ---------- | -------------------------------- | | on | 绑定监听事件 | | once | 绑定监听事件(触发一次后解除绑定) | | off | 解除绑定事件 | | emit | 触发事件 | | watch | 双向绑定属性值 | | setOptions | 属性混入合并 |

  • GetParams

    获取链接url参数

    示例
    let url = '//ip:8080?name=张三&age=23';
        
    // name
    let name = bUtil.GetParams(url, 'name'); // log ->: 张三
        
    // age
    let age = bUtil.GetParams(url, 'age'); // log ->: 23
        
    默认 location.href
    // href
    location.href = '//ip:8080?name=张三&age=23';
        
    // name
    let name = bUtil.GetParams('name'); // log ->: 张三
        
    // age
    let age = bUtil.GetParams('age'); // log ->: 23
        
  • GetSystem

    获取终端基础信息 返回 Object

    示例
    bUtil.GetSystem(); //{platform, version, brand, env}
  • GetEnv

    获取运行平台 返回 String

    示例
    bUtil.GetEnv()	// wechat(微信端)、 alipay(支付宝端)、 devapp(其他APP)
  • ColorMix

    颜色混合函数

    参数1:16 进制颜色码

    参数2:16进制颜色码

    参数3:混合比例 0 - 1

    示例
    // 蓝色与白色混合 20% 
    bUtil.ColorMix('#0099FF', '#FFFFFF', 0.2);
  • ColorFade

    颜色淡化函数

    参数1:16 进制颜色码

    参数2:透明度 0 - 1

    示例
    // 透明度 20% 
    bUtil.ColorFade('#0099FF', 0.2);
  • RandomString

    随机字符串

    参数: 位数 (默认16位)

    示例
    // 随机32位的字符串
    bUtil.RandomString(32);
  • DateFormat

    日期格式化

    示例
    // 扩展原型链方式
    Date.prototype.format = bUtil.DateFormat;
    // 调用
    new Date().format('YYYY/MM/DD HH:mm:ss');
        
        
    // 普通方式使用
    bUtil.DateFormat(new Date(), 'YYYY/MM/DD HH:mm:ss');
        
  • Math

    计算两点之间的常用算法。

    - Distance
    // 计算两点的距离 (墨卡托坐标)
    bUtil.Math.Distance({x: 1, y: 1}, {x: 10, y: 10});  //  12.72
    - LngLatDistance
    // 计算两点的距离 (经纬度坐标)
    bUtil.Math.LngLatDistance({lng: 1, lat: 1}, {lng: 10, lat: 10});
    - Angle
    // 计算两点的角度(顺时针)
    bUtil.Math.Angle({x: 1, y: 1}, {x: 10, y: 10}); //  45°
    - IntersectionPoint
    // 计算点到线的交叉点(吸附点/最近点)
    let pos = {x: 1, y: 5};
    let line1 = {x: 1, y: 1};
    let line2 = {x: 10, y: 10};
        
    bUtil.Math.IntersectionPoint(pos, line1, line2); //  {x: 3, y: 3}
    - RatioPoint
    // 计算两点之间 指定比例的点
    bUtil.Math.RatioPoint({x: 1, y: 1}, {x: 10, y: 10}, 0.2); // {x: 2.8, y: 2.8}
    - AdvancePointByAngle
    // 计算点 朝指定方向和距离 偏移的点 
     bUtil.Math.AdvancePointByAngle({x: 1, y: 1}, 45, 5); //  {x: 4.53, y: 4.53}
    - LineIntersect
    // 计算两个线段的交集点(交叉点)
     bUtil.Math.LineIntersect([{x: 1, y: 1}, {x: 5, y: 5}], [{x: 5, y: 1}, {x: 1, y: 5}]);
  • Coord

    坐标转换 支持WGS84 (GPS/Google)、GCJ02(高德、腾讯)、BD09(百度) 之间的转换

    示例
    // GCJ02 to WGS84
    bUtil.Coord.GCJ02ToWGS84(longitude, latitude);
        
    // WGS84 to GCJ02
    bUtil.Coord.WGS84ToGCJ02(longitude, latitude);
        
    // BD09 to WGS84
    bUtil.Coord.BD09ToWGS84(longitude, latitude);
        
    // WGS84 to BD09
    bUtil.Coord.WGS84ToBD09(longitude, latitude);
        
    // GCJ02 to BD09
    bUtil.Coord.GCJ02ToBD09(longitude, latitude);
        
    // BD09 to GCJ02
    bUtil.Coord.BD09ToGCJ02(longitude, latitude);
        
    方法

    | 名称 | 功能说明 | | - | --- | | GCJ02ToWGS84 | GCJ02转换WGS84 | | WGS84ToGCJ02 | WGS84转换GCJ02 | | BD09ToWGS84 | BD09转换WGS84 | | WGS84ToBD09 | WGS84转换BD09 | | GCJ02ToBD09 | GCJ02转换BD09 | | BD09ToGCJ02 | BD09转换GCJ02 |

  • ClassMix

    es6 语法,class继承扩展语法

    示例
    // base
    class Base {
        constructor () {}
    }
        
    // source
    class Source {
        constructor () {}
    }
        
    // 同时继承2个以上的类
    class Test ClassMix(Base, Source) {
        constructor () {}
    }