+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/utils/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @returns {Number}
*/
export function toInt (value) {
return parseInt(value)
return parseInt(value) || 0
}

/**
Expand All @@ -17,7 +17,7 @@ export function toInt (value) {
* @returns {Number}
*/
export function toFloat (value) {
return parseFloat(value)
return parseFloat(value) || 0
}

/**
Expand All @@ -40,7 +40,6 @@ export function isString (value) {
*/
export function isObject (value) {
let type = typeof value

return type === 'function' || type === 'object' && !!value // eslint-disable-line no-mixed-operators
}

Expand Down
9 changes: 5 additions & 4 deletions tests/unit/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
} from '../../src/utils/unit'

describe('Function', () => {
test('`toInt` should covert entered value in various formats to actual width number', () => {
expect(toInt(1, 100)).toBe(1)
expect(toInt('1', 100)).toBe(1)
expect(toInt('1px', 100)).toBe(1)
test('`toInt` should covert entered value in various formats to actual number', () => {
expect(toInt(1)).toBe(1)
expect(toInt('1')).toBe(1)
expect(toInt('1px')).toBe(1)
expect(toInt(null)).toBe(0)
})

test('`isString` return `true` on valid string', () => {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载