1.0.24 • Published 2 years ago

fancy-tool v1.0.24

Weekly downloads
25
License
ISC
Repository
gitlab
Last release
2 years ago

关于fancy-tool

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,
});
1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.11

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago