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 string.startsWith and string.endsWith #1235

Merged
merged 3 commits into from
Jul 18, 2022
Merged

Add string.startsWith and string.endsWith #1235

merged 3 commits into from
Jul 18, 2022

Conversation

grumpyoldman-io
Copy link
Contributor

This adds a startsWith and endsWith helper on the string like discussed here #604

small aside, the playground.ts is missing, which is mentioned in the contrib

@netlify
Copy link

netlify bot commented Jun 29, 2022

Deploy Preview for guileless-rolypoly-866f8a ready!

Name Link
🔨 Latest commit 92725f6
🔍 Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/62d4be890f3af60008d8057b
😎 Deploy Preview https://deploy-preview-1235--guileless-rolypoly-866f8a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@grumpyoldman-io
Copy link
Contributor Author

CC @alii

@alii
Copy link
Sponsor Contributor

alii commented Jun 29, 2022

ooh awesome :D thank you!

@grumpyoldman-io
Copy link
Contributor Author

@colinhacks anything else I can do for this PR, I cant assign you as a reviewer and the contribution file didnt mention anything around PR creation guidelines.

@AustinShelby
Copy link
Contributor

Transforming the parameter users give to the startsWith function into a regex doesn't work in certain edge cases.

Consider the following scenario;

const x = z.string().startsWith("[a-g]");
x.parse("[a-g]");

By first look this should work as the string [a-g] starts with [a-g].

The problem is that when you transform [a-g] into a regex using your implementation it checks if the string starts with any character from a to g, which it doesn't as it starts with the character [.

I suggest using the native String functions startsWith and endsWith.

@Svish
Copy link

Svish commented Jul 11, 2022

Rather than regular expressions, depending on what browser support this library aims for, these rules should probably just use the built-in startsWith and endsWith string functions, or alternatively the older indexOf of lastIndexOf functions?

@colinhacks colinhacks merged commit 799fbb1 into colinhacks:master Jul 18, 2022
@grumpyoldman-io grumpyoldman-io deleted the add-starts-and-ends-with branch November 16, 2022 09:55
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.

5 participants