2025-02-23 01:38:42 +01:00
import { stringTools } from '../pages/tools/string' ;
import { imageTools } from '../pages/tools/image' ;
import { DefinedTool , ToolCategory } from './defineTool' ;
2024-06-23 01:26:04 +01:00
import { capitalizeFirstLetter } from '../utils/string' ;
2025-02-23 01:38:42 +01:00
import { numberTools } from '../pages/tools/number' ;
import { videoTools } from '../pages/tools/video' ;
import { listTools } from '../pages/tools/list' ;
import { Entries } from 'type-fest' ;
2025-02-23 14:11:21 +00:00
import {
ArrangeByNumbers19Icon ,
Gif01Icon ,
HugeiconsIcon ,
LeftToRightListBulletIcon ,
Png01Icon ,
TextIcon
} from '@hugeicons/core-free-icons' ;
2024-06-22 22:06:16 +01:00
2024-06-25 03:11:48 +01:00
export const tools : DefinedTool [ ] = [
. . . imageTools ,
. . . stringTools ,
2025-02-23 14:11:21 +00:00
. . . listTools ,
2024-06-27 20:27:03 +01:00
. . . videoTools ,
2025-02-23 14:11:21 +00:00
. . . numberTools
2024-06-25 03:11:48 +01:00
] ;
2025-02-23 01:38:42 +01:00
const categoriesConfig : {
type : ToolCategory ;
value : string ;
title? : string ;
2025-02-23 14:11:21 +00:00
icon : typeof HugeiconsIcon ;
2025-02-23 01:38:42 +01:00
} [ ] = [
2024-06-23 01:26:04 +01:00
{
type : 'string' ,
2025-02-23 01:38:42 +01:00
title : 'Text' ,
2025-02-23 14:11:21 +00:00
icon : TextIcon ,
2024-06-23 01:26:04 +01:00
value :
'Tools for working with text – convert text to images, find and replace text, split text into fragments, join text lines, repeat text, and much more.'
} ,
{
type : 'png' ,
2025-02-23 14:11:21 +00:00
icon : Png01Icon ,
2024-06-23 01:26:04 +01:00
value :
'Tools for working with PNG images – convert PNGs to JPGs, create transparent PNGs, change PNG colors, crop, rotate, resize PNGs, and much more.'
2024-06-25 03:11:48 +01:00
} ,
{
type : 'number' ,
2025-02-23 14:11:21 +00:00
icon : ArrangeByNumbers19Icon ,
2024-06-25 03:11:48 +01:00
value :
'Tools for working with numbers – generate number sequences, convert numbers to words and words to numbers, sort, round, factor numbers, and much more.'
2024-06-27 12:39:38 +01:00
} ,
{
type : 'gif' ,
2025-02-23 14:11:21 +00:00
icon : Gif01Icon ,
2024-06-27 12:39:38 +01:00
value :
'Tools for working with GIF animations – create transparent GIFs, extract GIF frames, add text to GIF, crop, rotate, reverse GIFs, and much more.'
2024-06-27 20:27:03 +01:00
} ,
{
type : 'list' ,
2025-02-23 14:11:21 +00:00
icon : LeftToRightListBulletIcon ,
2024-06-27 20:27:03 +01:00
value :
'Tools for working with lists – sort, reverse, randomize lists, find unique and duplicate list items, change list item separators, and much more.'
2024-06-23 01:26:04 +01:00
}
] ;
2024-06-22 23:31:00 +01:00
export const filterTools = (
tools : DefinedTool [ ] ,
query : string
) : DefinedTool [ ] = > {
if ( ! query ) return tools ;
const lowerCaseQuery = query . toLowerCase ( ) ;
return tools . filter (
( tool ) = >
tool . name . toLowerCase ( ) . includes ( lowerCaseQuery ) ||
tool . description . toLowerCase ( ) . includes ( lowerCaseQuery ) ||
2024-06-25 08:39:29 +01:00
tool . shortDescription . toLowerCase ( ) . includes ( lowerCaseQuery ) ||
2024-06-22 23:31:00 +01:00
tool . keywords . some ( ( keyword ) = >
keyword . toLowerCase ( ) . includes ( lowerCaseQuery )
)
) ;
} ;
2024-06-23 01:26:04 +01:00
export const getToolsByCategory = ( ) : {
title : string ;
description : string ;
2025-02-23 14:11:21 +00:00
icon : typeof HugeiconsIcon ;
2024-06-23 01:26:04 +01:00
type : string ;
example : { title : string ; path : string } ;
2024-06-25 08:39:29 +01:00
tools : DefinedTool [ ] ;
2024-06-23 01:26:04 +01:00
} [ ] = > {
2025-02-23 01:38:42 +01:00
const groupedByType : Partial < Record < ToolCategory , DefinedTool [ ] > > =
Object . groupBy ( tools , ( { type } ) = > type ) ;
return ( Object . entries ( groupedByType ) as Entries < typeof groupedByType > ) . map (
( [ type , tools ] ) = > {
2025-02-23 14:11:21 +00:00
const categoryConfig = categoriesConfig . find (
( config ) = > config . type === type
) ;
2025-02-23 01:38:42 +01:00
return {
2025-02-23 14:11:21 +00:00
title : ` ${ categoryConfig ? . title ? ? capitalizeFirstLetter ( type ) } Tools ` ,
description : categoryConfig?.value ? ? '' ,
2025-02-23 01:38:42 +01:00
type ,
2025-02-23 14:11:21 +00:00
icon : categoryConfig ! . icon ,
2025-02-23 01:38:42 +01:00
tools : tools ? ? [ ] ,
example : tools
? { title : tools [ 0 ] . name , path : tools [ 0 ] . path }
: { title : '' , path : '' }
} ;
}
2024-06-23 01:26:04 +01:00
) ;
} ;