1 Star 0 Fork 0

Kagol / ktools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

KTools

前端工具库

API

  • chunk 数组分块
  • hex2rgb 十六进制颜色转十进制颜色
  • isColor 判断是否是十六进制颜色值
  • isPlainObject 判断是否是对象类型
  • rgb2hex 十进制颜色转十六进制颜色
  • stairStepAccessTable 阶梯访问表

本地开发

npm start

打包

npm run build

安装

npm i @kagol/ktools

使用

import { 
  chunk,
  hex2rgb,
  isColor,
  isPlainObject,
  rgb2hex,
  stairStepAccessTable,
} from '@kagol/ktools';

console.log('chunked array:', chunk('7bc96f', 2)); // [['7', 'b'], ['c', '9'], ['6', 'f']]
console.log('rgb:', hex2rgb('#7bc96f')); // rgb(123, 201, 111)
console.log('isColor(#7bc96f):', isColor('#7bc96f')); // true
console.log('isColor(#7bc9):', isColor('#7bc9')); // false
console.log('isPlainObject:', isPlainObject({ '6': '#7bc96f' }));
const rgb = [12, 48, 120];
console.log('hex:', rgb2hex(...rgb));

// 案例1
/**
 * 规则:
 * 0: '#ebedf0'
 * 1-3: '#c6e48b'
 * 4-6: '#7bc96f'
 * 7-9: '#239a3b'
 * >=10: '#196127'
 *  */
const contributionNum = 7;
const contributionRangeArray = [ 0, 3, 6, 9, 10 ];
const colorArray = [ '#ebedf0', '#c6e48b', '#7bc96f', '#239a3b', '#196127' ];
const color = stairStepAccessTable(contributionNum, contributionRangeArray, colorArray);
console.log('color:', color); // '#239a3b'

// 案例2(来自《代码大全》)
const studentScore = 88;
const rangeLimit = [ 50.0, 65.0, 75.0, 90.0, 100.0 ];
const grade = [ 'F', 'D', 'C', 'B', 'A' ];
const score = stairStepAccessTable(studentScore, rangeLimit, grade);
console.log('score:', score); // B

示例

cd demo
anywhere

浏览器访问

http://127.0.0.1:8000/

MIT License Copyright (c) 2020 Kagol Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

前端工具库 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/kagol/ktools.git
git@gitee.com:kagol/ktools.git
kagol
ktools
ktools
master

搜索帮助