Skip to content

Conversation

Cicatrice
Copy link

This is a very short PR which will add functions to manipulate strings, especially to turn them into camelcase, kebabcase or snakecase (useful to generate fields names).

Copy link
Member

@Duologic Duologic left a 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.


* [aggregate](aggregate.md)
* [ascii](ascii.md)
* [camelcase](camelcase.md)
Copy link
Member

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.

Comment on lines +12 to +15
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),
Copy link
Member

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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Function alias: `camelcase`
Function alias: `camelize`

d.arg('lower', d.T.boolean, default=false),
]
),
camelize(w,lower=false): self.camelcase(w, lower),
Copy link
Member

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.

Suggested change
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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Function aliases: `underscore`, `snakecase`
Function aliases: `underscore`, `snakize`

* `kebabcase("FooBar")` → `"foo-bar"`
* `kebabcase("+++More symbols!!!")` → `"more-symbols"`
Function aliases: `dasherize`, `kebabcase`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Function aliases: `dasherize`, `kebabcase`
Function aliases: `dasherize`, `kebabize`

@Cicatrice
Copy link
Author

Hi ! long time not working on this one !

Im intensively writing Jsonnet those days ; I may update this soon.

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.

2 participants