Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.1 #4

Merged
merged 64 commits into from
Feb 25, 2024
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b9c36d3
all tests with mode + tiles
crisconru Jul 12, 2022
dcb2336
integrate mode into tiles property
crisconru Jul 13, 2022
9d2282f
tested output data
crisconru Jul 13, 2022
2107bdb
Output options - parse data + path
crisconru Jul 15, 2022
0aa3a55
test name but not if it is an invalid os filename
crisconru Jul 17, 2022
63476bb
parse extension and tested
crisconru Jul 17, 2022
648b0d3
Complete tested filename without dependencies
crisconru Jul 22, 2022
0cd15cb
all splitea almost tested. Needs unique and store
crisconru Aug 28, 2022
6b36d01
test uniques completed
crisconru Oct 9, 2022
651ba7a
updating deps
crisconru Aug 3, 2023
e3b9b2c
changing jest for vitest
crisconru Aug 3, 2023
6f1638e
typescript config
crisconru Aug 3, 2023
d80b752
vitest
crisconru Aug 3, 2023
867b015
main repo files
crisconru Aug 3, 2023
a3ddd94
state of the art, tests are passing
crisconru Aug 3, 2023
562413d
update github actions
crisconru Aug 3, 2023
5bb14d5
removed lint
crisconru Aug 3, 2023
23ee44d
publish just with node 18
crisconru Aug 3, 2023
57e7c45
zod added
crisconru Aug 6, 2023
3796174
options to editorconfig
crisconru Aug 6, 2023
e21f871
added zod to project and removed parsers
crisconru Aug 6, 2023
5b96d30
reorder files and check tiles completed
crisconru Aug 6, 2023
1696115
checktiles tested
crisconru Aug 6, 2023
1e0c9e1
refactor testing
crisconru Aug 6, 2023
6e1e425
extracting unique logic to image file
crisconru Aug 6, 2023
464ecc3
output tested
crisconru Aug 7, 2023
8bd633b
utils tested
crisconru Aug 7, 2023
10ea42a
types with schemas
crisconru Aug 7, 2023
ac4be2c
refactor tiles to not operate with jimp
crisconru Aug 10, 2023
67a0c37
jimp operations moved to image.ts
crisconru Aug 10, 2023
86cda71
tested image
crisconru Aug 15, 2023
624bf45
tested tiles
crisconru Aug 15, 2023
97f9aec
output tested
crisconru Aug 15, 2023
46e4c66
create path if not exists
crisconru Aug 15, 2023
f6648b7
moving check logic to schemas
crisconru Sep 2, 2023
45db614
adding logic to schemas for tiles cut
crisconru Sep 3, 2023
9191ae6
tiles full tested and independant from images
crisconru Sep 3, 2023
edca669
images tested completely
crisconru Sep 3, 2023
a8e1619
tested Output schemas
crisconru Sep 3, 2023
8b96c51
tested output schemas
crisconru Sep 3, 2023
4bc475d
output completely tested
crisconru Sep 3, 2023
0b42301
fix types to remove temp folders + files
crisconru Sep 3, 2023
7510ee9
migrated schemas and types to valibot from zod
crisconru Feb 23, 2024
5a349fd
set ts options
crisconru Feb 23, 2024
2a4b9b7
removing build from repo
crisconru Feb 23, 2024
4cd6e7b
deleted unnecessary files
crisconru Feb 23, 2024
7e3c46c
removed build
crisconru Feb 23, 2024
8975758
tests passed
crisconru Feb 23, 2024
48974b8
add better error msg if it is a valibot error
crisconru Feb 25, 2024
3425bfc
schemas tested
crisconru Feb 25, 2024
1774191
image tested
crisconru Feb 25, 2024
20d83e2
output tested
crisconru Feb 25, 2024
1604006
splitea tested
crisconru Feb 25, 2024
31d4229
forgot to commit before
crisconru Feb 25, 2024
ced92f6
tiles tested
crisconru Feb 25, 2024
188e950
named export instead of default
crisconru Feb 25, 2024
009ab63
changed deprecated nodejs rmdir to rm
crisconru Feb 25, 2024
8f7b99f
adding better error
crisconru Feb 25, 2024
7892fde
refactor to pass the build
crisconru Feb 25, 2024
5e7d03c
adding types to filename-reserved-regex
crisconru Feb 25, 2024
1349d83
removed enable option in output.unique because is too redundant
crisconru Feb 25, 2024
429f619
full readme with final api
crisconru Feb 25, 2024
a4672a9
non node lts deprecated versions
crisconru Feb 25, 2024
337d641
alpha version is ready
crisconru Feb 25, 2024
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
Prev Previous commit
Next Next commit
checktiles tested
crisconru committed Aug 6, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 16961151f52cf6a0cbc806b90b8bddae481e3b91
2 changes: 1 addition & 1 deletion src/splitea.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ export const Splitea = async (image: Image, tiles: Tiles, output?: Output): Prom
checkTiles(tiles, size)
parseOutput(output)
// 3. Get the tiles
const newTiles = getTiles(img, size, tiles) as Jimp[]
const newTiles = getTiles(img, size, tiles)
// 4. Get the output
// 5. Return solution
// Check tiles options
9 changes: 7 additions & 2 deletions src/tiles/horizontal.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import Jimp from "jimp"
import { Image, Size } from "../types"
import { HorizontalTiles, Image, Size } from "../types"
import { SpliteaError, throwError } from "../errors"
import { getSplitImage } from "../image"
import { isSubmultiple } from "../utils"

export const checkModeHorizontal = (columns: number, width: number, size: Size): void => {
export const checkHorizontalTiles = (tiles: HorizontalTiles, size: Size): void => {
const { columns, width } = tiles
// At least Columns or Width is non zero
if (columns === 0 && width === 0) {
const msg = 'you need to provide one natural number, columns or width (px)'
throw new SpliteaError(msg)
}
// Just Columns or Width but not both
if (columns > 0 && width > 0) {
throw new SpliteaError(`You have to enter columns or width, but not both`)
}
// Image Width is multiple of Columns
if (columns > 0 && !isSubmultiple(size.width, columns)) {
throw new SpliteaError(`columns (${columns}) have to be a submultiple of ${size.width} px`)
9 changes: 7 additions & 2 deletions src/tiles/vertical.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import Jimp from "jimp"
import { Image, Size } from "../types"
import { Image, Size, VerticalTiles } from "../types"
import { SpliteaError, throwError } from "../errors"
import { getSplitImage } from "../image"
import { isSubmultiple } from "../utils"

export const checkModeVertical = (rows: number, height: number, size: Size): void => {
export const checkVerticalTiles = (tiles: VerticalTiles, size: Size): void => {
const { rows, height } = tiles
// At least Rows or Height is non zero
if (rows === 0 && height === 0) {
const msg = 'you need to provide one natural number, rows or height (px)'
throw new SpliteaError(msg)
}
// Just Rows or Height but not both
if (rows > 0 && height > 0) {
throw new SpliteaError(`You have to enter rows or height, but not both`)
}
// Image Height is multiple of Rows
if (rows > 0 && !isSubmultiple(size.height, rows)) {
throw new SpliteaError(`rows (${rows}) have to be a submultiple of ${size.height} px`)
9 changes: 6 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -37,9 +37,12 @@ export const TilesSchema = z.object({
})
export type Tiles = z.infer<typeof TilesSchema>
// Modes Parser
export const HorizontalSchema = TilesSchema.pick({ columns: true, width: true })
export const VerticalSchema = TilesSchema.pick({ rows: true, height: true })
export const GridSchema = TilesSchema.pick({ rows: true, height: true })
export const HorizontalTilesSchema = TilesSchema.pick({ columns: true, width: true })
export type HorizontalTiles = z.infer<typeof HorizontalTilesSchema>
export const VerticalTilesSchema = TilesSchema.pick({ rows: true, height: true })
export type VerticalTiles = z.infer<typeof VerticalTilesSchema>
export const GridTilesSchema = TilesSchema.omit({ mode: true, unique: true })
export type GridTiles = z.infer<typeof GridTilesSchema>

/**
* 1. Data to return -> data => "buffer" | "path"
71 changes: 71 additions & 0 deletions tests/tiles/grid.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { describe, test, expect } from 'vitest'
import { GridTiles, Size } from '../../src/types'
import { SpliteaError } from '../../src/errors'
import { checkGridTiles } from '../../src/tiles/grid'

describe('Grid tiles', () => {
test('checkGridTiles', () => {
const size: Size = { width: 10, height: 15 }
const tiles: GridTiles = {} as GridTiles
// Not data
tiles.rows = 0
tiles.columns = 0
tiles.width = 0
tiles.height = 0
expect(() => checkGridTiles(tiles, size)).toThrowError(SpliteaError)
// Just rows + columns -> width and height must be 0
tiles.rows = 1
tiles.columns = 1
tiles.width = 0
tiles.height = 1
expect(() => checkGridTiles(tiles, size)).toThrowError(SpliteaError)
tiles.rows = 1
tiles.columns = 1
tiles.width = 1
tiles.height = 0
expect(() => checkGridTiles(tiles, size)).toThrowError(SpliteaError)
// Just width + height -> rows and columns must be 0
tiles.rows = 1
tiles.columns = 0
tiles.width = 1
tiles.height = 1
expect(() => checkGridTiles(tiles, size)).toThrowError(SpliteaError)
tiles.rows = 0
tiles.columns = 1
tiles.width = 1
tiles.height = 1
expect(() => checkGridTiles(tiles, size)).toThrowError(SpliteaError)
// Just rows + columns -> must be submultiple of height + width
tiles.rows = 3
tiles.columns = 3
tiles.width = 0
tiles.height = 0
expect(() => checkGridTiles(tiles, size)).toThrowError(SpliteaError)
tiles.rows = 2
tiles.columns = 3
tiles.width = 0
tiles.height = 0
expect(() => checkGridTiles(tiles, size)).toThrowError(SpliteaError)
tiles.rows = 3
tiles.columns = 2
tiles.width = 0
tiles.height = 0
expect(() => checkGridTiles(tiles, size)).not.toThrowError(SpliteaError)
// Just width + height -> must be submultiple of width + height
tiles.rows = 0
tiles.columns = 0
tiles.width = 3
tiles.height = 3
expect(() => checkGridTiles(tiles, size)).toThrowError(SpliteaError)
tiles.rows = 0
tiles.columns = 0
tiles.width = 2
tiles.height = 2
expect(() => checkGridTiles(tiles, size)).toThrowError(SpliteaError)
tiles.rows = 0
tiles.columns = 0
tiles.width = 2
tiles.height = 3
expect(() => checkGridTiles(tiles, size)).not.toThrowError(SpliteaError)
})
})
35 changes: 35 additions & 0 deletions tests/tiles/horizontal.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, test, expect } from 'vitest'
import { HorizontalTiles, Size } from '../../src/types'
import { SpliteaError } from '../../src/errors'
import { checkHorizontalTiles } from '../../src/tiles/horizontal'

describe('Horizontal tiles', () => {
test('checkHorizontalTiles', () => {
const size: Size = { width: 10, height: 15 }
const tiles: HorizontalTiles = {} as HorizontalTiles
// Not data
tiles.columns = 0
tiles.width = 0
expect(() => checkHorizontalTiles(tiles, size)).toThrowError(SpliteaError)
// Not both data
tiles.columns = 3
tiles.width = 4
expect(() => checkHorizontalTiles(tiles, size)).toThrowError(SpliteaError)
// Invalid columns
tiles.columns = 3
tiles.width = 0
expect(() => checkHorizontalTiles(tiles, size)).toThrowError(SpliteaError)
// Valid columns
tiles.columns = 2
tiles.width = 0
expect(() => checkHorizontalTiles(tiles, size)).not.toThrowError(SpliteaError)
// Invalid width
tiles.columns = 0
tiles.width = 4
expect(() => checkHorizontalTiles(tiles, size)).toThrowError(SpliteaError)
// Valid columns
tiles.columns = 0
tiles.width = 5
expect(() => checkHorizontalTiles(tiles, size)).not.toThrowError(SpliteaError)
})
})
35 changes: 35 additions & 0 deletions tests/tiles/vertical.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, test, expect } from 'vitest'
import { Size, VerticalTiles } from '../../src/types'
import { SpliteaError } from '../../src/errors'
import { checkVerticalTiles } from '../../src/tiles/vertical'

describe('Vertical tiles', () => {
test('checkVerticalTiles', () => {
const size: Size = { width: 10, height: 15 }
const tiles: VerticalTiles = {} as VerticalTiles
// Not data
tiles.rows = 0
tiles.height = 0
expect(() => checkVerticalTiles(tiles, size)).toThrowError(SpliteaError)
// Not both data
tiles.rows = 3
tiles.height = 5
expect(() => checkVerticalTiles(tiles, size)).toThrowError(SpliteaError)
// Invalid rows
tiles.rows = 2
tiles.height = 0
expect(() => checkVerticalTiles(tiles, size)).toThrowError(SpliteaError)
// Valid rows
tiles.rows = 3
tiles.height = 0
expect(() => checkVerticalTiles(tiles, size)).not.toThrowError(SpliteaError)
// Invalid height
tiles.rows = 0
tiles.height = 4
expect(() => checkVerticalTiles(tiles, size)).toThrowError(SpliteaError)
// Valid rows
tiles.rows = 0
tiles.height = 5
expect(() => checkVerticalTiles(tiles, size)).not.toThrowError(SpliteaError)
})
})