Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra helpers for string module #113

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

samirsilwal
Copy link
Contributor

Description:

This PR introduces a set of utility functions that handle common string and array operations, such as checking string prefixes and suffixes, removing duplicates from arrays, and trimming whitespace. These functions enhance code reusability and reduce redundancy for string and array manipulations.

Changes Included:

  • startsWith(searchString):
Checks if a given string starts with a specific substring.
Returns false if the input is not a string.
Uses the built-in String.prototype.startsWith() method.
  • endsWith(searchString):
Checks if a given string ends with a specific substring.
Returns false if the input is not a string.
Uses the built-in String.prototype.endsWith() method.
  • unique(collection):
Extracts unique elements from an array.
Returns a new array with unique values.
Returns an empty string if the input is not an array or if it's empty.
Uses Set to filter out duplicates.
  • trim(string):
Trims whitespace from both ends of a string.
Returns the trimmed string if the input is a valid string.
Returns the input as is if it’s not a string.
Uses String.prototype.trim().

Testing:

  • Unit tests have been included for all functions to ensure correctness.
  • Edge cases for invalid input types have been handled.

@samirsilwal samirsilwal force-pushed the feat/add-additional-helpers branch from 4022dd6 to 915e2e9 Compare October 6, 2024 05:45
@samirsilwal samirsilwal force-pushed the feat/add-additional-helpers branch from d7342df to 002e944 Compare October 6, 2024 06:00
@mesaugat mesaugat self-requested a review October 16, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant