2024-06-23 19:57:58 +01:00
import { stringTools } from '../pages/string' ;
import { imageTools } from '../pages/image' ;
2024-06-22 23:31:00 +01:00
import { DefinedTool } from './defineTool' ;
2024-06-23 01:26:04 +01:00
import { capitalizeFirstLetter } from '../utils/string' ;
2024-06-25 03:11:48 +01:00
import { numberTools } from '../pages/number' ;
2024-06-27 12:39:38 +01:00
import { videoTools } from '../pages/video' ;
2024-06-27 20:27:03 +01:00
import { listTools } from '../pages/list' ;
2024-06-22 22:06:16 +01:00
2024-06-25 03:11:48 +01:00
export const tools : DefinedTool [ ] = [
. . . imageTools ,
. . . stringTools ,
2024-06-27 12:39:38 +01:00
. . . numberTools ,
2024-06-27 20:27:03 +01:00
. . . videoTools ,
. . . listTools
2024-06-25 03:11:48 +01:00
] ;
2024-06-23 01:26:04 +01:00
const categoriesDescriptions : { type : string ; value : string } [ ] = [
{
type : 'string' ,
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' ,
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' ,
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' ,
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' ,
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 ;
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
} [ ] = > {
const grouped : Partial < Record < string , DefinedTool [ ] > > = Object . groupBy (
tools ,
( { type } ) = > type
) ;
return Object . entries ( grouped ) . map ( ( [ type , tls ] ) = > {
return {
title : ` ${ capitalizeFirstLetter ( type ) } Tools ` ,
description :
categoriesDescriptions . find ( ( desc ) = > desc . type === type ) ? . value ? ? '' ,
type ,
2024-06-25 08:39:29 +01:00
tools : tls ? ? [ ] ,
2024-06-23 01:26:04 +01:00
example : tls
? { title : tls [ 0 ] . name , path : tls [ 0 ] . path }
: { title : '' , path : '' }
} ;
} ) ;
} ;