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

fancy-tool

v1.0.24

Published

fancy-tool用来封装一些可以在不同团队或项目中使用的一些共同方法或共同模块。

Downloads

27

Readme

关于fancy-tool

fancy-tool用来封装一些可以在不同团队或项目中使用的一些共通方法或共通模块。

项目地址

  • npm 仓库:https://www.npmjs.com/package/fancy-tool

  • gitlab 仓库: https://gitlab.wks.wistron.com.cn/mld700/fancy-tool

安装

npm install fancy-tool

加入我们

JOIN US

contents

TransformNumber

主要用于数值的转换

parameters

  • ROUND:四舍五入取整
  • *100:乘以100
  • %:添加百分号
  • .1:保留一位小数
  • .2:保留两位小数
  • .3:保留三位小数
  • /12:除以12
  • THOUSAND:千分位形式
  • SYMBOL:添加正号或负号

examples

// 在 .js 文件中引入
var transformNumber = require('fancy-tool').TransformNumber;

// 在 .ts 文件中引入
import { TransformNumber } from 'fancty-tool/index';

// 保留1位小数      输出:1.2
transformNumber.transform('1.234', '.1');
transformNumber.transform('1.234#.1');

// 多个参数可以逗号分隔,循环处理,注意参数的顺序
// 转换为百分比     输出:45%
transformNumber.transform('0.45', '*100,%');
transformNumber.transform('0.45#*100,%');

// 数字后紧跟的参数拥有最高优先级
transformNumber.transform('1.2345#.1', '.3'); // 输出:1.2
transformNumber.transform('36#/12', '*100'); // 输出:3

AppModels

封装前端访问loopback模型Restful API的常用方法

import/require

// 在 .js 文件引入
var appModels = require('fancy-tool').AppModels;

// 在 .ts 文件引入
import { AppModels } from 'fancy-tool/index';

appInit

初始化AppModels实例

AppModels.appInit({
    baseURL: 'http://xxx.xxx.com/api', // 必填
    headers: { // 选填
        ...
    }
});

about filter

更多使用方式可以参考:https://loopback.io/doc/en/lb3/Querying-data.html

find

从数据库中查找与筛选器匹配所有模型实例

成功返回:[{...}, {...}, ...]

失败返回:[]

// 查询 Users 表中所有记录
AppModels.find('Users').then(res=>{
	console.log(res);
});

// 使用筛选器查询
AppModels.find('Users', {
    where: {
        name: 'jack',
        age: 18,
    }
});

// 使用筛选器过滤指定字段
AppModels.find('Users', {
    fields: {
        name: true,
        age: true,
    }
});

update

从数据库中更新与筛选器匹配的模型实例

成功返回:更新的记录数

失败返回:-1

AppModels.update('Users', {
    id: 1,
}, {
    name: 'jack',
    age: 18,
});

count

统计数据库中与筛选器匹配的模型实例个数

成功返回:匹配的记录数

失败返回:-1

AppModels.count('Users', {
    name: 'jack',
    age: 18,
});

insert

创建新的模型实例并保存到数据库中,新的模型实例中不要包含id字段

成功返回:插入的记录实例, { id: xx, ... }

失败返回:null

AppModels.insert('Users', {
    name: 'jack',
    age: 18,
});

exists

根据主键id检查数据库中是否存在模型实例

成功返回:true/false

失败返回:null

AppModels.exist('Users', 1);

replaceById

根据主键id替换数据库中的模型实例,主键id不可替换

成功返回:替换的记录实例, { id: xx, ... }

失败返回:null

AppModels.replaceById('Users', 1, {
    name: 'jack',
    age: 18,
});