js type automatic conversion
js type automatic conversion
String & Number
`255` < 16;
false
`15` < 16;
true
`25` < 16;
false
`15` + 16;
"1516"
`15` * 16;
240
`15` - 16;
-1
`15` / 16;
0.9375
demo
function rgb2hex (sRGB = 'rgb(255, 255, 255)') {
const regex = /^(rgb|RGB)\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)/;
if(!regex.test(sRGB)){
return sRGB;
}else {
function hex(str) {
// string < number ️
return str < 16 ? "0" + Number(str).toString(16) : Number(str).toString(16);
}
return sRGB.replace(regex, function(a, c, r, g, b){
console.log(`a, c`, a, c);
console.log(`r, g, b`, r, g, b);
console.log(`typeof r, typeof g, typeof b`, typeof r, typeof g, typeof b);
// console.log(`a, c, r, g, b`, a, c, r, g, b);
return "#" + hex(r) + hex(g) + hex(b);
})
}
}
// OK
/^(rgb|RGB)\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)/

// Error
/^rgb\([\s*\d+,]{2}[\s*\d+]{1}\)$/

refs
https://regexper.com/#%2F^(rgb|RGB)\((\d{1%2C3})%2C\s%28%5Cd%7B1%2C3%7D%29%2C%5Cs%28%5Cd%7B1%2C3%7D%29%5C%29%2F
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
js type automatic conversion的更多相关文章
- cube.js 学习(七)cube.js type 以及format 说明
cube.js 对于measure以及dimension 提供了丰富的数据类型,基本满足我们常见应用的开发,同时对于不同类型也提供了 格式化的操作 measure类型 number 格式 purc ...
- js type
js中的数据类型有undefined,boolean,number,string,object等5种,前4种为原始类型,第5种为引用类型. new Object() functionundefined ...
- js 实现 input type="file" 文件上传示例代码
在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...
- [置顶] js 实现 <input type="file" /> 文件上传
在开发中,文件上传必不可少,<input type="file" /> 是常用的上传标签,但是它长得又丑.浏览的字样不能换,我们一般会用让,<input type ...
- Refused to execute script from '....js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.md
目录 问题描述 解决过程 总结 问题描述 在整合 Spring Boot.Spring Security.Thymeleaf 的练习中,对页面进行调试时,发现如下错误提示: Refused to ex ...
- how to check SVG type in js
how to check SVG type in js SVGSVGElement & SVGElement svg = document.querySelector(`svg`); // & ...
- 每天一个JS 小demo之韩雪冬轮播图。主要知识点:html,css布局,对于数组和对象的理解和运用
@charset "utf-8"; /* CSS Document */ ;; } li { list-style: none; } img { border: none; } b ...
- 在线PDF的实现 纯js
/// <summary> /// 使用微软的TransmitFile下载文件 /// </summary> /// <param name="filePath ...
- 利用snowfall.jquery.js实现爱心满屏飞
小颖在上一篇一步一步教你用CSS画爱心中已经分享一种画爱心的方法,这次再分享一种方法用css画爱心,并利用snowfall.jquery.js实现爱心满屏飞的效果. 第一步: 利用伪元素before和 ...
随机推荐
- 架构风格 vs. 架构模式 vs. 设计模式(译)
4.架构风格 vs. 架构模式 vs. 设计模式(译) - 简书 https://www.jianshu.com/p/d8dce27f279f
- How to kill go routine?
How to kill go routine? https://stackoverflow.com/questions/37997608/kill-a-method-in-an-infinite-lo ...
- Linux常用命令:文件操作命令
Linux系统命令主要包括文件操作.网络命令和性能命令,本文介绍常用文件操作命令. 修改文件属性 文件类型: 普通文件:- 目录文件:d 块设备文件:b,硬盘 字符设备: c,串行端口的接口设备,例如 ...
- H3C交换机端口聚合配置
1.接入交换机: interface Ten-GigabitEthernet1/0/21 port link-mode bridge port link-type trunk port trunk p ...
- (3)UNIX/Linux系统结构
UNIX/Linux 系统可以粗糙地抽象为 3 个层次,如图所示.底层是 UNIX/Linux 操作系统,即系统内核(Kernel):中间层是Shell层,即命令解释层:高层则是应用层. 1) 内核层 ...
- 牛客练习赛64 D【容斥+背包】
牛客练习赛64 D.宝石装箱 Description \(n\)颗宝石装进\(n\)个箱子使得每个箱子中都有一颗宝石.第\(i\)颗宝石不能装入第\(a_i\)个箱子.求合法的装箱方案对\(99824 ...
- P2617 Dynamic Rankings (动态开点权值线段树 + 树状数组)
题意:带修求区间k小 题解:回忆在使用主席树求区间k小时 利用前缀和的思想 既然是前缀和 那么我们可以使用更擅长维护前缀和的树状数组 但是这里每一颗权值线段树就不是带版本的 而是维护数组里i号点的权值 ...
- hdu5432Rikka with Array (数位dp+十进制转化为二进制)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- LA3902 Network (树上dfs)
题目链接:点击打开链接 题意:n台机器连成一个树状网络,其中叶节点是客户端,其他节点是服务器,目前有一台服务器s正在提供服务.让你在其他服务器上也安排同样的服务,使得每台客户端到最近服务器的距离不超过 ...
- hdu5637 Transform (bfs+预处理)
Problem Description A list of n integers are given. For an integer x you can do the following operat ...