-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`placeKitten 表现正常: 1 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 1, 500 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/500.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 5 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 5, 3 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 9 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 9, 88.4 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/90.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 9.9 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 9.9, 100 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/100.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 10 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 10, 95 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/100.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 10.1 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 10.1, 1300.3 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/1000.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 11 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 11, 34 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/30.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 12 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 12, 56 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/10/60.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 16 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/20/20.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 16, 90 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/20/90.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 121 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/120/120.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 121, 220 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/120/220.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 500.44 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/500/500.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 500.44, 778 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/500/780.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 999 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/1000/1000.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 999, 1 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/1000/10.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 1000 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/1000/1000.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 1000, 45 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/1000/50.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 1200 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/1000/1000.jpg"`; | ||
|
||
exports[`placeKitten 表现正常: 1200, 60 1`] = `"https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/1000/60.jpg"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { placeKitten } from './placeKitten' | ||
|
||
describe('placeKitten', () => { | ||
test('表现正常', () => { | ||
expect(placeKitten(1)).toMatchSnapshot('1') | ||
expect(placeKitten(5)).toMatchSnapshot('5') | ||
expect(placeKitten(9)).toMatchSnapshot('9') | ||
expect(placeKitten(9.9)).toMatchSnapshot('9.9') | ||
expect(placeKitten(10)).toMatchSnapshot('10') | ||
expect(placeKitten(10.1)).toMatchSnapshot('10.1') | ||
expect(placeKitten(11)).toMatchSnapshot('11') | ||
expect(placeKitten(12)).toMatchSnapshot('12') | ||
expect(placeKitten(16)).toMatchSnapshot('16') | ||
expect(placeKitten(121)).toMatchSnapshot('121') | ||
expect(placeKitten(500.44)).toMatchSnapshot('500.44') | ||
expect(placeKitten(999)).toMatchSnapshot('999') | ||
expect(placeKitten(1000)).toMatchSnapshot('1000') | ||
expect(placeKitten(1200)).toMatchSnapshot('1200') | ||
expect(placeKitten(1, 500)).toMatchSnapshot('1, 500') | ||
expect(placeKitten(5, 3)).toMatchSnapshot('5, 3') | ||
expect(placeKitten(9, 88.4)).toMatchSnapshot('9, 88.4') | ||
expect(placeKitten(9.9, 100)).toMatchSnapshot('9.9, 100') | ||
expect(placeKitten(10, 95)).toMatchSnapshot('10, 95') | ||
expect(placeKitten(10.1, 1300.3)).toMatchSnapshot('10.1, 1300.3') | ||
expect(placeKitten(11, 34)).toMatchSnapshot('11, 34') | ||
expect(placeKitten(12, 56)).toMatchSnapshot('12, 56') | ||
expect(placeKitten(16, 90)).toMatchSnapshot('16, 90') | ||
expect(placeKitten(121, 220)).toMatchSnapshot('121, 220') | ||
expect(placeKitten(500.44, 778)).toMatchSnapshot('500.44, 778') | ||
expect(placeKitten(999, 1)).toMatchSnapshot('999, 1') | ||
expect(placeKitten(1000, 45)).toMatchSnapshot('1000, 45') | ||
expect(placeKitten(1200, 60)).toMatchSnapshot('1200, 60') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function getAvaliableSize(size: number): number { | ||
return Math.min(1000, Math.max(10, Math.round(size / 10) * 10)) | ||
} | ||
|
||
/** | ||
* 给定大小获取占位猫咪图片。 | ||
* | ||
* @param size 大小 | ||
* @returns 返回占位图地址 | ||
*/ | ||
export function placeKitten(size: number): string | ||
|
||
/** | ||
* 给定宽高获取占位猫咪图片。 | ||
* | ||
* @param width 宽度 | ||
* @param height 高度 | ||
* @returns 返回占位图地址 | ||
*/ | ||
export function placeKitten(width: number, height: number): string | ||
|
||
export function placeKitten(width: number, height?: number): string { | ||
height = height ?? width | ||
width = getAvaliableSize(width) | ||
height = getAvaliableSize(height) | ||
return `https://cdn.jsdelivr.net/gh/fjc0k/placekitten/images/${width}/${height}.jpg` | ||
} |