Skip to content

Commit

Permalink
feat: add placeKitten
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Jan 15, 2019
1 parent 5fabef0 commit 442ba11
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export { default as objectToQueryString } from './objectToQueryString'
export { default as omit } from './omit'
export { default as parseCSSValue } from './parseCSSValue'
export { default as pick } from './pick'
export { default as placeKitten } from './placeKitten'
export { default as preventEventDefault } from './preventEventDefault'
export { default as randomString } from './randomString'
export { default as range } from './range'
Expand Down
21 changes: 21 additions & 0 deletions src/placeKitten.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 获取占位图片,来自:https://placekitten.com/
*
* @param size 占位图片大小(单位: px)
* @returns 占位图片链接
*/
function placeKitten(size: number): string
/**
* 获取占位图片,来自:https://placekitten.com/
*
* @param width 占位图片宽(单位: px)
* @param height 占位图片高(单位: px)
* @returns 占位图片链接
*/
function placeKitten(width: number, height: number): string
function placeKitten(width: number, height?: number): string {
height = height || width
return `https://placekitten.com/${width}/${height}`
}

export default placeKitten
7 changes: 7 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1439,3 +1439,10 @@ describe('last', () => {
expect(vtils.last([])).toBe(undefined)
})
})

describe('placeKitten', () => {
test('ok', () => {
expect(vtils.placeKitten(100)).toMatch(/100\/100/)
expect(vtils.placeKitten(200, 100)).toMatch(/200\/100/)
})
})

0 comments on commit 442ba11

Please sign in to comment.