-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: add strings lib #8
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks you for this.
A bit nitty but I would like to suggest adding a few linebreaks to make it a bit easier to digest, I generally apply "one line does one thing" approach but use common sense.
Examples:
// Put conditional inside conditionals on new line
local something =
if statement1
then
if statement2
then doSomething
else somethingElse2
else somethingElse;
// Add linebreak inside std functions to see where they start and end
local filtered =
std.filter(
function(x)
std.length(x) == 1
&& x.value != 1,
someArray,
);
Additionally I see a few abbreviated variables (wcs, camcs), they actually make it harder
to read.
I'm not sure if I'm a fan of the aliases, I personally like to have a decisive function
name but I have no reasonable arguments against them.
@@ -14,10 +14,9 @@ This package serves as a test field for functions intended to be contributed to | |||
in the future, but also provides a place for less general, yet useful utilities. | |||
|
|||
|
|||
## Subpackages | |||
|
|||
* [aggregate](aggregate.md) | |||
* [ascii](ascii.md) | |||
* [camelcase](camelcase.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does camelcase deliver the same result here?
If so, we might want to deprecate the original one. To do so, we can remove the docs and and perhap provide use strings.camelcase there instead to keep it backwards compatible for libraries depending on it.
isUpcase(c):: std.codepoint(c) >= 65 && std.codepoint(c) <= 90, // between A & Z | ||
isDowncase(c):: std.codepoint(c) >= 97 && std.codepoint(c) <= 122, // between a & z | ||
isDigit(c) :: std.codepoint(c) >= 48 && std.codepoint(c) <= 57, // between 0 & 9 | ||
isAlphaNum(c):: self.isUpcase(c) || self.isDowncase(c) || self.isDigit(c), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are already covered in the ascii
package, perhaps we can reference those instead of redefining them here.
* `camelcase("foo_bar",lower=true)` → `"fooBar"` | ||
* `camelcase("+++More symbols!!!")` → `"MoreSymbols"` | ||
|
||
Function alias: `camelcase` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function alias: `camelcase` | |
Function alias: `camelize` |
d.arg('lower', d.T.boolean, default=false), | ||
] | ||
), | ||
camelize(w,lower=false): self.camelcase(w, lower), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave out the function arguments here, it gets inherited.
camelize(w,lower=false): self.camelcase(w, lower), | |
camelize: self.camelcase, |
* `snakecase("FooBar")` → `"foo_bar"` | ||
* `snakecase("+++More symbols!!!",caps=true)` → `"MORE_SYMBOLS"` | ||
|
||
Function aliases: `underscore`, `snakecase` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function aliases: `underscore`, `snakecase` | |
Function aliases: `underscore`, `snakize` |
* `kebabcase("FooBar")` → `"foo-bar"` | ||
* `kebabcase("+++More symbols!!!")` → `"more-symbols"` | ||
|
||
Function aliases: `dasherize`, `kebabcase` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function aliases: `dasherize`, `kebabcase` | |
Function aliases: `dasherize`, `kebabize` |
Hi ! long time not working on this one ! Im intensively writing Jsonnet those days ; I may update this soon. |
This is a very short PR which will add functions to manipulate strings, especially to turn them into
camelcase
,kebabcase
orsnakecase
(useful to generate fields names).