Skip to content

Conversation

@RobsonTrasel
Copy link
Contributor

Proposed changes

Adds new static methods (includesSome and includesEvery) to the String class, allowing checks for whether some or all of the provided search terms appear in the given string value. Includes comprehensive tests to ensure correct functionality under various scenarios.

Types of changes

What types of changes does your code introduce?

Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

Further comments

These new methods solve the need for checking substring inclusions in a more flexible way (checking for at least one or for all matches). Implementation follows existing patterns in the library, and the tests added provide coverage for multiple parameters, arrays, and edge cases (e.g., empty arrays).

RobsonTrasel added 3 commits March 1, 2025 22:00
- Creates the static includesSome method in String
- Checks if at least one of the given terms is included in the base string
- Creates the static includesEvery method in String
- Checks if all of the given terms are included in the base string
- Adds tests for includesSome with multiple params and with an array:
  * shouldReturnTrueIfAtLeastOneTermMatchesUsingMultipleParams
  * shouldReturnTrueIfAtLeastOneTermMatchesUsingAnArray
  * shouldReturnFalseForIncludesSomeWithEmptyTerms

- Adds tests for includesEvery with multiple params and with an array:
  * shouldReturnTrueOnlyIfAllTermsMatchUsingMultipleParams
  * shouldReturnTrueOnlyIfAllTermsMatchUsingAnArray
  * shouldReturnTrueForIncludesEveryWithEmptyTerms

Ensures maximum coverage and verifies behavior under various conditions (e.g., no matches, partial matches, empty arrays).
@RobsonTrasel RobsonTrasel changed the title Feature/improved includes helper [Feature] Improved Includes Helper Mar 2, 2025
@RobsonTrasel
Copy link
Contributor Author

Hey, @jlenon7, I'm a bit confused about using Macroable so I can do something like value.athenna.includesSome('models.id', 'models.provider') as mentioned in issue #132 . I saw there's this class called Macroable, but I’m not entirely sure how to hook everything up so that 'hello'.athenna.includesEvery(['someValue']) actually works. Could you please show me a clear example or explain how I should set up these macros/getters? I’d really appreciate it!

@jlenon7 jlenon7 linked an issue Apr 22, 2025 that may be closed by this pull request
@jlenon7 jlenon7 self-requested a review April 22, 2025 20:07
@jlenon7 jlenon7 added feature New feature or request good first issue Good for newcomers semver-minor Issue or PR that should land as semver minor. labels Apr 22, 2025
@jlenon7
Copy link
Member

jlenon7 commented Apr 22, 2025

Hey, @jlenon7, I'm a bit confused about using Macroable so I can do something like value.athenna.includesSome('models.id', 'models.provider') as mentioned in issue #132 . I saw there's this class called Macroable, but I’m not entirely sure how to hook everything up so that 'hello'.athenna.includesEvery(['someValue']) actually works. Could you please show me a clear example or explain how I should set up these macros/getters? I’d really appreciate it!

I apologize that we still don't have documentation for the Macroable class in Athenna helpers section, I've raised an issue to add the missing helpers and new methods later.

About Macroable

You actually don't need Macroable here, but to satisfy your curiosity, you can use Macroable to extend a class behavior by adding new methods or getters to it. The String class is "macroable" because it extends the Macroable class, so the developer could extend it behavior by doing this:

String.macro('foo', function foo(this: String) {
  return 'bar'
})

String.staticMacro('foo', function foo(this: String) {
  return 'bar'
})

String.foo() // bar
new String().foo() // bar

Notice that we are using TypeScript and this class cannot infer the types of the methods and getters that the developer wants to create, so he needs to create a .d.ts file to declare his methods:

import { String as AthennaString } from '@athenna/common'

declare module '@athenna/common' {
  class String extends AthennaString {
    /**
     * Output bar when called.
     */
    static foo(): string;
    
    /**
     * Output bar when called.
     */
    foo(): string;
  }
}

About your implementation

Keep in mind that the String class of Athenna is not the same as the global String class of JavaScript. The global String class is the one we want to extend here, you can use as an example the Array.ts file that is extending the native Array class of JavaScript to add the .athenna property to it.

Since you already implemented includesSome() and includesEvery() in String class, you can create a String.ts file in the same folder of Array.ts and just make a call to the helpers you created, or even exposes all the helpers of the String class into the "hello".athenna property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request good first issue Good for newcomers semver-minor Issue or PR that should land as semver minor.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Create improved includes() helper

2 participants