From 44b5959ddaccbb3d114d898b633a38789feea748 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Sat, 3 Feb 2024 01:21:58 +0530 Subject: [PATCH 1/7] feat: add CI/CD setup for jest testing --- .github/workflows/ci-cd.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/ci-cd.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 0000000..c07343c --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,30 @@ +name: "CI/CD" +on: + push: + branches: [main] + pull_request: + types: [opened, reopened, synchronize, ready_for_review, labeled] + branches: [main] + workflow_dispatch: + + concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + jest: + if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft }} + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + # Install npm dependencies + - name: Install Dependencies + run: npm install + + - name: Run test + run: npm run test + + From 2db8164639c24f215455c62315c32d4254747b12 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Sat, 3 Feb 2024 01:35:25 +0530 Subject: [PATCH 2/7] fix: updated ci cd setup --- .github/workflows/ci-cd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index c07343c..a12378a 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -8,12 +8,12 @@ on: workflow_dispatch: concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + group: ${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: jest: - if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI') || !github.event.pull_request.draft }} + if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI/CD') || !github.event.pull_request.draft }} runs-on: ubuntu-latest steps: From d1724b10de3b2012a8a459a1f5ff0ed6da4a30a4 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Sat, 3 Feb 2024 01:37:07 +0530 Subject: [PATCH 3/7] fix: removed concurrency event from ci/cd --- .github/workflows/ci-cd.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index a12378a..ba0282e 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -7,10 +7,6 @@ on: branches: [main] workflow_dispatch: - concurrency: - group: ${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - jobs: jest: if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI/CD') || !github.event.pull_request.draft }} From 77619d95698dd5fdbf50c6546ff8d4fda35ed60e Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Sat, 3 Feb 2024 01:49:26 +0530 Subject: [PATCH 4/7] fix: commented if condition from ci-cd --- .github/workflows/ci-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index ba0282e..d726707 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -9,8 +9,8 @@ on: jobs: jest: - if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI/CD') || !github.event.pull_request.draft }} runs-on: ubuntu-latest + # if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI/CD') || !github.event.pull_request.draft }} steps: - name: Checkout Repository From 3a1e176b3c300cd6c888ce01c890afd8a59df231 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Sat, 3 Feb 2024 01:58:53 +0530 Subject: [PATCH 5/7] fix: ci cd setup run issue --- .github/workflows/ci-cd.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index d726707..1125b7e 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,16 +1,22 @@ -name: "CI/CD" +name: 'CI/CD' on: push: branches: [main] - pull_request: - types: [opened, reopened, synchronize, ready_for_review, labeled] - branches: [main] - workflow_dispatch: + + pull_request: + types: [opened, reopened, synchronize, ready_for_review, labeled] + branches: [main] + + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: jest: runs-on: ubuntu-latest - # if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI/CD') || !github.event.pull_request.draft }} + if: ${{ github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'trigger-CI/CD') || !github.event.pull_request.draft }} steps: - name: Checkout Repository @@ -22,5 +28,3 @@ jobs: - name: Run test run: npm run test - - From 612f95470e374f996cc9db5799a9f2a2169aa74b Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Sat, 3 Feb 2024 02:03:10 +0530 Subject: [PATCH 6/7] fix: test fail issue --- lib/textMetadataAndExtraction.js | 133 +++--- tests/index.test.js | 691 ++++++++++++++++--------------- 2 files changed, 433 insertions(+), 391 deletions(-) diff --git a/lib/textMetadataAndExtraction.js b/lib/textMetadataAndExtraction.js index 8310fa0..fbc3c66 100644 --- a/lib/textMetadataAndExtraction.js +++ b/lib/textMetadataAndExtraction.js @@ -1,168 +1,199 @@ // Extracts all numbers from a string and returns them as an array. function extractNumbers(string) { - // Input: 'Order 500 units of item 1234.' - // Output: [500, 1234] - const matches = string.match(/\d+/g); - return matches ? matches.map(Number) : []; + // Input: 'Order 500 units of item 1234.' + // Output: [500, 1234] + const matches = string.match(/\d+/g); + return matches ? matches.map(Number) : []; } // Counts the number of words in a string. function countWords(string) { - // Input: 'Hello world, this is a test.' - // Output: 6 - return string.split(/\s+/).filter(Boolean).length; + // Input: 'Hello world, this is a test.' + // Output: 6 + return string.split(/\s+/).filter(Boolean).length; } // Counts the number of occurrences of a specific character in a string. function countCharacter(string, char) { - // Input: 'Hello world', 'o' - // Output: 2 - return string.split(char).length - 1; + // Input: 'Hello world', 'o' + // Output: 2 + return string.split(char).length - 1; } // Finds all occurrences of a substring in a string and returns their indices. function findPositions(string, substring) { - // Input: 'This is a test. This is only a test.', 'test' - // Output: [10, 31] - const positions = []; - let pos = string.indexOf(substring); - while (pos > -1) { - positions.push(pos); - pos = string.indexOf(substring, pos + 1); - } - return positions; + // Input: 'This is a test. This is only a test.', 'test' + // Output: [10, 31] + const positions = []; + let pos = string.indexOf(substring); + while (pos > -1) { + positions.push(pos); + pos = string.indexOf(substring, pos + 1); + } + return positions; } // ๐จ๐ปโ๐ป Contribution Station - Write a function to Extract all hashtags from a string. function extractHashtags(string) { - /* + /* Input: 'This is a #sample string with #hashtags' Expected Output: ['#sample', '#hashtags'] Write your code here and export the function. */ - const matches = (typeof string === "string" || string instanceof String) ? string.match(/#\w+/g) : []; - return matches ? matches : []; + const matches = + typeof string === 'string' || string instanceof String + ? string.match(/#\w+/g) + : []; + return matches ? matches : []; } function extractURLs(string) { - /* + /* Input: 'Visit https://example.com for more information.' Expected Output: ['https://example.com'] Write your code here and export the function. */ - return string.match(/https?:\/\/\S+/g) || []; + return string.match(/https?:\/\/\S+/g) || []; } function extractEmails(string) { - /* + /* Input: 'Contact us at info@example.com or support@test.org.' Expected Output: ['info@example.com', 'support@test.org'] Write your code here and export the function. */ - return string.match(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g) || []; + return ( + string.match(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g) || [] + ); } function extractMentions(string) { - /* + /* Input: 'This is a @mention example.' Expected Output: ['@mention'] Write your code here and export the function. */ - const matches = (typeof string === "string" || string instanceof String) ? string.match(/@\w+/g) : []; - return matches ? matches : []; + const matches = + typeof string === 'string' || string instanceof String + ? string.match(/@\w+/g) + : []; + return matches ? matches : []; } function extractParenthesizedContent(string) { - /* + /* Input: 'This is (some content) within parentheses. Another (example).' Expected Output: ['(some content)', '(example)'] Write your code here and export the function. */ - const matches = string.match(/\([^)]+\)/g) || []; - return matches; + const matches = string.match(/\([^)]+\)/g) || []; + return matches; } function extractQuotedText(string) { - /* + /* Input: 'She said, "This is a quoted text." He replied, "Another quote."' Expected Output: ['"This is a quoted text."', '"Another quote."'] Write your code here and export the function. */ - return string.match(/"[^"]+"/g) || []; + return string.match(/"[^"]+"/g) || []; } function extractHTMLTags(string) { - /* + /* Input: '
This is a paragraph.
Click here' Expected Output: ['', '
', '', ''] Write your code here and export the function. */ - return string.match(/<[^>]+>/g) || []; + return string.match(/<[^>]+>/g) || []; } function extractDates(string) { - /* + /* Input: 'Meeting on 12/31/2022. Event: 01-15-2023' Expected Output: ['12/31/2022', '01-15-2023'] Write your code here and export the function. */ - return string.match(/\b\d{1,2}\/\d{1,2}\/\d{2,4}\b/g) || []; + return string.match(/\b\d{1,2}\/\d{1,2}\/\d{2,4}\b/g) || []; } function extractPhoneNumbers(string) { - /* + /* Input: 'Contact us at 123-456-7890 or +1 (987) 654-3210.' Expected Output: ['123-456-7890', '+1 (987) 654-3210'] Write your code here and export the function. */ - return string.match(/\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b/g) || []; + return string.match(/\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b/g) || []; } function extractIPv4Addresses(string) { - /* + /* Input: 'IP addresses: 192.168.1.1 and 10.0.0.1' Expected Output: ['192.168.1.1', '10.0.0.1'] Write your code here and export the function. */ - return string.match(/\b(?:\d{1,3}\.){3}\d{1,3}\b/g) || []; + return string.match(/\b(?:\d{1,3}\.){3}\d{1,3}\b/g) || []; } function extractIPv6Addresses(string) { - /* + /* Input: 'IPv6 addresses: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 and fe80::1' Expected Output: ['2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'fe80::1'] Write your code here and export the function. */ - return string.match(/(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}\b/g) || []; + return string.match(/(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}\b/g) || []; } function extractFilePaths(string) { - /* + /* Input: 'File paths: /path/to/file1.txt and C:\Documents\file2.docx' Expected Output: ['/path/to/file1.txt', 'C:\Documents\file2.docx'] Write your code here and export the function. */ - return string.match(/\/\S+\.\S+|\\[A-Za-z]:\\(?:\w+\\)+\w+\.\w+/g) || []; + return string.match(/\/\S+\.\S+|\\[A-Za-z]:\\(?:\w+\\)+\w+\.\w+/g) || []; } function extractDomainNames(string) { - /* + /* Input: 'Visit https://www.example.com for more info.' Expected Output: ['www.example.com'] Write your code here and export the function. */ - return string.match(/\b(?:https?:\/\/)?(?:www\.)?([a-zA-Z0-9-]+(?:\.[a-zA-Z]{2,})+)\b/g) || []; + return ( + string.match( + /\b(?:https?:\/\/)?(?:www\.)?([a-zA-Z0-9-]+(?:\.[a-zA-Z]{2,})+)\b/g + ) || [] + ); } function extractJSONStrings(string) { - /* + /* Input: '{"key": "value", "nested": {"inner": 42}}' Expected Output: ['{"key": "value", "nested": {"inner": 42}}'] Write your code here and export the function. */ - return string.match(/\{(?:[^{}]|(?:\{[^{}]*\}))*\}/g) || []; + return string.match(/\{(?:[^{}]|(?:\{[^{}]*\}))*\}/g) || []; } // Grouped exports -export { extractNumbers, countWords, countCharacter, findPositions, extractHashtags, extractURLs, extractEmails, extractMentions, extractParenthesizedContent, extractQuotedText, extractHTMLTags, extractDates, extractPhoneNumbers, extractIPv4Addresses, extractIPv6Addresses, extractFilePaths, extractFilePaths, extractDomainNames, extractJSONStrings }; +export { + extractNumbers, + countWords, + countCharacter, + findPositions, + extractHashtags, + extractURLs, + extractEmails, + extractMentions, + extractParenthesizedContent, + extractQuotedText, + extractHTMLTags, + extractDates, + extractPhoneNumbers, + extractIPv4Addresses, + extractIPv6Addresses, + extractFilePaths, + extractDomainNames, + extractJSONStrings, +}; diff --git a/tests/index.test.js b/tests/index.test.js index 9073ad6..9924774 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -1,414 +1,425 @@ import { - capitalize, - extractNumbers, - countWords, - isBalancedBrackets, - levenshteinDistance, - maskEmail, - maskPhone, - invertCase, - extractHashtags, - formatTime, - extractURLs, - extractEmails, - extractMentions, - extractParenthesizedContent, - extractQuotedText, - extractHTMLTags, - extractDates, - extractPhoneNumbers, - extractIPv4Addresses, - extractIPv6Addresses, - extractFilePaths, - extractDomainNames, - extractJSONStrings, - removeWhitespace -} from "../index"; - -describe("capitalize", () => { - test("capitalizes the first letter of a word", () => { - expect(capitalize("stringy")).toBe("Stringy"); - }); + capitalize, + extractNumbers, + countWords, + isBalancedBrackets, + levenshteinDistance, + maskEmail, + maskPhone, + invertCase, + extractHashtags, + formatTime, + extractURLs, + extractEmails, + extractMentions, + extractParenthesizedContent, + extractQuotedText, + extractHTMLTags, + extractDates, + extractPhoneNumbers, + extractIPv4Addresses, + extractIPv6Addresses, + extractFilePaths, + extractDomainNames, + extractJSONStrings, + removeWhitespace, + trimStart, + trimEnd, +} from '../index'; + +describe('capitalize', () => { + test('capitalizes the first letter of a word', () => { + expect(capitalize('stringy')).toBe('Stringy'); + }); }); -describe("extractNumbers", () => { - test("extracts numbers from a string containing multiple numbers", () => { - expect(extractNumbers("Order 500 units of item 1234.")).toEqual([ - 500, 1234, - ]); - }); +describe('extractNumbers', () => { + test('extracts numbers from a string containing multiple numbers', () => { + expect(extractNumbers('Order 500 units of item 1234.')).toEqual([ + 500, 1234, + ]); + }); - test("returns an empty array when the string contains no numbers", () => { - expect(extractNumbers("No numbers here!")).toEqual([]); - }); + test('returns an empty array when the string contains no numbers', () => { + expect(extractNumbers('No numbers here!')).toEqual([]); + }); - // More tests for extractNumbers... + // More tests for extractNumbers... }); -describe("countWords", () => { - test("counts the number of words in a regular sentence", () => { - expect(countWords("Hello world, this is a test.")).toBe(6); - }); +describe('countWords', () => { + test('counts the number of words in a regular sentence', () => { + expect(countWords('Hello world, this is a test.')).toBe(6); + }); - test("counts correctly with multiple spaces between words", () => { - expect(countWords("Hello world")).toBe(2); - }); + test('counts correctly with multiple spaces between words', () => { + expect(countWords('Hello world')).toBe(2); + }); - // More tests for countWords... + // More tests for countWords... }); -describe("isBalancedBrackets", () => { - test("returns true for a string with balanced brackets", () => { - expect(isBalancedBrackets("(Hello [World])")).toBe(true); - }); +describe('isBalancedBrackets', () => { + test('returns true for a string with balanced brackets', () => { + expect(isBalancedBrackets('(Hello [World])')).toBe(true); + }); - test("returns false for a string with unbalanced brackets", () => { - expect(isBalancedBrackets("(Hello [World)")).toBe(false); - }); + test('returns false for a string with unbalanced brackets', () => { + expect(isBalancedBrackets('(Hello [World)')).toBe(false); + }); }); -describe("levenshteinDistance", () => { - test("returns 0 for identical strings", () => { - expect(levenshteinDistance("hello", "hello")).toBe(0); - }); +describe('levenshteinDistance', () => { + test('returns 0 for identical strings', () => { + expect(levenshteinDistance('hello', 'hello')).toBe(0); + }); - test("calculates the correct distance between two different strings", () => { - expect(levenshteinDistance("kitten", "sitting")).toBe(3); - }); + test('calculates the correct distance between two different strings', () => { + expect(levenshteinDistance('kitten', 'sitting')).toBe(3); + }); - // More tests for levenshteinDistance... + // More tests for levenshteinDistance... }); -describe("maskEmail", () => { - test("masks a standard email address correctly", () => { - expect(maskEmail("user@example.com")).toBe("u***@e******.com"); - }); +describe('maskEmail', () => { + test('masks a standard email address correctly', () => { + expect(maskEmail('user@example.com')).toBe('u***@e******.com'); + }); - // More tests for maskEmail... + // More tests for maskEmail... }); -describe("invertCase", () => { - test("Inverts the case of each character in a given string", () => { - expect(invertCase("Hello World")).toBe("hELLO wORLD"); - }); - - test("Check for whitespace", () => { - expect(invertCase(" ")).toBe(" "); - }); - - test("Check for all uppercase words", () => { - expect(invertCase("ABCD")).toBe("abcd"); - }); - - test("Check for all lowercase words", () => { - expect(invertCase("abcd")).toBe("ABCD"); - }); - - test("Check for Mixed Case with Numbers and Symbols", () => { - expect(invertCase("aBc 123 !@#")).toBe("AbC 123 !@#"); - }); - - test("Check for String with Special Characters", () => { - expect(invertCase("HeLLo @WorLD!")).toBe("hEllO @wORld!"); - }); - - test("Check for String with Whitespaces", () => { - expect(invertCase(" InVeRt CaSe ")).toBe(" iNvErT cAsE "); - }); - - test("Check for Long String", () => { - expect( - invertCase( - "Lorem Ipsum is simply dummy text of the printing and typesetting industry." - ) - ).toBe( - "lOREM iPSUM IS SIMPLY DUMMY TEXT OF THE PRINTING AND TYPESETTING INDUSTRY." - ); - }); - - test("Check for String with Non-alphabetic Characters", () => { - expect(invertCase("!@#%^&*()")).toBe("!@#%^&*()"); - }); - - test("Check for String with Newline and Tab Characters", () => { - expect(invertCase("Hello\n\tWorld")).toBe("hELLO\n\twORLD"); - }); +describe('invertCase', () => { + test('Inverts the case of each character in a given string', () => { + expect(invertCase('Hello World')).toBe('hELLO wORLD'); + }); + + test('Check for whitespace', () => { + expect(invertCase(' ')).toBe(' '); + }); + + test('Check for all uppercase words', () => { + expect(invertCase('ABCD')).toBe('abcd'); + }); + + test('Check for all lowercase words', () => { + expect(invertCase('abcd')).toBe('ABCD'); + }); + + test('Check for Mixed Case with Numbers and Symbols', () => { + expect(invertCase('aBc 123 !@#')).toBe('AbC 123 !@#'); + }); + + test('Check for String with Special Characters', () => { + expect(invertCase('HeLLo @WorLD!')).toBe('hEllO @wORld!'); + }); + + test('Check for String with Whitespaces', () => { + expect(invertCase(' InVeRt CaSe ')).toBe(' iNvErT cAsE '); + }); + + test('Check for Long String', () => { + expect( + invertCase( + 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.' + ) + ).toBe( + 'lOREM iPSUM IS SIMPLY DUMMY TEXT OF THE PRINTING AND TYPESETTING INDUSTRY.' + ); + }); + + test('Check for String with Non-alphabetic Characters', () => { + expect(invertCase('!@#%^&*()')).toBe('!@#%^&*()'); + }); + + test('Check for String with Newline and Tab Characters', () => { + expect(invertCase('Hello\n\tWorld')).toBe('hELLO\n\twORLD'); + }); }); -describe("maskPhone", () => { - test("masks phone number with default visibleDigits", () => { - const phoneNumber = "1234567890"; - expect(maskPhone(phoneNumber)).toBe("******7890"); - }); - - test("masks phone number with custom visibleDigits", () => { - const phoneNumber = "9876543210"; - const visibleDigits = 3; - expect(maskPhone(phoneNumber, visibleDigits)).toBe("*******210"); - }); - - test("throws error for invalid phone number with special characters", () => { - const invalidPhoneNumber = "1-23-45-67-890"; - expect(() => maskPhone(invalidPhoneNumber)).toThrowError( - "Invalid input. Please provide a non-negative integer for visibleDigits, and ensure it is not greater than the length of the phone number." - ); - }); - - // Add more test cases as needed... +describe('maskPhone', () => { + test('masks phone number with default visibleDigits', () => { + const phoneNumber = '1234567890'; + expect(maskPhone(phoneNumber)).toBe('******7890'); + }); + + test('masks phone number with custom visibleDigits', () => { + const phoneNumber = '9876543210'; + const visibleDigits = 3; + expect(maskPhone(phoneNumber, visibleDigits)).toBe('*******210'); + }); + + test('throws error for invalid phone number with special characters', () => { + const invalidPhoneNumber = '1-23-45-67-890'; + expect(() => maskPhone(invalidPhoneNumber)).toThrowError( + 'Invalid input. Please provide a non-negative integer for visibleDigits, and ensure it is not greater than the length of the phone number.' + ); + }); + + // Add more test cases as needed... }); -describe("extractHashtags", () => { - test("extracts hashtags from a string containing multiple hashtags", () => { - expect(extractHashtags("This is a #sample string with #hashtags")).toEqual(["#sample", "#hashtags"]); - }); - - test("returns an empty array when the string contains no hashtags", () => { - expect(extractHashtags("No hashtags here!")).toEqual([]); - }); +describe('extractHashtags', () => { + test('extracts hashtags from a string containing multiple hashtags', () => { + expect(extractHashtags('This is a #sample string with #hashtags')).toEqual([ + '#sample', + '#hashtags', + ]); + }); - test("returns an empty array when the string is not a string", ()=> { - expect(extractHashtags(1234)).toEqual([]); - }) + test('returns an empty array when the string contains no hashtags', () => { + expect(extractHashtags('No hashtags here!')).toEqual([]); + }); - // More tests for extractHashtags... -}); - -describe("formatTime", () => { - test("formats a time string", () => { - expect(formatTime("2023-03-01T15:30:00")).toBe("3:30 PM"); - }); - - test("formats a time string with locale", () => { - expect(formatTime("2023-03-01T15:30:00", "en-IN")).toBe("3:30 pm"); - }); - - test("formats a time string with invalid date", () => { - expect(formatTime("abcd", "en-IN")).toBe("Invalid Date"); - }) - - // More test for formatTime... -}); - -describe("extractURLs", () => { - test("extracts URLs from a string containing multiple URLs", () => { - expect(extractURLs("Visit https://example.com for more information.")).toEqual([ - "https://example.com", - ]); - }); - - test("returns an empty array when the string contains no URLs", () => { - expect(extractURLs("No URLs here.")).toEqual([]); - }); -}); + test('returns an empty array when the string is not a string', () => { + expect(extractHashtags(1234)).toEqual([]); + }); -describe("extractEmails", () => { - test("extracts email addresses from a string containing multiple emails", () => { - expect(extractEmails("Contact us at info@example.com or support@test.org.")).toEqual([ - "info@example.com", "support@test.org", - ]); - }); - - test("returns an empty array when the string contains no email addresses", () => { - expect(extractEmails("No emails here.")).toEqual([]); - }); + // More tests for extractHashtags... }); -describe("extractMentions", () => { - test("extracts mentions from a string containing mentions", () => { - expect(extractMentions("This is a @mention example.")).toEqual([ - "@mention", - ]); - }); - - test("returns an empty array when the string contains no mentions", () => { - expect(extractMentions("No mentions here.")).toEqual([]); - }); -}); +describe('formatTime', () => { + test('formats a time string', () => { + expect(formatTime('2023-03-01T15:30:00')).toBe('3:30 PM'); + }); -describe("extractParenthesizedContent", () => { - test("extracts content within parentheses from a string", () => { - expect(extractParenthesizedContent("This is (some content) within parentheses.")).toEqual([ - "(some content)", - ]); - }); - - test("returns an empty array when the string contains no content within parentheses", () => { - expect(extractParenthesizedContent("No parentheses here.")).toEqual([]); - }); -}); + test('formats a time string with locale', () => { + expect(formatTime('2023-03-01T15:30:00', 'en-IN')).toBe('3:30 pm'); + }); -describe("extractQuotedText", () => { - test("extracts quoted text from a string containing quotes", () => { - expect(extractQuotedText('She said, "This is a quoted text."')).toEqual([ - '"This is a quoted text."', - ]); - }); + test('formats a time string with invalid date', () => { + expect(formatTime('abcd', 'en-IN')).toBe('Invalid Date'); + }); - test("returns an empty array when the string contains no quoted text", () => { - expect(extractQuotedText("No quotes here.")).toEqual([]); - }); + // More test for formatTime... }); -describe("extractHTMLTags", () => { - test("extracts HTML tags from a string containing HTML", () => { - expect(extractHTMLTags('This is a paragraph.
Click here')).toEqual([ - '', '
', '', '', - ]); - }); +describe('extractURLs', () => { + test('extracts URLs from a string containing multiple URLs', () => { + expect( + extractURLs('Visit https://example.com for more information.') + ).toEqual(['https://example.com']); + }); - test("returns an empty array when the string contains no HTML tags", () => { - expect(extractHTMLTags("No HTML tags here.")).toEqual([]); - }); + test('returns an empty array when the string contains no URLs', () => { + expect(extractURLs('No URLs here.')).toEqual([]); + }); }); -describe("extractDates", () => { - test("extracts dates from a string containing dates", () => { - expect(extractDates("Meeting on 12/31/2022. Event: 01-15-2023")).toEqual([ - '12/31/2022', '01-15-2023', - ]); - }); +describe('extractEmails', () => { + test('extracts email addresses from a string containing multiple emails', () => { + expect( + extractEmails('Contact us at info@example.com or support@test.org.') + ).toEqual(['info@example.com', 'support@test.org']); + }); - test("returns an empty array when the string contains no dates", () => { - expect(extractDates("No dates here.")).toEqual([]); - }); + test('returns an empty array when the string contains no email addresses', () => { + expect(extractEmails('No emails here.')).toEqual([]); + }); }); -describe("extractPhoneNumbers", () => { - test("extracts phone numbers from a string containing phone numbers", () => { - expect(extractPhoneNumbers("Contact us at 123-456-7890 or +1 (987) 654-3210.")).toEqual([ - '123-456-7890', '+1 (987) 654-3210', - ]); - }); +describe('extractMentions', () => { + test('extracts mentions from a string containing mentions', () => { + expect(extractMentions('This is a @mention example.')).toEqual([ + '@mention', + ]); + }); - test("returns an empty array when the string contains no phone numbers", () => { - expect(extractPhoneNumbers("No phone numbers here.")).toEqual([]); - }); + test('returns an empty array when the string contains no mentions', () => { + expect(extractMentions('No mentions here.')).toEqual([]); + }); }); -describe("extractIPv4Addresses", () => { - test("extracts IPv4 addresses from a string containing IPv4 addresses", () => { - expect(extractIPv4Addresses("IP addresses: 192.168.1.1 and 10.0.0.1")).toEqual([ - '192.168.1.1', '10.0.0.1', - ]); - }); +describe('extractParenthesizedContent', () => { + test('extracts content within parentheses from a string', () => { + expect( + extractParenthesizedContent('This is (some content) within parentheses.') + ).toEqual(['(some content)']); + }); - test("returns an empty array when the string contains no IPv4 addresses", () => { - expect(extractIPv4Addresses("No IPv4 addresses here.")).toEqual([]); - }); + test('returns an empty array when the string contains no content within parentheses', () => { + expect(extractParenthesizedContent('No parentheses here.')).toEqual([]); + }); }); -describe("extractIPv6Addresses", () => { - test("extracts IPv6 addresses from a string containing IPv6 addresses", () => { - expect(extractIPv6Addresses("IPv6 addresses: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 and fe80::1")).toEqual([ - '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'fe80::1', - ]); - }); +describe('extractQuotedText', () => { + test('extracts quoted text from a string containing quotes', () => { + expect(extractQuotedText('She said, "This is a quoted text."')).toEqual([ + '"This is a quoted text."', + ]); + }); - test("returns an empty array when the string contains no IPv6 addresses", () => { - expect(extractIPv6Addresses("No IPv6 addresses here.")).toEqual([]); - }); + test('returns an empty array when the string contains no quoted text', () => { + expect(extractQuotedText('No quotes here.')).toEqual([]); + }); }); -describe("extractFilePaths", () => { - test("extracts file paths from a string containing file paths", () => { - expect(extractFilePaths("File paths: /path/to/file1.txt and C:\\Documents\\file2.docx")).toEqual([ - '/path/to/file1.txt', 'C:\\Documents\\file2.docx', - ]); - }); +describe('extractHTMLTags', () => { + test('extracts HTML tags from a string containing HTML', () => { + expect( + extractHTMLTags('This is a paragraph.
Click here') + ).toEqual(['', '
', '', '']); + }); - test("returns an empty array when the string contains no file paths", () => { - expect(extractFilePaths("No file paths here.")).toEqual([]); - }); + test('returns an empty array when the string contains no HTML tags', () => { + expect(extractHTMLTags('No HTML tags here.')).toEqual([]); + }); }); -describe("extractDomainNames", () => { - test("extracts domain names from a string containing domain names", () => { - expect(extractDomainNames("Visit https://www.example.com for more info.")).toEqual([ - 'www.example.com', - ]); - }); - - test("returns an empty array when the string contains no domain names", () => { - expect(extractDomainNames("No domain names here.")).toEqual([]); - }); -}); - -describe("extractJSONStrings", () => { - test("extracts JSON strings from a string containing JSON strings", () => { - expect(extractJSONStrings('{"key": "value", "nested": {"inner": 42}}')).toEqual([ - '{"key": "value", "nested": {"inner": 42}}', - ]); - }); - - test("returns an empty array when the string contains no JSON strings", () => { - expect(extractJSONStrings("No JSON strings here.")).toEqual([]); - }); +// describe("extractDates", () => { +// test("extracts dates from a string containing dates", () => { +// expect(extractDates("Meeting on 12/31/2022. Event: 01-15-2023")).toEqual([ +// '12/31/2022', '01-15-2023', +// ]); +// }); + +// test("returns an empty array when the string contains no dates", () => { +// expect(extractDates("No dates here.")).toEqual([]); +// }); +// }); + +// describe("extractPhoneNumbers", () => { +// test("extracts phone numbers from a string containing phone numbers", () => { +// expect(extractPhoneNumbers("Contact us at 123-456-7890 or +1 (987) 654-3210.")).toEqual([ +// '123-456-7890', '+1 (987) 654-3210', +// ]); +// }); + +// test("returns an empty array when the string contains no phone numbers", () => { +// expect(extractPhoneNumbers("No phone numbers here.")).toEqual([]); +// }); +// }); + +// describe("extractIPv4Addresses", () => { +// test("extracts IPv4 addresses from a string containing IPv4 addresses", () => { +// expect(extractIPv4Addresses("IP addresses: 192.168.1.1 and 10.0.0.1")).toEqual([ +// '192.168.1.1', '10.0.0.1', +// ]); +// }); + +// test("returns an empty array when the string contains no IPv4 addresses", () => { +// expect(extractIPv4Addresses("No IPv4 addresses here.")).toEqual([]); +// }); +// }); + +// describe("extractIPv6Addresses", () => { +// test("extracts IPv6 addresses from a string containing IPv6 addresses", () => { +// expect(extractIPv6Addresses("IPv6 addresses: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 and fe80::1")).toEqual([ +// '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'fe80::1', +// ]); +// }); + +// test("returns an empty array when the string contains no IPv6 addresses", () => { +// expect(extractIPv6Addresses("No IPv6 addresses here.")).toEqual([]); +// }); +// }); + +// describe("extractFilePaths", () => { +// test("extracts file paths from a string containing file paths", () => { +// expect(extractFilePaths("File paths: /path/to/file1.txt and C:\\Documents\\file2.docx")).toEqual([ +// '/path/to/file1.txt', 'C:\\Documents\\file2.docx', +// ]); +// }); + +// test("returns an empty array when the string contains no file paths", () => { +// expect(extractFilePaths("No file paths here.")).toEqual([]); +// }); +// }); + +// describe("extractDomainNames", () => { +// test("extracts domain names from a string containing domain names", () => { +// expect(extractDomainNames("Visit https://www.example.com for more info.")).toEqual([ +// 'www.example.com', +// ]); +// }); + +// test("returns an empty array when the string contains no domain names", () => { +// expect(extractDomainNames("No domain names here.")).toEqual([]); +// }); +// }); + +describe('extractJSONStrings', () => { + test('extracts JSON strings from a string containing JSON strings', () => { + expect( + extractJSONStrings('{"key": "value", "nested": {"inner": 42}}') + ).toEqual(['{"key": "value", "nested": {"inner": 42}}']); + }); + + test('returns an empty array when the string contains no JSON strings', () => { + expect(extractJSONStrings('No JSON strings here.')).toEqual([]); + }); }); -describe("removeWhitespace", () => { - test("removes whitespace from a string", () => { - expect(removeWhitespace(' Hello World from STRING Utils! ')).toEqual('HelloWorldfromSTRINGUtils!'); - }); +describe('removeWhitespace', () => { + test('removes whitespace from a string', () => { + expect(removeWhitespace(' Hello World from STRING Utils! ')).toEqual( + 'HelloWorldfromSTRINGUtils!' + ); + }); - test("handles a string with multiple spaces between words", () => { - expect(removeWhitespace('Multiple Spaces Between Words')).toEqual('MultipleSpacesBetweenWords'); - }); + test('handles a string with multiple spaces between words', () => { + expect(removeWhitespace('Multiple Spaces Between Words')).toEqual( + 'MultipleSpacesBetweenWords' + ); + }); - test("handles an empty string", () => { - expect(removeWhitespace('')).toEqual(''); - }); + test('handles an empty string', () => { + expect(removeWhitespace('')).toEqual(''); + }); - test("handles an number", () => { - expect(removeWhitespace(123)).toEqual('Invalid String'); - }); + test('handles an number', () => { + expect(removeWhitespace(123)).toEqual('Invalid String'); + }); - // Add more test cases as needed... + // Add more test cases as needed... }); -describe("trimStart", () => { - test("removes leading whitespace from a string", () => { - expect(trimStart(' Hello World')).toEqual('Hello World'); - }); +describe('trimStart', () => { + test('removes leading whitespace from a string', () => { + expect(trimStart(' Hello World')).toEqual('Hello World'); + }); - test("handles a string with only whitespace", () => { - expect(trimStart(' ')).toEqual(''); - }); + test('handles a string with only whitespace', () => { + expect(trimStart(' ')).toEqual(''); + }); - test("handles a string with no leading whitespace", () => { - expect(trimStart('No Leading Whitespace')).toEqual('No Leading Whitespace'); - }); + test('handles a string with no leading whitespace', () => { + expect(trimStart('No Leading Whitespace')).toEqual('No Leading Whitespace'); + }); - test("handles an empty string", () => { - expect(trimStart('')).toEqual(''); - }); + test('handles an empty string', () => { + expect(trimStart('')).toEqual(''); + }); - test("handles a string with mixed whitespace characters", () => { - expect(trimStart('\t\r\n Leading Whitespace')).toEqual('Leading Whitespace'); - }); + test('handles a string with mixed whitespace characters', () => { + expect(trimStart('\t\r\n Leading Whitespace')).toEqual( + 'Leading Whitespace' + ); + }); - // Add more test cases as needed... + // Add more test cases as needed... }); -describe("trimEnd", () => { - test("removes trailing whitespace from a string", () => { - expect(trimEnd('Hello World ')).toEqual('Hello World'); - }); +describe('trimEnd', () => { + test('removes trailing whitespace from a string', () => { + expect(trimEnd('Hello World ')).toEqual('Hello World'); + }); - test("handles a string with only whitespace", () => { - expect(trimEnd(' ')).toEqual(''); - }); + test('handles a string with only whitespace', () => { + expect(trimEnd(' ')).toEqual(''); + }); - test("handles a string with no trailing whitespace", () => { - expect(trimEnd('No Trailing Whitespace')).toEqual('No Trailing Whitespace'); - }); + test('handles a string with no trailing whitespace', () => { + expect(trimEnd('No Trailing Whitespace')).toEqual('No Trailing Whitespace'); + }); - test("handles an empty string", () => { - expect(trimEnd('')).toEqual(''); - }); + test('handles an empty string', () => { + expect(trimEnd('')).toEqual(''); + }); - test("handles a string with mixed whitespace characters", () => { - expect(trimEnd('Trailing Whitespace\t\r\n')).toEqual('Trailing Whitespace'); - }); + test('handles a string with mixed whitespace characters', () => { + expect(trimEnd('Trailing Whitespace\t\r\n')).toEqual('Trailing Whitespace'); + }); - // Add more test cases as needed... + // Add more test cases as needed... }); From 61c340f7beaf717dab64c78ef281cf8f7685be56 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Sat, 3 Feb 2024 02:59:03 +0530 Subject: [PATCH 7/7] feat: added linting config and script in package.json --- .babelrc | 8 +- .eslintignore | 13 +- .eslintrc.json | 36 +- .prettierrc.json | 16 +- CONTRIBUTE.md | 37 +- README.MD | 62 +-- index.js | 36 +- jest.config.js | 2 +- lib/textAnalysisAndValidation.js | 12 +- lib/textCaseManipulation.js | 25 +- lib/textCleaning.js | 2 +- lib/textFormatting.js | 46 +- lib/textGeneration.js | 12 +- lib/textMaskingAndSecurity.js | 24 +- lib/textMetadataAndExtraction.js | 160 +++---- lib/textSpecializedOperations.js | 4 +- lib/textTransformations.js | 22 +- package-lock.json | 581 ++++++++++++++++++++++++++ package.json | 6 +- tests/index.test.js | 692 ++++++++++++++++--------------- tests/textTransformation.test.js | 46 +- 21 files changed, 1230 insertions(+), 612 deletions(-) diff --git a/.babelrc b/.babelrc index a80efbf..d604723 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,4 @@ { - "presets": ["@babel/preset-env"], - "plugins": ["@babel/plugin-transform-modules-commonjs"] - - } - \ No newline at end of file + "presets": ["@babel/preset-env"], + "plugins": ["@babel/plugin-transform-modules-commonjs"] +} diff --git a/.eslintignore b/.eslintignore index 4c5b351..b6843a1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,12 @@ -tests/*.test.js \ No newline at end of file +node_modules/ +.DS_Store +*.log +*.lock +*.env +.github/ +.husky + +*.md +*.MD + +package-lock.json \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index 9a981ae..bee47c5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,19 +1,21 @@ { - "env": { - "browser": true, - "es2021": true + "env": { + "browser": true, + "es2021": true, + "jest/globals": true + }, + "extends": ["eslint:recommended", "prettier"], + "parserOptions": { + "ecmaFeatures": { + "jsx": true }, - "extends": ["eslint:recommended", "prettier"], - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": "latest", - "sourceType": "module" - }, - "rules": { - "indent": ["warn", "tab"], - "quotes": ["error", "single"], - "semi": ["error", "always"] - } -} \ No newline at end of file + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": ["jest"], + "rules": { + "indent": ["warn", 2], + "quotes": ["error", "single"], + "semi": ["error", "always"] + } +} diff --git a/.prettierrc.json b/.prettierrc.json index 6d99820..611317a 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,9 +1,9 @@ { - "tabWidth": 2, - "useTabs": true, - "printWidth": 80, - "semi": true, - "trailingComma": "es5", - "jsxSingleQuote": true, - "singleQuote": true -} \ No newline at end of file + "tabWidth": 2, + "useTabs": false, + "printWidth": 80, + "semi": true, + "trailingComma": "es5", + "jsxSingleQuote": true, + "singleQuote": true +} diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md index 905f419..10f5adb 100644 --- a/CONTRIBUTE.md +++ b/CONTRIBUTE.md @@ -5,9 +5,10 @@This is a paragraph.
Click here' Expected Output: ['', '
', '', ''] Write your code here and export the function. */ - return string.match(/<[^>]+>/g) || []; + return string.match(/<[^>]+>/g) || []; } function extractDates(string) { - /* + /* Input: 'Meeting on 12/31/2022. Event: 01-15-2023' Expected Output: ['12/31/2022', '01-15-2023'] Write your code here and export the function. */ - return string.match(/\b\d{1,2}\/\d{1,2}\/\d{2,4}\b/g) || []; + return string.match(/\b\d{1,2}\/\d{1,2}\/\d{2,4}\b/g) || []; } function extractPhoneNumbers(string) { - /* + /* Input: 'Contact us at 123-456-7890 or +1 (987) 654-3210.' Expected Output: ['123-456-7890', '+1 (987) 654-3210'] Write your code here and export the function. */ - return string.match(/\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b/g) || []; + return string.match(/\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b/g) || []; } function extractIPv4Addresses(string) { - /* + /* Input: 'IP addresses: 192.168.1.1 and 10.0.0.1' Expected Output: ['192.168.1.1', '10.0.0.1'] Write your code here and export the function. */ - return string.match(/\b(?:\d{1,3}\.){3}\d{1,3}\b/g) || []; + return string.match(/\b(?:\d{1,3}\.){3}\d{1,3}\b/g) || []; } function extractIPv6Addresses(string) { - /* + /* Input: 'IPv6 addresses: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 and fe80::1' Expected Output: ['2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'fe80::1'] Write your code here and export the function. */ - return string.match(/(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}\b/g) || []; + return string.match(/(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}\b/g) || []; } function extractFilePaths(string) { - /* + /* Input: 'File paths: /path/to/file1.txt and C:\Documents\file2.docx' Expected Output: ['/path/to/file1.txt', 'C:\Documents\file2.docx'] Write your code here and export the function. */ - return string.match(/\/\S+\.\S+|\\[A-Za-z]:\\(?:\w+\\)+\w+\.\w+/g) || []; + return string.match(/\/\S+\.\S+|\\[A-Za-z]:\\(?:\w+\\)+\w+\.\w+/g) || []; } function extractDomainNames(string) { - /* + /* Input: 'Visit https://www.example.com for more info.' Expected Output: ['www.example.com'] Write your code here and export the function. */ - return ( - string.match( - /\b(?:https?:\/\/)?(?:www\.)?([a-zA-Z0-9-]+(?:\.[a-zA-Z]{2,})+)\b/g - ) || [] - ); + return ( + string.match( + /\b(?:https?:\/\/)?(?:www\.)?([a-zA-Z0-9-]+(?:\.[a-zA-Z]{2,})+)\b/g + ) || [] + ); } function extractJSONStrings(string) { - /* + /* Input: '{"key": "value", "nested": {"inner": 42}}' Expected Output: ['{"key": "value", "nested": {"inner": 42}}'] Write your code here and export the function. */ - return string.match(/\{(?:[^{}]|(?:\{[^{}]*\}))*\}/g) || []; + return string.match(/\{(?:[^{}]|(?:\{[^{}]*\}))*\}/g) || []; } // Grouped exports export { - extractNumbers, - countWords, - countCharacter, - findPositions, - extractHashtags, - extractURLs, - extractEmails, - extractMentions, - extractParenthesizedContent, - extractQuotedText, - extractHTMLTags, - extractDates, - extractPhoneNumbers, - extractIPv4Addresses, - extractIPv6Addresses, - extractFilePaths, - extractDomainNames, - extractJSONStrings, + extractNumbers, + countWords, + countCharacter, + findPositions, + extractHashtags, + extractURLs, + extractEmails, + extractMentions, + extractParenthesizedContent, + extractQuotedText, + extractHTMLTags, + extractDates, + extractPhoneNumbers, + extractIPv4Addresses, + extractIPv6Addresses, + extractFilePaths, + extractDomainNames, + extractJSONStrings, }; diff --git a/lib/textSpecializedOperations.js b/lib/textSpecializedOperations.js index a4fdeae..4b607aa 100644 --- a/lib/textSpecializedOperations.js +++ b/lib/textSpecializedOperations.js @@ -3,12 +3,12 @@ function isBalancedBrackets(string) { // Input: '(Hello [World])' // Output: true const stack = []; - const brackets = { "(": ")", "[": "]", "{": "}" }; + const brackets = { '(': ')', '[': ']', '{': '}' }; for (const char of string) { if (brackets[char]) { stack.push(brackets[char]); - } else if ([")", "]", "}"].includes(char)) { + } else if ([')', ']', '}'].includes(char)) { if (stack.pop() !== char) return false; } } diff --git a/lib/textTransformations.js b/lib/textTransformations.js index fb2e299..9dcb118 100644 --- a/lib/textTransformations.js +++ b/lib/textTransformations.js @@ -4,7 +4,7 @@ function shorten(string, length, ending) { // Input: 'This is a long string', 10 // Output: 'This is a ...read more' if (string.length <= length) return string; - return string.substring(0, length) + "..." + ending; + return string.substring(0, length) + '...' + ending; } // Wraps text to a specified width. @@ -12,8 +12,8 @@ function wordWrap(string, width) { // Input: 'This is a long string that needs to be wrapped.', 20 // Output: 'This is a long\nstring that needs\nto be wrapped.' return string.replace( - new RegExp(`(?![^\\n]{1,${width}}$)([^\\n]{1,${width}})\\s`, "g"), - "$1\n" + new RegExp(`(?![^\\n]{1,${width}}$)([^\\n]{1,${width}})\\s`, 'g'), + '$1\n' ); } @@ -25,9 +25,12 @@ function shuffle(string) { Mix up those characters! Write your shuffle logic and export the function. */ // split the string and sort it in any random order - return (typeof string === "string" || string instanceof String) ? - string.split('').sort(() => Math.random() - 0.5).join('') : ""; - + return typeof string === 'string' || string instanceof String + ? string + .split('') + .sort(() => Math.random() - 0.5) + .join('') + : ''; } // Removes duplicate characters from a string. function removeDuplicates(string) { @@ -36,8 +39,11 @@ function removeDuplicates(string) { Expected Output: 'abcd' Sweep away those duplicates! Implement your logic and don't forget to export the function. */ - // adding to Set to remove duplicates - const characterArray = (typeof string === "string" || string instanceof String) ? string.split('') : []; + // adding to Set to remove duplicates + const characterArray = + typeof string === 'string' || string instanceof String + ? string.split('') + : []; const uniqueCharactersSet = Array.from(new Set(characterArray)); return uniqueCharactersSet.join(''); } diff --git a/package-lock.json b/package-lock.json index 78203a5..3c509be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "eslint": "^8.54.0", "eslint-config-prettier": "9.0.0", "eslint-formatter-table": "^7.32.1", + "eslint-plugin-jest": "^27.6.3", "husky": "^8.0.0", "jest": "^29.7.0", "lint-staged": "^15.1.0", @@ -2505,6 +2506,12 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true + }, "node_modules/@types/node": { "version": "20.9.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.9.4.tgz", @@ -2514,6 +2521,12 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/semver": { + "version": "7.5.6", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.6.tgz", + "integrity": "sha512-dn1l8LaMea/IjDoHNd9J52uBbInB796CDffS6VdIxvqYCPSG0V0DzHp76GpaWnlhg88uYyPbXCDIowa86ybd5A==", + "dev": true + }, "node_modules/@types/stack-utils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", @@ -2535,6 +2548,194 @@ "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", "dev": true }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz", + "integrity": "sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/visitor-keys": "5.62.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/types": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.62.0.tgz", + "integrity": "sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz", + "integrity": "sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/visitor-keys": "5.62.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "node_modules/@typescript-eslint/utils": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.62.0.tgz", + "integrity": "sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@types/json-schema": "^7.0.9", + "@types/semver": "^7.3.12", + "@typescript-eslint/scope-manager": "5.62.0", + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/typescript-estree": "5.62.0", + "eslint-scope": "^5.1.1", + "semver": "^7.3.7" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz", + "integrity": "sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "5.62.0", + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, "node_modules/@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", @@ -2639,6 +2840,15 @@ "sprintf-js": "~1.0.2" } }, + "node_modules/array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/astral-regex": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", @@ -3221,6 +3431,18 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "dependencies": { + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -3370,6 +3592,31 @@ "node": "^10.12.0 || >=12.0.0" } }, + "node_modules/eslint-plugin-jest": { + "version": "27.6.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.6.3.tgz", + "integrity": "sha512-+YsJFVH6R+tOiO3gCJon5oqn4KWc+mDq2leudk8mrp8RFubLOo9CVyi3cib4L7XMpxExmkmBZQTPDYVBzgpgOA==", + "dev": true, + "dependencies": { + "@typescript-eslint/utils": "^5.10.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + }, + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^5.0.0 || ^6.0.0", + "eslint": "^7.0.0 || ^8.0.0", + "jest": "*" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + }, + "jest": { + "optional": true + } + } + }, "node_modules/eslint-scope": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", @@ -3633,6 +3880,34 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "node_modules/fast-glob": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -3829,6 +4104,26 @@ "node": ">=4" } }, + "node_modules/globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "dependencies": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -5368,6 +5663,15 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, + "node_modules/merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, "node_modules/micromatch": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", @@ -5602,6 +5906,15 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "node_modules/path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -6305,6 +6618,27 @@ "node": ">=8.0" } }, + "node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + }, + "node_modules/tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "dependencies": { + "tslib": "^1.8.1" + }, + "engines": { + "node": ">= 6" + }, + "peerDependencies": { + "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + } + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -6338,6 +6672,20 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, + "peer": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", @@ -8360,6 +8708,12 @@ "@types/istanbul-lib-report": "*" } }, + "@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true + }, "@types/node": { "version": "20.9.4", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.9.4.tgz", @@ -8369,6 +8723,12 @@ "undici-types": "~5.26.4" } }, + "@types/semver": { + "version": "7.5.6", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.6.tgz", + "integrity": "sha512-dn1l8LaMea/IjDoHNd9J52uBbInB796CDffS6VdIxvqYCPSG0V0DzHp76GpaWnlhg88uYyPbXCDIowa86ybd5A==", + "dev": true + }, "@types/stack-utils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", @@ -8390,6 +8750,131 @@ "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", "dev": true }, + "@typescript-eslint/scope-manager": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz", + "integrity": "sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w==", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/visitor-keys": "5.62.0" + } + }, + "@typescript-eslint/types": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.62.0.tgz", + "integrity": "sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==", + "dev": true + }, + "@typescript-eslint/typescript-estree": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz", + "integrity": "sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA==", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/visitor-keys": "5.62.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "semver": "^7.3.7", + "tsutils": "^3.21.0" + }, + "dependencies": { + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + } + } + }, + "@typescript-eslint/utils": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.62.0.tgz", + "integrity": "sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==", + "dev": true, + "requires": { + "@eslint-community/eslint-utils": "^4.2.0", + "@types/json-schema": "^7.0.9", + "@types/semver": "^7.3.12", + "@typescript-eslint/scope-manager": "5.62.0", + "@typescript-eslint/types": "5.62.0", + "@typescript-eslint/typescript-estree": "5.62.0", + "eslint-scope": "^5.1.1", + "semver": "^7.3.7" + }, + "dependencies": { + "eslint-scope": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", + "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "dev": true, + "requires": { + "esrecurse": "^4.3.0", + "estraverse": "^4.1.1" + } + }, + "estraverse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", + "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "dev": true + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, + "semver": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + } + } + }, + "@typescript-eslint/visitor-keys": { + "version": "5.62.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz", + "integrity": "sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw==", + "dev": true, + "requires": { + "@typescript-eslint/types": "5.62.0", + "eslint-visitor-keys": "^3.3.0" + } + }, "@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", @@ -8464,6 +8949,12 @@ "sprintf-js": "~1.0.2" } }, + "array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true + }, "astral-regex": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", @@ -8873,6 +9364,15 @@ "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==", "dev": true }, + "dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "requires": { + "path-type": "^4.0.0" + } + }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -9056,6 +9556,15 @@ "table": "^6.0.9" } }, + "eslint-plugin-jest": { + "version": "27.6.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-27.6.3.tgz", + "integrity": "sha512-+YsJFVH6R+tOiO3gCJon5oqn4KWc+mDq2leudk8mrp8RFubLOo9CVyi3cib4L7XMpxExmkmBZQTPDYVBzgpgOA==", + "dev": true, + "requires": { + "@typescript-eslint/utils": "^5.10.0" + } + }, "eslint-scope": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", @@ -9167,6 +9676,30 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "fast-glob": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "dependencies": { + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + } + } + }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -9314,6 +9847,20 @@ "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", "dev": true }, + "globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "requires": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" + } + }, "graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -10438,6 +10985,12 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, + "merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true + }, "micromatch": { "version": "4.0.5", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", @@ -10614,6 +11167,12 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true + }, "picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -11102,6 +11661,21 @@ "is-number": "^7.0.0" } }, + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true + }, + "tsutils": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", + "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "dev": true, + "requires": { + "tslib": "^1.8.1" + } + }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -11123,6 +11697,13 @@ "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", "dev": true }, + "typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "dev": true, + "peer": true + }, "undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", diff --git a/package.json b/package.json index 5e21e99..e55249b 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "author": "", "scripts": { "test": "jest", - "prepare": "husky install" + "prepare": "husky install", + "lint": "eslint --fix --ignore-path .eslintignore . && prettier --write . --tab-width 2" }, "license": "ISC", "devDependencies": { @@ -18,6 +19,7 @@ "eslint": "^8.54.0", "eslint-config-prettier": "9.0.0", "eslint-formatter-table": "^7.32.1", + "eslint-plugin-jest": "^27.6.3", "husky": "^8.0.0", "jest": "^29.7.0", "lint-staged": "^15.1.0", @@ -29,4 +31,4 @@ "prettier --write" ] } -} \ No newline at end of file +} diff --git a/tests/index.test.js b/tests/index.test.js index 9924774..819a0b5 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -1,425 +1,435 @@ import { - capitalize, - extractNumbers, - countWords, - isBalancedBrackets, - levenshteinDistance, - maskEmail, - maskPhone, - invertCase, - extractHashtags, - formatTime, - extractURLs, - extractEmails, - extractMentions, - extractParenthesizedContent, - extractQuotedText, - extractHTMLTags, - extractDates, - extractPhoneNumbers, - extractIPv4Addresses, - extractIPv6Addresses, - extractFilePaths, - extractDomainNames, - extractJSONStrings, - removeWhitespace, - trimStart, - trimEnd, + capitalize, + extractNumbers, + countWords, + isBalancedBrackets, + levenshteinDistance, + maskEmail, + maskPhone, + invertCase, + extractHashtags, + formatTime, + extractURLs, + extractEmails, + extractMentions, + extractParenthesizedContent, + extractQuotedText, + extractHTMLTags, + extractDates, + extractPhoneNumbers, + extractIPv4Addresses, + extractIPv6Addresses, + extractFilePaths, + extractDomainNames, + extractJSONStrings, + removeWhitespace, + trimStart, + trimEnd, } from '../index'; describe('capitalize', () => { - test('capitalizes the first letter of a word', () => { - expect(capitalize('stringy')).toBe('Stringy'); - }); + test('capitalizes the first letter of a word', () => { + expect(capitalize('stringy')).toBe('Stringy'); + }); }); describe('extractNumbers', () => { - test('extracts numbers from a string containing multiple numbers', () => { - expect(extractNumbers('Order 500 units of item 1234.')).toEqual([ - 500, 1234, - ]); - }); + test('extracts numbers from a string containing multiple numbers', () => { + expect(extractNumbers('Order 500 units of item 1234.')).toEqual([ + 500, 1234, + ]); + }); - test('returns an empty array when the string contains no numbers', () => { - expect(extractNumbers('No numbers here!')).toEqual([]); - }); + test('returns an empty array when the string contains no numbers', () => { + expect(extractNumbers('No numbers here!')).toEqual([]); + }); - // More tests for extractNumbers... + // More tests for extractNumbers... }); describe('countWords', () => { - test('counts the number of words in a regular sentence', () => { - expect(countWords('Hello world, this is a test.')).toBe(6); - }); + test('counts the number of words in a regular sentence', () => { + expect(countWords('Hello world, this is a test.')).toBe(6); + }); - test('counts correctly with multiple spaces between words', () => { - expect(countWords('Hello world')).toBe(2); - }); + test('counts correctly with multiple spaces between words', () => { + expect(countWords('Hello world')).toBe(2); + }); - // More tests for countWords... + // More tests for countWords... }); describe('isBalancedBrackets', () => { - test('returns true for a string with balanced brackets', () => { - expect(isBalancedBrackets('(Hello [World])')).toBe(true); - }); + test('returns true for a string with balanced brackets', () => { + expect(isBalancedBrackets('(Hello [World])')).toBe(true); + }); - test('returns false for a string with unbalanced brackets', () => { - expect(isBalancedBrackets('(Hello [World)')).toBe(false); - }); + test('returns false for a string with unbalanced brackets', () => { + expect(isBalancedBrackets('(Hello [World)')).toBe(false); + }); }); describe('levenshteinDistance', () => { - test('returns 0 for identical strings', () => { - expect(levenshteinDistance('hello', 'hello')).toBe(0); - }); + test('returns 0 for identical strings', () => { + expect(levenshteinDistance('hello', 'hello')).toBe(0); + }); - test('calculates the correct distance between two different strings', () => { - expect(levenshteinDistance('kitten', 'sitting')).toBe(3); - }); + test('calculates the correct distance between two different strings', () => { + expect(levenshteinDistance('kitten', 'sitting')).toBe(3); + }); - // More tests for levenshteinDistance... + // More tests for levenshteinDistance... }); describe('maskEmail', () => { - test('masks a standard email address correctly', () => { - expect(maskEmail('user@example.com')).toBe('u***@e******.com'); - }); + test('masks a standard email address correctly', () => { + expect(maskEmail('user@example.com')).toBe('u***@e******.com'); + }); - // More tests for maskEmail... + // More tests for maskEmail... }); describe('invertCase', () => { - test('Inverts the case of each character in a given string', () => { - expect(invertCase('Hello World')).toBe('hELLO wORLD'); - }); - - test('Check for whitespace', () => { - expect(invertCase(' ')).toBe(' '); - }); - - test('Check for all uppercase words', () => { - expect(invertCase('ABCD')).toBe('abcd'); - }); - - test('Check for all lowercase words', () => { - expect(invertCase('abcd')).toBe('ABCD'); - }); - - test('Check for Mixed Case with Numbers and Symbols', () => { - expect(invertCase('aBc 123 !@#')).toBe('AbC 123 !@#'); - }); - - test('Check for String with Special Characters', () => { - expect(invertCase('HeLLo @WorLD!')).toBe('hEllO @wORld!'); - }); - - test('Check for String with Whitespaces', () => { - expect(invertCase(' InVeRt CaSe ')).toBe(' iNvErT cAsE '); - }); - - test('Check for Long String', () => { - expect( - invertCase( - 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.' - ) - ).toBe( - 'lOREM iPSUM IS SIMPLY DUMMY TEXT OF THE PRINTING AND TYPESETTING INDUSTRY.' - ); - }); - - test('Check for String with Non-alphabetic Characters', () => { - expect(invertCase('!@#%^&*()')).toBe('!@#%^&*()'); - }); - - test('Check for String with Newline and Tab Characters', () => { - expect(invertCase('Hello\n\tWorld')).toBe('hELLO\n\twORLD'); - }); + test('Inverts the case of each character in a given string', () => { + expect(invertCase('Hello World')).toBe('hELLO wORLD'); + }); + + test('Check for whitespace', () => { + expect(invertCase(' ')).toBe(' '); + }); + + test('Check for all uppercase words', () => { + expect(invertCase('ABCD')).toBe('abcd'); + }); + + test('Check for all lowercase words', () => { + expect(invertCase('abcd')).toBe('ABCD'); + }); + + test('Check for Mixed Case with Numbers and Symbols', () => { + expect(invertCase('aBc 123 !@#')).toBe('AbC 123 !@#'); + }); + + test('Check for String with Special Characters', () => { + expect(invertCase('HeLLo @WorLD!')).toBe('hEllO @wORld!'); + }); + + test('Check for String with Whitespaces', () => { + expect(invertCase(' InVeRt CaSe ')).toBe(' iNvErT cAsE '); + }); + + test('Check for Long String', () => { + expect( + invertCase( + 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.' + ) + ).toBe( + 'lOREM iPSUM IS SIMPLY DUMMY TEXT OF THE PRINTING AND TYPESETTING INDUSTRY.' + ); + }); + + test('Check for String with Non-alphabetic Characters', () => { + expect(invertCase('!@#%^&*()')).toBe('!@#%^&*()'); + }); + + test('Check for String with Newline and Tab Characters', () => { + expect(invertCase('Hello\n\tWorld')).toBe('hELLO\n\twORLD'); + }); }); describe('maskPhone', () => { - test('masks phone number with default visibleDigits', () => { - const phoneNumber = '1234567890'; - expect(maskPhone(phoneNumber)).toBe('******7890'); - }); - - test('masks phone number with custom visibleDigits', () => { - const phoneNumber = '9876543210'; - const visibleDigits = 3; - expect(maskPhone(phoneNumber, visibleDigits)).toBe('*******210'); - }); - - test('throws error for invalid phone number with special characters', () => { - const invalidPhoneNumber = '1-23-45-67-890'; - expect(() => maskPhone(invalidPhoneNumber)).toThrowError( - 'Invalid input. Please provide a non-negative integer for visibleDigits, and ensure it is not greater than the length of the phone number.' - ); - }); - - // Add more test cases as needed... + test('masks phone number with default visibleDigits', () => { + const phoneNumber = '1234567890'; + expect(maskPhone(phoneNumber)).toBe('******7890'); + }); + + test('masks phone number with custom visibleDigits', () => { + const phoneNumber = '9876543210'; + const visibleDigits = 3; + expect(maskPhone(phoneNumber, visibleDigits)).toBe('*******210'); + }); + + test('throws error for invalid phone number with special characters', () => { + const invalidPhoneNumber = '1-23-45-67-890'; + expect(() => maskPhone(invalidPhoneNumber)).toThrowError( + 'Invalid input. Please provide a non-negative integer for visibleDigits, and ensure it is not greater than the length of the phone number.' + ); + }); + + // Add more test cases as needed... }); describe('extractHashtags', () => { - test('extracts hashtags from a string containing multiple hashtags', () => { - expect(extractHashtags('This is a #sample string with #hashtags')).toEqual([ - '#sample', - '#hashtags', - ]); - }); - - test('returns an empty array when the string contains no hashtags', () => { - expect(extractHashtags('No hashtags here!')).toEqual([]); - }); - - test('returns an empty array when the string is not a string', () => { - expect(extractHashtags(1234)).toEqual([]); - }); - - // More tests for extractHashtags... + test('extracts hashtags from a string containing multiple hashtags', () => { + expect(extractHashtags('This is a #sample string with #hashtags')).toEqual([ + '#sample', + '#hashtags', + ]); + }); + + test('returns an empty array when the string contains no hashtags', () => { + expect(extractHashtags('No hashtags here!')).toEqual([]); + }); + + test('returns an empty array when the string is not a string', () => { + expect(extractHashtags(1234)).toEqual([]); + }); + + // More tests for extractHashtags... }); describe('formatTime', () => { - test('formats a time string', () => { - expect(formatTime('2023-03-01T15:30:00')).toBe('3:30 PM'); - }); + test('formats a time string', () => { + expect(formatTime('2023-03-01T15:30:00')).toBe('3:30 PM'); + }); - test('formats a time string with locale', () => { - expect(formatTime('2023-03-01T15:30:00', 'en-IN')).toBe('3:30 pm'); - }); + test('formats a time string with locale', () => { + expect(formatTime('2023-03-01T15:30:00', 'en-IN')).toBe('3:30 pm'); + }); - test('formats a time string with invalid date', () => { - expect(formatTime('abcd', 'en-IN')).toBe('Invalid Date'); - }); + test('formats a time string with invalid date', () => { + expect(formatTime('abcd', 'en-IN')).toBe('Invalid Date'); + }); - // More test for formatTime... + // More test for formatTime... }); describe('extractURLs', () => { - test('extracts URLs from a string containing multiple URLs', () => { - expect( - extractURLs('Visit https://example.com for more information.') - ).toEqual(['https://example.com']); - }); - - test('returns an empty array when the string contains no URLs', () => { - expect(extractURLs('No URLs here.')).toEqual([]); - }); + test('extracts URLs from a string containing multiple URLs', () => { + expect( + extractURLs('Visit https://example.com for more information.') + ).toEqual(['https://example.com']); + }); + + test('returns an empty array when the string contains no URLs', () => { + expect(extractURLs('No URLs here.')).toEqual([]); + }); }); describe('extractEmails', () => { - test('extracts email addresses from a string containing multiple emails', () => { - expect( - extractEmails('Contact us at info@example.com or support@test.org.') - ).toEqual(['info@example.com', 'support@test.org']); - }); - - test('returns an empty array when the string contains no email addresses', () => { - expect(extractEmails('No emails here.')).toEqual([]); - }); + test('extracts email addresses from a string containing multiple emails', () => { + expect( + extractEmails('Contact us at info@example.com or support@test.org.') + ).toEqual(['info@example.com', 'support@test.org']); + }); + + test('returns an empty array when the string contains no email addresses', () => { + expect(extractEmails('No emails here.')).toEqual([]); + }); }); describe('extractMentions', () => { - test('extracts mentions from a string containing mentions', () => { - expect(extractMentions('This is a @mention example.')).toEqual([ - '@mention', - ]); - }); - - test('returns an empty array when the string contains no mentions', () => { - expect(extractMentions('No mentions here.')).toEqual([]); - }); + test('extracts mentions from a string containing mentions', () => { + expect(extractMentions('This is a @mention example.')).toEqual([ + '@mention', + ]); + }); + + test('returns an empty array when the string contains no mentions', () => { + expect(extractMentions('No mentions here.')).toEqual([]); + }); }); describe('extractParenthesizedContent', () => { - test('extracts content within parentheses from a string', () => { - expect( - extractParenthesizedContent('This is (some content) within parentheses.') - ).toEqual(['(some content)']); - }); - - test('returns an empty array when the string contains no content within parentheses', () => { - expect(extractParenthesizedContent('No parentheses here.')).toEqual([]); - }); + test('extracts content within parentheses from a string', () => { + expect( + extractParenthesizedContent('This is (some content) within parentheses.') + ).toEqual(['(some content)']); + }); + + test('returns an empty array when the string contains no content within parentheses', () => { + expect(extractParenthesizedContent('No parentheses here.')).toEqual([]); + }); }); describe('extractQuotedText', () => { - test('extracts quoted text from a string containing quotes', () => { - expect(extractQuotedText('She said, "This is a quoted text."')).toEqual([ - '"This is a quoted text."', - ]); - }); - - test('returns an empty array when the string contains no quoted text', () => { - expect(extractQuotedText('No quotes here.')).toEqual([]); - }); + test('extracts quoted text from a string containing quotes', () => { + expect(extractQuotedText('She said, "This is a quoted text."')).toEqual([ + '"This is a quoted text."', + ]); + }); + + test('returns an empty array when the string contains no quoted text', () => { + expect(extractQuotedText('No quotes here.')).toEqual([]); + }); }); describe('extractHTMLTags', () => { - test('extracts HTML tags from a string containing HTML', () => { - expect( - extractHTMLTags('This is a paragraph.
Click here') - ).toEqual(['', '
', '', '']); - }); - - test('returns an empty array when the string contains no HTML tags', () => { - expect(extractHTMLTags('No HTML tags here.')).toEqual([]); - }); + test('extracts HTML tags from a string containing HTML', () => { + expect( + extractHTMLTags('This is a paragraph.
Click here') + ).toEqual(['', '
', '', '']); + }); + + test('returns an empty array when the string contains no HTML tags', () => { + expect(extractHTMLTags('No HTML tags here.')).toEqual([]); + }); }); -// describe("extractDates", () => { -// test("extracts dates from a string containing dates", () => { -// expect(extractDates("Meeting on 12/31/2022. Event: 01-15-2023")).toEqual([ -// '12/31/2022', '01-15-2023', -// ]); -// }); - -// test("returns an empty array when the string contains no dates", () => { -// expect(extractDates("No dates here.")).toEqual([]); -// }); -// }); - -// describe("extractPhoneNumbers", () => { -// test("extracts phone numbers from a string containing phone numbers", () => { -// expect(extractPhoneNumbers("Contact us at 123-456-7890 or +1 (987) 654-3210.")).toEqual([ -// '123-456-7890', '+1 (987) 654-3210', -// ]); -// }); - -// test("returns an empty array when the string contains no phone numbers", () => { -// expect(extractPhoneNumbers("No phone numbers here.")).toEqual([]); -// }); -// }); - -// describe("extractIPv4Addresses", () => { -// test("extracts IPv4 addresses from a string containing IPv4 addresses", () => { -// expect(extractIPv4Addresses("IP addresses: 192.168.1.1 and 10.0.0.1")).toEqual([ -// '192.168.1.1', '10.0.0.1', -// ]); -// }); - -// test("returns an empty array when the string contains no IPv4 addresses", () => { -// expect(extractIPv4Addresses("No IPv4 addresses here.")).toEqual([]); -// }); -// }); - -// describe("extractIPv6Addresses", () => { -// test("extracts IPv6 addresses from a string containing IPv6 addresses", () => { -// expect(extractIPv6Addresses("IPv6 addresses: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 and fe80::1")).toEqual([ -// '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'fe80::1', -// ]); -// }); - -// test("returns an empty array when the string contains no IPv6 addresses", () => { -// expect(extractIPv6Addresses("No IPv6 addresses here.")).toEqual([]); -// }); -// }); - -// describe("extractFilePaths", () => { -// test("extracts file paths from a string containing file paths", () => { -// expect(extractFilePaths("File paths: /path/to/file1.txt and C:\\Documents\\file2.docx")).toEqual([ -// '/path/to/file1.txt', 'C:\\Documents\\file2.docx', -// ]); -// }); - -// test("returns an empty array when the string contains no file paths", () => { -// expect(extractFilePaths("No file paths here.")).toEqual([]); -// }); -// }); - -// describe("extractDomainNames", () => { -// test("extracts domain names from a string containing domain names", () => { -// expect(extractDomainNames("Visit https://www.example.com for more info.")).toEqual([ -// 'www.example.com', -// ]); -// }); - -// test("returns an empty array when the string contains no domain names", () => { -// expect(extractDomainNames("No domain names here.")).toEqual([]); -// }); -// }); +describe('extractDates', () => { + // Todo: remove `skip` when test fail issue resolved + test.skip('extracts dates from a string containing dates', () => { + expect(extractDates('Meeting on 12/31/2022. Event: 01-15-2023')).toEqual([ + '12/31/2022', + '01-15-2023', + ]); + }); + + test('returns an empty array when the string contains no dates', () => { + expect(extractDates('No dates here.')).toEqual([]); + }); +}); + +describe('extractPhoneNumbers', () => { + // Todo: remove `skip` when test fail issue resolved + test.skip('extracts phone numbers from a string containing phone numbers', () => { + expect( + extractPhoneNumbers('Contact us at 123-456-7890 or +1 (987) 654-3210.') + ).toEqual(['123-456-7890', '+1 (987) 654-3210']); + }); + + test('returns an empty array when the string contains no phone numbers', () => { + expect(extractPhoneNumbers('No phone numbers here.')).toEqual([]); + }); +}); + +describe('extractIPv4Addresses', () => { + test('extracts IPv4 addresses from a string containing IPv4 addresses', () => { + expect( + extractIPv4Addresses('IP addresses: 192.168.1.1 and 10.0.0.1') + ).toEqual(['192.168.1.1', '10.0.0.1']); + }); + + test('returns an empty array when the string contains no IPv4 addresses', () => { + expect(extractIPv4Addresses('No IPv4 addresses here.')).toEqual([]); + }); +}); + +describe('extractIPv6Addresses', () => { + // Todo: remove `skip` when test fail issue resolved + test.skip('extracts IPv6 addresses from a string containing IPv6 addresses', () => { + expect( + extractIPv6Addresses( + 'IPv6 addresses: 2001:0db8:85a3:0000:0000:8a2e:0370:7334 and fe80::1' + ) + ).toEqual(['2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'fe80::1']); + }); + + test('returns an empty array when the string contains no IPv6 addresses', () => { + expect(extractIPv6Addresses('No IPv6 addresses here.')).toEqual([]); + }); +}); + +describe('extractFilePaths', () => { + // Todo: remove `skip` when test fail issue resolved + test.skip('extracts file paths from a string containing file paths', () => { + expect( + extractFilePaths( + 'File paths: /path/to/file1.txt and C:\\Documents\\file2.docx' + ) + ).toEqual(['/path/to/file1.txt', 'C:\\Documents\\file2.docx']); + }); + + test('returns an empty array when the string contains no file paths', () => { + expect(extractFilePaths('No file paths here.')).toEqual([]); + }); +}); + +describe('extractDomainNames', () => { + // Todo: remove `skip` when test fail issue resolved + test.skip('extracts domain names from a string containing domain names', () => { + expect( + extractDomainNames('Visit https://www.example.com for more info.') + ).toEqual(['www.example.com']); + }); + + test('returns an empty array when the string contains no domain names', () => { + expect(extractDomainNames('No domain names here.')).toEqual([]); + }); +}); describe('extractJSONStrings', () => { - test('extracts JSON strings from a string containing JSON strings', () => { - expect( - extractJSONStrings('{"key": "value", "nested": {"inner": 42}}') - ).toEqual(['{"key": "value", "nested": {"inner": 42}}']); - }); - - test('returns an empty array when the string contains no JSON strings', () => { - expect(extractJSONStrings('No JSON strings here.')).toEqual([]); - }); + test('extracts JSON strings from a string containing JSON strings', () => { + expect( + extractJSONStrings('{"key": "value", "nested": {"inner": 42}}') + ).toEqual(['{"key": "value", "nested": {"inner": 42}}']); + }); + + test('returns an empty array when the string contains no JSON strings', () => { + expect(extractJSONStrings('No JSON strings here.')).toEqual([]); + }); }); describe('removeWhitespace', () => { - test('removes whitespace from a string', () => { - expect(removeWhitespace(' Hello World from STRING Utils! ')).toEqual( - 'HelloWorldfromSTRINGUtils!' - ); - }); - - test('handles a string with multiple spaces between words', () => { - expect(removeWhitespace('Multiple Spaces Between Words')).toEqual( - 'MultipleSpacesBetweenWords' - ); - }); - - test('handles an empty string', () => { - expect(removeWhitespace('')).toEqual(''); - }); - - test('handles an number', () => { - expect(removeWhitespace(123)).toEqual('Invalid String'); - }); - - // Add more test cases as needed... + test('removes whitespace from a string', () => { + expect(removeWhitespace(' Hello World from STRING Utils! ')).toEqual( + 'HelloWorldfromSTRINGUtils!' + ); + }); + + test('handles a string with multiple spaces between words', () => { + expect(removeWhitespace('Multiple Spaces Between Words')).toEqual( + 'MultipleSpacesBetweenWords' + ); + }); + + test('handles an empty string', () => { + expect(removeWhitespace('')).toEqual(''); + }); + + test('handles an number', () => { + expect(removeWhitespace(123)).toEqual('Invalid String'); + }); + + // Add more test cases as needed... }); describe('trimStart', () => { - test('removes leading whitespace from a string', () => { - expect(trimStart(' Hello World')).toEqual('Hello World'); - }); + test('removes leading whitespace from a string', () => { + expect(trimStart(' Hello World')).toEqual('Hello World'); + }); - test('handles a string with only whitespace', () => { - expect(trimStart(' ')).toEqual(''); - }); + test('handles a string with only whitespace', () => { + expect(trimStart(' ')).toEqual(''); + }); - test('handles a string with no leading whitespace', () => { - expect(trimStart('No Leading Whitespace')).toEqual('No Leading Whitespace'); - }); + test('handles a string with no leading whitespace', () => { + expect(trimStart('No Leading Whitespace')).toEqual('No Leading Whitespace'); + }); - test('handles an empty string', () => { - expect(trimStart('')).toEqual(''); - }); + test('handles an empty string', () => { + expect(trimStart('')).toEqual(''); + }); - test('handles a string with mixed whitespace characters', () => { - expect(trimStart('\t\r\n Leading Whitespace')).toEqual( - 'Leading Whitespace' - ); - }); + test('handles a string with mixed whitespace characters', () => { + expect(trimStart('\t\r\n Leading Whitespace')).toEqual( + 'Leading Whitespace' + ); + }); - // Add more test cases as needed... + // Add more test cases as needed... }); describe('trimEnd', () => { - test('removes trailing whitespace from a string', () => { - expect(trimEnd('Hello World ')).toEqual('Hello World'); - }); + test('removes trailing whitespace from a string', () => { + expect(trimEnd('Hello World ')).toEqual('Hello World'); + }); - test('handles a string with only whitespace', () => { - expect(trimEnd(' ')).toEqual(''); - }); + test('handles a string with only whitespace', () => { + expect(trimEnd(' ')).toEqual(''); + }); - test('handles a string with no trailing whitespace', () => { - expect(trimEnd('No Trailing Whitespace')).toEqual('No Trailing Whitespace'); - }); + test('handles a string with no trailing whitespace', () => { + expect(trimEnd('No Trailing Whitespace')).toEqual('No Trailing Whitespace'); + }); - test('handles an empty string', () => { - expect(trimEnd('')).toEqual(''); - }); + test('handles an empty string', () => { + expect(trimEnd('')).toEqual(''); + }); - test('handles a string with mixed whitespace characters', () => { - expect(trimEnd('Trailing Whitespace\t\r\n')).toEqual('Trailing Whitespace'); - }); + test('handles a string with mixed whitespace characters', () => { + expect(trimEnd('Trailing Whitespace\t\r\n')).toEqual('Trailing Whitespace'); + }); - // Add more test cases as needed... + // Add more test cases as needed... }); diff --git a/tests/textTransformation.test.js b/tests/textTransformation.test.js index 11aa0cf..58fbb04 100644 --- a/tests/textTransformation.test.js +++ b/tests/textTransformation.test.js @@ -1,63 +1,61 @@ // tests/textTransformations.test.js -import { shuffle, removeDuplicates } from "../lib/textTransformations"; +import { shuffle, removeDuplicates } from '../lib/textTransformations'; -describe("shuffle", () => { - test("string should be shuffled and not have the same order", () => { - const originalString = "abcdefghijklmnopqrstuvwxyz"; +describe('shuffle', () => { + test('string should be shuffled and not have the same order', () => { + const originalString = 'abcdefghijklmnopqrstuvwxyz'; const shuffledString = shuffle(originalString); // sorting the strigns to check they equal - const sortedOriginal = originalString.split("").sort().join(""); - const sortedShuffled = shuffledString.split("").sort().join(""); + const sortedOriginal = originalString.split('').sort().join(''); + const sortedShuffled = shuffledString.split('').sort().join(''); expect(sortedOriginal).toEqual(sortedShuffled); // Assert that at least one character is in a different position expect(originalString).not.toEqual(shuffledString); }); - test("return an empty string if string is not passed to shuffle", () => { + test('return an empty string if string is not passed to shuffle', () => { const nums = 1234; // Numbers // Remove Duplicate on passing any other type except string like number here const emptyString = shuffle(nums); // Check if the result contains empty string or not - expect(emptyString).toEqual(""); + expect(emptyString).toEqual(''); }); - }); -describe("removeDuplicates", () => { - test("string should have duplicates removed", () => { - const stringWithDuplicates = "aabbccddeeff"; - +describe('removeDuplicates', () => { + test('string should have duplicates removed', () => { + const stringWithDuplicates = 'aabbccddeeff'; + // Remove duplicates from the string const stringWithOutDuplicates = removeDuplicates(stringWithDuplicates); // Check that the result contains unique characters - expect(stringWithOutDuplicates).toEqual("abcdef"); - + expect(stringWithOutDuplicates).toEqual('abcdef'); }); - - test("removeDuplicates should not change a string with no duplicates", () => { - const stringWithOutDuplicates = "abcdef"; - + + test('removeDuplicates should not change a string with no duplicates', () => { + const stringWithOutDuplicates = 'abcdef'; + // Remove duplicates from the string const stringWithOutDuplicates2 = removeDuplicates(stringWithOutDuplicates); - + // Check that the result contains unique characters - expect(stringWithOutDuplicates2).toEqual("abcdef"); + expect(stringWithOutDuplicates2).toEqual('abcdef'); }); - test("return empty string if string is not passed to removeDuplicates", () => { + test('return empty string if string is not passed to removeDuplicates', () => { const bool = true; // Boolean // Remove duplicates on type boolean should return empty string const emptyString = removeDuplicates(bool); // Check if the result contains empty string or not - expect(emptyString).toEqual(""); - }) + expect(emptyString).toEqual(''); + }); });