-
-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
RobsonTrasel
commented
Mar 2, 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!
Hey, @jlenon7, I'm a bit confused about using
Macroableso I can do something likevalue.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.
⛔ Snyk checks have failed. 4 issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
- 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).
9d5d0a7 to
0fb33af
Compare
Proposed changes
Adds new static methods (
includesSomeandincludesEvery) to theStringclass, 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
xin the boxes that applyChecklist
Put an
xin the boxes that apply. You can also fill these out aftercreating 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.
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).