From 8a21e1dc7d039e4138502d9157115a83b2933bfa Mon Sep 17 00:00:00 2001 From: Guillaume Date: Mon, 8 Apr 2024 14:11:12 +0200 Subject: [PATCH] Add string length tool --- pages/tools/index.tsx | 17 ++++- pages/tools/string-length-word-counter.tsx | 76 +++++++++++++++++++ .../string-length-word-counter.svg | 22 ++++++ 3 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 pages/tools/string-length-word-counter.tsx create mode 100644 public/images/illustrations/string-length-word-counter.svg diff --git a/pages/tools/index.tsx b/pages/tools/index.tsx index 786b7cf3..39963ac7 100644 --- a/pages/tools/index.tsx +++ b/pages/tools/index.tsx @@ -28,28 +28,37 @@ const tools = [ title: 'XML to JSON converter', description: 'Convert your data from XML to JSON and back and verify their validity', - links: [{ src: '/tools/xml-to-json', text: 'Convert' }], + links: [{ src: '/tools/xml-to-json/', text: 'Convert' }], imageSrc: '/images/illustrations/xml-to-json.svg' }, { title: 'Base64 encoder/decoder', description: 'Encode or decode your data to/from the Base64 format', - links: [{ src: '/tools/base64-encode-decode', text: 'Encode/decode' }], + links: [{ src: '/tools/base64-encode-decode/', text: 'Encode/decode' }], imageSrc: '/images/illustrations/base64-encode-decode.svg' }, { title: 'JSON to YAML converter', description: 'Convert your data from JSON to YAML and back and verify their validity', - links: [{ src: '/tools/json-to-yaml', text: 'Convert' }], + links: [{ src: '/tools/json-to-yaml/', text: 'Convert' }], imageSrc: '/images/illustrations/json-to-yaml.svg' }, { title: 'JSONPath and object-path online evaluator', description: 'Extract values from JSON data using JSONPath or object-path syntaxes', - links: [{ src: '/tools/json-object-path-evaluator', text: 'Extract data' }], + links: [ + { src: '/tools/json-object-path-evaluator/', text: 'Extract data' } + ], imageSrc: '/images/illustrations/json-path-evaluator.svg' + }, + { + title: 'String length and word counter', + description: + 'Count the number of characters, words, and lines in your text', + links: [{ src: '/tools/string-length-word-counter/', text: 'Count' }], + imageSrc: '/images/illustrations/string-length-word-counter.svg' } ]; diff --git a/pages/tools/string-length-word-counter.tsx b/pages/tools/string-length-word-counter.tsx new file mode 100644 index 00000000..2a1814cd --- /dev/null +++ b/pages/tools/string-length-word-counter.tsx @@ -0,0 +1,76 @@ +import { FunctionComponent, useState } from 'react'; +import TextEditor from '../../components/editors/text-editor'; +import Hero from '../../components/hero'; +import Meta from '../../components/meta'; +import Layout from '../../layout/layout'; + +const StringLengthCounter: FunctionComponent = function () { + const [stats, setStats] = useState({ + length: 14, + words: 2, + lines: 1 + }); + + return ( + + + +
+
+
+
+

Length

+

{stats.length}

+
+
+
+

Words

{' '} +

{stats.words}

+
+
+
+

Lines

{' '} +

{stats.lines}

+
+
+ { + setStats({ + length: value.length, + words: value.trim().split(/\s+/).length, + lines: value.split(/\n|\r\n/).length + }); + }} + /> +
+
+ +
+
+
+
+

About this tool

+

+ This tool allows you to count the number of characters, words, + and lines in your text. It is useful for checking the length of + your content, such as for social media posts, blog articles, or + academic papers. It also helps you to identify the number of + words and lines in your text, which can be useful for writing + essays, reports, or other documents. +

+
+
+
+
+
+ ); +}; + +export default StringLengthCounter; diff --git a/public/images/illustrations/string-length-word-counter.svg b/public/images/illustrations/string-length-word-counter.svg new file mode 100644 index 00000000..07c58ab8 --- /dev/null +++ b/public/images/illustrations/string-length-word-counter.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + abcdefg... + + + +