Skip to content

[RFC]: Add @stdlib/string/base/stickycase #852

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

Closed
3 tasks done
kgryte opened this issue Feb 7, 2023 · 4 comments · Fixed by #1447
Closed
3 tasks done

[RFC]: Add @stdlib/string/base/stickycase #852

kgryte opened this issue Feb 7, 2023 · 4 comments · Fixed by #1447
Assignees
Labels
difficulty: 2 May require some initial design or R&D, but should be straightforward to resolve and/or implement. Feature Issue or pull request for adding a new feature. Good First Issue A good first issue for new contributors! JavaScript Issue involves or relates to JavaScript. Needs Discussion Needs further discussion. priority: Low Low priority concern or feature request. RFC Request for comments. Feature requests and proposed changes. Utilities Issue or pull request concerning general utilities.

Comments

@kgryte
Copy link
Member

kgryte commented Feb 7, 2023

Description

This RFC proposes adding support for converting a string to "sticky caps" case (also known as "studly case" or sponge case), where capitalization is random.

E.g.,

stickycase( 'foo bar' );
// returns 'fOo bAR'

Package: @stdlib/string/base/stickycase
Alias: stickycase

Related Issues

None.

Questions

  • We should use @stdlib/random/base/bernoulli. We could consider supporting a p (probability) parameter in which randomness of capitalization is controlled by a specified probability.
  • Should this package be named differently? (e.g., spongecase?)

Other

See @stdlib/string/base/constantcase for a similar package.

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.
@kgryte kgryte added RFC Request for comments. Feature requests and proposed changes. Feature Issue or pull request for adding a new feature. Good First Issue A good first issue for new contributors! labels Feb 7, 2023
@kgryte kgryte added Needs Discussion Needs further discussion. priority: Low Low priority concern or feature request. Utilities Issue or pull request concerning general utilities. JavaScript Issue involves or relates to JavaScript. difficulty: 2 May require some initial design or R&D, but should be straightforward to resolve and/or implement. labels Feb 23, 2024
@anudeeps0306
Copy link
Contributor

@kgryte

The proposed package name stickycase seems appropriate for describing the behavior of converting a string to "sticky caps" case. However, considering that the term "studly case" or "sponge case" is also commonly used to describe this capitalization style, it might be beneficial to choose a more general name that encompasses these variations. Therefore, spongecase could be a more suitable name for the package as it's broader and includes other common terms for the same concept.

To implement support for a probability parameter (p) in controlling the randomness of capitalization, the following steps can be taken:

  1. Modify the stickycase function to accept an additional parameter p representing the probability of capitalization.
  2. Validate the p parameter to ensure it's a valid probability value between 0 and 1.
  3. Use the @stdlib/random/base/bernoulli module to generate random numbers based on the specified probability p.
  4. Utilize the generated random numbers to decide whether each character in the input string should be capitalized or not.

Can I start working on this issue?

@kgryte
Copy link
Member Author

kgryte commented Feb 25, 2024

I suggest keeping the name as stickycase. There's a larger question whether this API should support PRNG seeding, but that can always be a follow-up enhancement. As a starting point, what you outline is fine. Feel free to submit a PR with an initial draft implementation.

@anudeeps0306
Copy link
Contributor

@kgryte As the output would be random, how should I create an example?

image

@Planeshifter
Copy link
Member

@anudeeps0306 You can use return annotations like // returns <string> in case the output is random.

Planeshifter added a commit that referenced this issue Mar 5, 2024
PR-URL: #1447
Closes: #852

---------

Signed-off-by: Anudeep Sanapala <[email protected]>
Signed-off-by: Philipp Burckhardt <[email protected]>
Co-authored-by: stdlib-bot <[email protected]>
Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
bad-in-coding pushed a commit to bad-in-coding/stdlib that referenced this issue Mar 7, 2024
PR-URL: stdlib-js#1447
Closes: stdlib-js#852

---------

Signed-off-by: Anudeep Sanapala <[email protected]>
Signed-off-by: Philipp Burckhardt <[email protected]>
Co-authored-by: stdlib-bot <[email protected]>
Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: 2 May require some initial design or R&D, but should be straightforward to resolve and/or implement. Feature Issue or pull request for adding a new feature. Good First Issue A good first issue for new contributors! JavaScript Issue involves or relates to JavaScript. Needs Discussion Needs further discussion. priority: Low Low priority concern or feature request. RFC Request for comments. Feature requests and proposed changes. Utilities Issue or pull request concerning general utilities.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants