diff --git a/.codebuddy/.gitignore b/.codebuddy/.gitignore
index 9f4c740..1db7c29 100644
--- a/.codebuddy/.gitignore
+++ b/.codebuddy/.gitignore
@@ -1 +1,2 @@
-db/
\ No newline at end of file
+db/
+docs
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index fdac9bb..2cc7269 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,17 +4,21 @@
-
+
+
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
@@ -337,14 +341,6 @@
-
-
- 1720665220407
-
-
-
- 1720665220408
-
1720730102816
@@ -729,7 +725,15 @@
1741416193639
-
+
+
+ 1741417920442
+
+
+
+ 1741417920442
+
+
@@ -788,7 +792,6 @@
-
@@ -813,7 +816,8 @@
-
+
+
diff --git a/src/components/ToolContent.tsx b/src/components/ToolContent.tsx
index bdb1864..dc6ae0e 100644
--- a/src/components/ToolContent.tsx
+++ b/src/components/ToolContent.tsx
@@ -10,7 +10,7 @@ import ToolExamples, {
} from '@components/examples/ToolExamples';
import { ToolComponentProps } from '@tools/defineTool';
-interface ToolContentPropsBase extends ToolComponentProps {
+interface ToolContentProps extends ToolComponentProps {
// Input/Output components
inputComponent: ReactNode;
resultComponent: ReactNode;
@@ -29,28 +29,15 @@ interface ToolContentPropsBase extends ToolComponentProps {
};
// Input value to pass to the compute function
- input: I;
+ input?: I;
+
+ exampleCards?: CardExampleType[];
+ setInput?: React.Dispatch>;
// Validation schema (optional)
validationSchema?: any;
}
-interface ToolContentPropsWithExamples
- extends ToolContentPropsBase {
- exampleCards: CardExampleType[];
- setInput: React.Dispatch>;
-}
-
-interface ToolContentPropsWithoutExamples
- extends ToolContentPropsBase {
- exampleCards?: never;
- setInput?: never;
-}
-
-type ToolContentProps =
- | ToolContentPropsWithExamples
- | ToolContentPropsWithoutExamples;
-
export default function ToolContent({
title,
inputComponent,
diff --git a/src/components/examples/ExampleCard.tsx b/src/components/examples/ExampleCard.tsx
index 41d0ba3..f4b1bf0 100644
--- a/src/components/examples/ExampleCard.tsx
+++ b/src/components/examples/ExampleCard.tsx
@@ -14,10 +14,10 @@ import { GetGroupsType } from '@components/options/ToolOptions';
export interface ExampleCardProps {
title: string;
description: string;
- sampleText: string;
+ sampleText?: string;
sampleResult: string;
sampleOptions: T;
- changeInputResult: (newInput: string, newOptions: T) => void;
+ changeInputResult: (newInput: string | undefined, newOptions: T) => void;
getGroups: GetGroupsType | null;
}
diff --git a/src/components/examples/ToolExamples.tsx b/src/components/examples/ToolExamples.tsx
index f541b94..84f562e 100644
--- a/src/components/examples/ToolExamples.tsx
+++ b/src/components/examples/ToolExamples.tsx
@@ -15,7 +15,7 @@ export interface ExampleProps {
exampleCards: CardExampleType[];
getGroups: GetGroupsType | null;
formRef: React.RefObject>;
- setInput: React.Dispatch>;
+ setInput?: React.Dispatch>;
}
export default function ToolExamples({
@@ -26,8 +26,8 @@ export default function ToolExamples({
formRef,
setInput
}: ExampleProps) {
- function changeInputResult(newInput: string, newOptions: T) {
- setInput(newInput);
+ function changeInputResult(newInput: string | undefined, newOptions: T) {
+ setInput?.(newInput);
formRef.current?.setValues(newOptions);
const toolsElement = document.getElementById('tool');
if (toolsElement) {
diff --git a/src/pages/tools/json/stringify/meta.ts b/src/pages/tools/json/stringify/meta.ts
index 3fda725..8c28b61 100644
--- a/src/pages/tools/json/stringify/meta.ts
+++ b/src/pages/tools/json/stringify/meta.ts
@@ -4,9 +4,18 @@ import { lazy } from 'react';
export const tool = defineTool('json', {
name: 'Stringify JSON',
path: 'stringify',
- icon: 'lets-icons:json-format-light',
- description: 'Convert JavaScript objects and arrays into their JSON string representation. Options include custom indentation and HTML character escaping for web-safe JSON strings.',
+ icon: 'ant-design:field-string-outlined',
+ description:
+ 'Convert JavaScript objects and arrays into their JSON string representation. Options include custom indentation and HTML character escaping for web-safe JSON strings.',
shortDescription: 'Convert JavaScript objects to JSON strings',
- keywords: ['stringify', 'serialize', 'convert', 'object', 'array', 'json', 'string'],
+ keywords: [
+ 'stringify',
+ 'serialize',
+ 'convert',
+ 'object',
+ 'array',
+ 'json',
+ 'string'
+ ],
component: lazy(() => import('./index'))
});
diff --git a/src/pages/tools/number/arithmetic-sequence/arithmetic-sequence.service.test.ts b/src/pages/tools/number/arithmetic-sequence/arithmetic-sequence.service.test.ts
new file mode 100644
index 0000000..5e4affe
--- /dev/null
+++ b/src/pages/tools/number/arithmetic-sequence/arithmetic-sequence.service.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from 'vitest';
+import { generateArithmeticSequence } from './service';
+
+describe('generateArithmeticSequence', () => {
+ it('should generate basic arithmetic sequence', () => {
+ const result = generateArithmeticSequence(1, 2, 5, ', ');
+ expect(result).toBe('1, 3, 5, 7, 9');
+ });
+
+ it('should handle negative first term', () => {
+ const result = generateArithmeticSequence(-5, 2, 5, ' ');
+ expect(result).toBe('-5 -3 -1 1 3');
+ });
+
+ it('should handle negative common difference', () => {
+ const result = generateArithmeticSequence(10, -2, 5, ',');
+ expect(result).toBe('10,8,6,4,2');
+ });
+
+ it('should handle decimal numbers', () => {
+ const result = generateArithmeticSequence(1.5, 0.5, 4, ' ');
+ expect(result).toBe('1.5 2 2.5 3');
+ });
+
+ it('should handle single term sequence', () => {
+ const result = generateArithmeticSequence(1, 2, 1, ',');
+ expect(result).toBe('1');
+ });
+});
diff --git a/src/pages/tools/number/arithmetic-sequence/index.tsx b/src/pages/tools/number/arithmetic-sequence/index.tsx
new file mode 100644
index 0000000..11451bd
--- /dev/null
+++ b/src/pages/tools/number/arithmetic-sequence/index.tsx
@@ -0,0 +1,136 @@
+import { Box } from '@mui/material';
+import React, { useState } from 'react';
+import ToolContent from '@components/ToolContent';
+import ToolTextResult from '@components/result/ToolTextResult';
+import TextFieldWithDesc from '@components/options/TextFieldWithDesc';
+import { generateArithmeticSequence } from './service';
+import * as Yup from 'yup';
+import { CardExampleType } from '@components/examples/ToolExamples';
+
+type InitialValuesType = {
+ firstTerm: string;
+ commonDifference: string;
+ numberOfTerms: string;
+ separator: string;
+};
+
+const initialValues: InitialValuesType = {
+ firstTerm: '1',
+ commonDifference: '2',
+ numberOfTerms: '10',
+ separator: ', '
+};
+
+const validationSchema = Yup.object({
+ firstTerm: Yup.number().required('First term is required'),
+ commonDifference: Yup.number().required('Common difference is required'),
+ numberOfTerms: Yup.number()
+ .min(1, 'Must generate at least 1 term')
+ .max(1000, 'Maximum 1000 terms allowed')
+ .required('Number of terms is required'),
+ separator: Yup.string().required('Separator is required')
+});
+
+const exampleCards: CardExampleType[] = [
+ {
+ title: 'Basic Arithmetic Sequence',
+ description:
+ 'Generate a sequence starting at 1, increasing by 2, for 5 terms',
+ sampleOptions: {
+ firstTerm: '1',
+ commonDifference: '2',
+ numberOfTerms: '5',
+ separator: ', '
+ },
+ sampleResult: '1, 3, 5, 7, 9'
+ },
+ {
+ title: 'Negative Sequence',
+ description: 'Generate a decreasing sequence starting at 10',
+ sampleOptions: {
+ firstTerm: '10',
+ commonDifference: '-3',
+ numberOfTerms: '4',
+ separator: ' → '
+ },
+ sampleResult: '10 → 7 → 4 → 1'
+ },
+ {
+ title: 'Decimal Sequence',
+ description: 'Generate a sequence with decimal numbers',
+ sampleOptions: {
+ firstTerm: '0.5',
+ commonDifference: '0.5',
+ numberOfTerms: '6',
+ separator: ' '
+ },
+ sampleResult: '0.5 1 1.5 2 2.5 3'
+ }
+];
+
+export default function ArithmeticSequence() {
+ const [result, setResult] = useState('');
+
+ return (
+
+ }
+ initialValues={initialValues}
+ validationSchema={validationSchema}
+ exampleCards={exampleCards}
+ toolInfo={{
+ title: 'What is an Arithmetic Sequence?',
+ description:
+ 'An arithmetic sequence is a sequence of numbers where the difference between each consecutive term is constant. This constant difference is called the common difference. Given the first term (a₁) and the common difference (d), each term can be found by adding the common difference to the previous term.'
+ }}
+ getGroups={({ values, updateField }) => [
+ {
+ title: 'Sequence Parameters',
+ component: (
+
+ updateField('firstTerm', val)}
+ type="number"
+ />
+ updateField('commonDifference', val)}
+ type="number"
+ />
+ updateField('numberOfTerms', val)}
+ type="number"
+ />
+
+ )
+ },
+ {
+ title: 'Output Format',
+ component: (
+ updateField('separator', val)}
+ />
+ )
+ }
+ ]}
+ compute={(values) => {
+ const sequence = generateArithmeticSequence(
+ Number(values.firstTerm),
+ Number(values.commonDifference),
+ Number(values.numberOfTerms),
+ values.separator
+ );
+ setResult(sequence);
+ }}
+ />
+ );
+}
diff --git a/src/pages/tools/number/arithmetic-sequence/meta.ts b/src/pages/tools/number/arithmetic-sequence/meta.ts
new file mode 100644
index 0000000..2423600
--- /dev/null
+++ b/src/pages/tools/number/arithmetic-sequence/meta.ts
@@ -0,0 +1,21 @@
+import { defineTool } from '@tools/defineTool';
+import { lazy } from 'react';
+
+export const tool = defineTool('number', {
+ name: 'Generate Arithmetic Sequence',
+ path: 'arithmetic-sequence',
+ icon: 'ic:sharp-plus',
+ description:
+ 'Generate an arithmetic sequence by specifying the first term (a₁), common difference (d), and number of terms (n). The tool creates a sequence where each number differs from the previous by a constant difference.',
+ shortDescription:
+ 'Generate a sequence where each term differs by a constant value.',
+ keywords: [
+ 'arithmetic',
+ 'sequence',
+ 'progression',
+ 'numbers',
+ 'series',
+ 'generate'
+ ],
+ component: lazy(() => import('./index'))
+});
diff --git a/src/pages/tools/number/arithmetic-sequence/service.ts b/src/pages/tools/number/arithmetic-sequence/service.ts
new file mode 100644
index 0000000..467260a
--- /dev/null
+++ b/src/pages/tools/number/arithmetic-sequence/service.ts
@@ -0,0 +1,13 @@
+export function generateArithmeticSequence(
+ firstTerm: number,
+ commonDifference: number,
+ numberOfTerms: number,
+ separator: string
+): string {
+ const sequence: number[] = [];
+ for (let i = 0; i < numberOfTerms; i++) {
+ const term = firstTerm + i * commonDifference;
+ sequence.push(term);
+ }
+ return sequence.join(separator);
+}
diff --git a/src/pages/tools/number/index.ts b/src/pages/tools/number/index.ts
index 51564fe..c2ca546 100644
--- a/src/pages/tools/number/index.ts
+++ b/src/pages/tools/number/index.ts
@@ -1,4 +1,5 @@
import { tool as numberSum } from './sum/meta';
import { tool as numberGenerate } from './generate/meta';
+import { tool as numberArithmeticSequence } from './arithmetic-sequence/meta';
-export const numberTools = [numberSum, numberGenerate];
+export const numberTools = [numberSum, numberGenerate, numberArithmeticSequence];