3 Star 54 Fork 14

Yaohaixiao / dom.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pixel.js 850 Bytes
一键复制 编辑 原始数据 按行查看 历史
import isString from './utils/types/isString'
import isNumber from './utils/types/isNumber'
/**
* CSS 单位值和数值互换
* ========================================================================
* @method pixel
* @since 1.2.0
* @param {String|Number} val
* @return {Number|String|Array|Boolean}
*/
const pixel = (val) => {
const parse = (str) => {
const value = str.replace(/\D*$/i, '')
if (value.indexOf('.') > -1) {
return Math.ceil(Number(value))
} else {
return Number(value)
}
}
if (!isString(val) && !isNumber(val)) {
return false
}
if (isString(val)) {
if (val.indexOf(' ') > -1) {
return val.split(' ').map((item) => pixel(item))
} else {
return parse(val)
}
} else {
return `${val}px`
}
}
export default pixel
JavaScript
1
https://gitee.com/yaohaixiao/dom.js.git
git@gitee.com:yaohaixiao/dom.js.git
yaohaixiao
dom.js
dom.js
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891