From 2bfd315e5aecb5c31b2b42bf4a745f665533216b Mon Sep 17 00:00:00 2001 From: Farkhanda Dalal <125860512+Farkhanda-Dalal@users.noreply.github.com> Date: Sat, 13 Sep 2025 13:03:19 +0530 Subject: [PATCH 1/4] Update README.md --- README.md | 105 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 71 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 222fa10..d101a44 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@
- - ![Stringzy banner](./assets/stringzy-banner2.jpg) +![Stringzy banner](./assets/stringzy-banner2.jpg) ![NPM Version](https://img.shields.io/npm/v/stringzy) ![Typescript](https://img.shields.io/badge/TypeScript-3178C6?style=flat&logo=typescript&logoColor=white) @@ -95,6 +94,8 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2 - [isCoordinates](#iscoordinates) - Checks if given latitude and longitude are valid coordinates - [isLowerCase](#islowercase) - Checks if given string only has lower case characters. - [isUpperCase](#isuppercase) - Checks if given string only has upper case characters. +- [isAlphabetic](#isalphabetic) - Checks if input string contains only Alphabets (case insensitive) +- [isAlphaNumeric](#isalphanumeric) - Checks if input string contains only Alphabets and Digits (case insensitive) ### Analysis @@ -105,8 +106,7 @@ const count = stringzy.analyze.wordCount('Hello world'); // 2 - [stringSimilarity](#stringsimilarity) - Calculates the percentage similarity between two strings - [complexity](#complexity) - Analyzes string complexity including score, uniqueness, and length - [patternCount](#patterncount) - calculates the number of times a specific pattern occurs in a given text -- [vowelConsonantCount](#vowelconsonantcount) - Counts the number of vowels and consonants in a given string - +- [vowelConsonantCount](#vowelconsonantcount) - Counts the number of vowels and consonants in a given string ### Formatting @@ -461,7 +461,9 @@ splitChunks('helloworld'); | chunkSize | number | `1` | The size of each chunk in which the string is to be split | --- + #### `numberToText(num, lang)` + Converts a number to its text representation in the specified language. ```javascript @@ -471,14 +473,13 @@ numberToText(12345, 'en'); // Returns: 'twelve thousand three hundred forty-five numberToText(12345, 'pl'); // Returns: 'dwanaście tysięcy trzysta czterdzieści pięć' ``` -| Parameter | Type | Default | Description | -|-----------|--------|---------|-------------| -| num | number | required | The number to convert to text | -| lang | string | 'en' | The language code for the text representation (e.g., 'en' for English, 'pl' for Polish) | +| Parameter | Type | Default | Description | +| --------- | ------ | -------- | --------------------------------------------------------------------------------------- | +| num | number | required | The number to convert to text | +| lang | string | 'en' | The language code for the text representation (e.g., 'en' for English, 'pl' for Polish) | Available languages: en (English), pl (Polish). - ### ✅ Validations Functions for validating string formats and content. @@ -565,19 +566,18 @@ isSlug('hello_world'); // false (underscore not allowed) Checks if a file or URL has a valid extension for a given type ```javascript -isType("photo.PNG", "image"); // true -isType("https://example.com/logo.svg", "image"); // true -isType({ name: "track.mp3" }, "audio"); // true -isType("filewithoutextension", "image"); // false -isType("document.zip", "document"); // false -isType("video.mp4", "document"); // false +isType('photo.PNG', 'image'); // true +isType('https://example.com/logo.svg', 'image'); // true +isType({ name: 'track.mp3' }, 'audio'); // true +isType('filewithoutextension', 'image'); // false +isType('document.zip', 'document'); // false +isType('video.mp4', 'document'); // false ``` -| Parameter | Type | Default | Description | -|-----------|------|---------|-------------| -| input | string | required | The file name, URL string, or object with .name | -| input | string | required | The file type category to validate (image, video, audio, document, archive) | - +| Parameter | Type | Default | Description | +| --------- | ------ | -------- | --------------------------------------------------------------------------- | +| input | string | required | The file name, URL string, or object with .name | +| input | string | required | The file type category to validate (image, video, audio, document, archive) | #### `isIPv4(text)` @@ -625,11 +625,11 @@ The check is case-insensitive and ignores spaces and punctuation. ```javascript import { isPalindrome } from 'stringzy'; -isPalindrome('racecar'); // true -isPalindrome('A man, a plan, a canal: Panama'); // true -isPalindrome('No lemon, no melon'); // true -isPalindrome('hello'); // false -isPalindrome('Was it a car or a cat I saw?'); // true +isPalindrome('racecar'); // true +isPalindrome('A man, a plan, a canal: Panama'); // true +isPalindrome('No lemon, no melon'); // true +isPalindrome('hello'); // false +isPalindrome('Was it a car or a cat I saw?'); // true ``` | Parameter | Type | Default | Description | @@ -648,10 +648,10 @@ isCoordinates(40.748817, -73.985428); // true isCoordinates(9999, -9999); // false ``` -| Parameter | Type | Default | Description | -| --------- | ----------- | -------- | ----------------------------------------- | -| latitude | number | required | Latitude to validate | -| longitude | number | required | Longitude to validate | +| Parameter | Type | Default | Description | +| --------- | ------ | -------- | --------------------- | +| latitude | number | required | Latitude to validate | +| longitude | number | required | Longitude to validate | #### `isLowerCase(str)` @@ -689,6 +689,47 @@ isUpperCase('12345'); // false | --------- | ------ | -------- | ---------------------------------------------------------------------------- | | str | string | required | The input string to validate as containing uppercase alphabetic letters | +#### `isAlphabetic(text)` + +Checks if a string contains only alphabetic characters (a-z, A-Z). +Throws an error if the input is not a string. + +```javascript +import { isAlphabetic } from 'stringzy'; + +isAlphabetic('hello'); // true +isAlphabetic('World'); // true +isAlphabetic('helloWORLD'); // true +isAlphabetic('abc123'); // false +isAlphabetic('hello!'); // false +isAlphabetic(''); // false +``` + +| Parameter | Type | Default | Description | +| --------- | ------ | -------- | --------------------------------------------- | +| text | string | required | The input string to check for alphabetic only | + +#### `isAlphaNumeric(text)` + +Checks if a string contains only alphanumeric characters (letters and digits). +Throws an error if the input is not a string. + +```javascript +import { isAlphaNumeric } from 'stringzy'; + +isAlphaNumeric('abc123'); // true +isAlphaNumeric('A1B2C3'); // true +isAlphaNumeric('123'); // true +isAlphaNumeric('hello'); // true +isAlphaNumeric('hello!'); // false +isAlphaNumeric('123 456'); // false +isAlphaNumeric(''); // false +``` + +| Parameter | Type | Default | Description | +| --------- | ------ | -------- | ----------------------------------------------- | +| text | string | required | The input string to check for alphanumeric only | + --- ### 📊 Analysis @@ -778,8 +819,6 @@ stringSimilarity('flaw', 'lawn', 'Damerau-Levenshtein'); // Returns: 50 | textB | string | required | The second text to compare. | | algorithm | string | 'Levenshtein' | The algorithm to use: 'Levenshtein' or 'Damerau-Levenshtein'. | - - #### `complexity(text)` Analyzes the complexity of a string, returning an object with detailed metrics. @@ -807,8 +846,6 @@ complexity(''); - `uniqueness` (number): Measure of character uniqueness - `length` (number): Length of the input string - - #### `patternCount(text, pattern)` Counts the number of times a substring (pattern) occurs in a string, including overlapping occurrences. @@ -832,7 +869,7 @@ Counts the number of vowels and consonants in a given string. This function is case-insensitive and ignores non-alphabetic characters. ```javascript -vowelConsonantCount('hello'); +vowelConsonantCount('hello'); // { vowels: 2, consonants: 3 } vowelConsonantCount('stringzy'); From 81ac8b931fa3460106010ce5b8768077e0495a31 Mon Sep 17 00:00:00 2001 From: Farkhanda Dalal <125860512+Farkhanda-Dalal@users.noreply.github.com> Date: Sat, 13 Sep 2025 13:04:43 +0530 Subject: [PATCH 2/4] Add alphabetic and alphanumeric validations --- src/validations/index.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/validations/index.ts b/src/validations/index.ts index 547982c..c1d0ae8 100644 --- a/src/validations/index.ts +++ b/src/validations/index.ts @@ -9,6 +9,8 @@ export { isHexColor } from './isHexColor'; export { isPalindrome } from './isPalindrome' export {isLowerCase} from './isLowerCase'; export {isUpperCase} from './isUpperCase'; +export { isAlphabetic } from './isAlphabetic'; +export { isAlphaNumeric } from './isAlphaNumeric'; import { isCoordinates } from './isCoordinates'; import { isDate } from './isDate'; @@ -21,6 +23,8 @@ import { isHexColor } from './isHexColor'; import { isPalindrome } from './isPalindrome'; import { isLowerCase } from './isLowerCase'; import { isUpperCase } from './isUpperCase'; +import { isAlphabetic } from './isAlphabetic'; +import { isAlphaNumeric } from './isAlphaNumeric'; export const validations = { isCoordinates, @@ -33,5 +37,7 @@ export const validations = { isHexColor, isPalindrome, isLowerCase, - isUpperCase + isUpperCase, + isAlphabetic, + isAlphaNumeric }; From 68f76d7e155d372668f3c70d25caa04097b379af Mon Sep 17 00:00:00 2001 From: Farkhanda Dalal <125860512+Farkhanda-Dalal@users.noreply.github.com> Date: Sat, 13 Sep 2025 13:14:51 +0530 Subject: [PATCH 3/4] Add files via upload --- src/validations/isAlphaNumeric.ts | 21 +++++++++++++++++++++ src/validations/isAlphabetic.ts | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/validations/isAlphaNumeric.ts create mode 100644 src/validations/isAlphabetic.ts diff --git a/src/validations/isAlphaNumeric.ts b/src/validations/isAlphaNumeric.ts new file mode 100644 index 0000000..d5c9b2c --- /dev/null +++ b/src/validations/isAlphaNumeric.ts @@ -0,0 +1,21 @@ +/** + * Checks whether the given string is alphanumeric. + * + * The check ensures that the string contains only + * letters (a-z, A-Z) and digits (0-9). + * + * @param {string} str - The input string to check. + * @returns {boolean} True if the input is alphanumeric, false otherwise. + * @throws {TypeError} If the input is not a string. + */ +export function isAlphaNumeric(str: string): boolean { + if (typeof str !== 'string') { + throw new TypeError('Input must be a string'); + } + + if (str.length === 0) { + return false; + } + + return /^[a-z0-9]+$/i.test(str); +} diff --git a/src/validations/isAlphabetic.ts b/src/validations/isAlphabetic.ts new file mode 100644 index 0000000..3455202 --- /dev/null +++ b/src/validations/isAlphabetic.ts @@ -0,0 +1,19 @@ +/** + * Checks whether a given string contains only alphabetic characters (A-Z, a-z). + * + * + * @param {string} str - The input string to check. + * @returns {boolean} True if the input contains only alphabetic characters, otherwise false. + * @throws {TypeError} If the input is not a string. + */ +export function isAlphabetic(str: string): boolean { + if (typeof str !== 'string') { + throw new TypeError('Input must be a string'); + } + + // empty string is not considered alphabetic + if (str === '') return false; + + // Regular expression to match only alphabetic characters + return /^[A-Za-z]+$/.test(str); +} From 374457365ad9e432f47a7bb1d3508f3d68457d8f Mon Sep 17 00:00:00 2001 From: Farkhanda Dalal <125860512+Farkhanda-Dalal@users.noreply.github.com> Date: Sat, 13 Sep 2025 13:15:43 +0530 Subject: [PATCH 4/4] Add files via upload --- src/tests/validations/isAlphaNumeric.test.ts | 29 ++++++++++++++++++ src/tests/validations/isAlphabetic.test.ts | 32 ++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/tests/validations/isAlphaNumeric.test.ts create mode 100644 src/tests/validations/isAlphabetic.test.ts diff --git a/src/tests/validations/isAlphaNumeric.test.ts b/src/tests/validations/isAlphaNumeric.test.ts new file mode 100644 index 0000000..8af4938 --- /dev/null +++ b/src/tests/validations/isAlphaNumeric.test.ts @@ -0,0 +1,29 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { isAlphaNumeric } from '../../validations/isAlphaNumeric'; + +describe('isAlphaNumeric', () => { + it('returns true for alphanumeric strings', () => { + assert.strictEqual(isAlphaNumeric('abc123'), true); + assert.strictEqual(isAlphaNumeric('A1B2C3'), true); + assert.strictEqual(isAlphaNumeric('123'), true); + assert.strictEqual(isAlphaNumeric('abc'), true); + }); + + it('returns false for strings with special characters or spaces', () => { + assert.strictEqual(isAlphaNumeric('abc!123'), false); + assert.strictEqual(isAlphaNumeric('hello world'), false); + assert.strictEqual(isAlphaNumeric('test@'), false); + }); + + it('returns false for empty string', () => { + assert.strictEqual(isAlphaNumeric(''), false); + }); + + it('throws an error if input is not a string', () => { + assert.throws(() => isAlphaNumeric(123 as any), /Input must be a string/); + assert.throws(() => isAlphaNumeric(null as any), /Input must be a string/); + assert.throws(() => isAlphaNumeric(undefined as any), /Input must be a string/); + assert.throws(() => isAlphaNumeric({} as any), /Input must be a string/); + }); +}); diff --git a/src/tests/validations/isAlphabetic.test.ts b/src/tests/validations/isAlphabetic.test.ts new file mode 100644 index 0000000..088149a --- /dev/null +++ b/src/tests/validations/isAlphabetic.test.ts @@ -0,0 +1,32 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { isAlphabetic } from '../../validations/isAlphabetic'; + +describe('isAlphabetic', () => { + it('returns true for purely alphabetic strings', () => { + assert.strictEqual(isAlphabetic('hello'), true); + assert.strictEqual(isAlphabetic('World'), true); + assert.strictEqual(isAlphabetic('TestCase'), true); + }); + + it('returns false for strings with numbers', () => { + assert.strictEqual(isAlphabetic('hello123'), false); + assert.strictEqual(isAlphabetic('Test1'), false); + }); + + it('returns false for strings with special characters or spaces', () => { + assert.strictEqual(isAlphabetic('hello!'), false); + assert.strictEqual(isAlphabetic('hello world'), false); + assert.strictEqual(isAlphabetic('Hi-There'), false); + }); + + it('returns false for empty strings', () => { + assert.strictEqual(isAlphabetic(''), false); + }); + + it('throws an error if input is not a string', () => { + assert.throws(() => isAlphabetic(123 as any), /Input must be a string/); + assert.throws(() => isAlphabetic(null as any), /Input must be a string/); + assert.throws(() => isAlphabetic(undefined as any), /Input must be a string/); + }); +});