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

Show whitespace character for default values #203

Merged
merged 1 commit into from
Oct 24, 2016
Merged

Show whitespace character for default values #203

merged 1 commit into from
Oct 24, 2016

Conversation

tizmagik
Copy link
Collaborator

Closes #196

image

Copy link
Member

@sapegin sapegin left a comment

Choose a reason for hiding this comment

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

Thanks!

/**
* Remove quotes around given string.
*
* @param {string} string
* @returns {string}
*/
export function unquote(string) {
return trim(string, '"\'');
return string.replace(/^\'|^\"|\"$|\'$/g, '');
Copy link
Member

Choose a reason for hiding this comment

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

Good catch ;-) But I’d even replace it with this module, it also unescape quotes inside the sting: https://github.com/dominictarr/quote-unquote/blob/master/index.js#L14-L20

Copy link
Collaborator Author

@tizmagik tizmagik Oct 24, 2016

Choose a reason for hiding this comment

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

Hm, we only "unquote" so that we don't show the quotes surrounding the stringified values parsed from the defaultProp definitions right? E.g. I wouldn't necessarily want the quotes within my defaultProps touched at all.

Also, the function itself looks broken:

var unquote = function (s) {
  var quote = s[0]
  var single = quote === "'"
  return s.substring(1, s.length - 1)
      .replace(/\\\\/g, '\\')
      .replace(single ? /\\'/g : /\\"/g, quote)
}

unquote("here's my quote"); // "ere's my quot"

It seems to eat the first and last char.

EDIT: Oh, I see, it's expecting the string as:

unquote("\"here's my quote\"");

I still think the simple regex that's there is sufficient 😛

Copy link
Member

Choose a reason for hiding this comment

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

It assumes (for some unknown) reason that the string is quoted 8-)

I was thinking that unescaping will make string easier to read but probably we don’t have quotes inside strings to often to do anything.

* @returns {string}
*/
export function showSpaces(string) {
return string.replace(/^\s|\s$/g, '␣');
Copy link
Member

@sapegin sapegin Oct 24, 2016

Choose a reason for hiding this comment

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

Maybe it’d be more useful to show different kinds of whitespace: space, new lines, etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it makes sense only to show those if they are at the beginning or end of a line, so I can add support for replacing \n with

For example, I wouldn't want to see this:

text
here

Represented as:

text⏎here

Also, I imagine a string that starts/ends with a new-line would be an extremely rare case, but I can still add it if you think it makes sense. Let me know!

Copy link
Member

Choose a reason for hiding this comment

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

I think you’re right, so leave it as is ;-)

@sapegin sapegin merged commit a2e6b30 into master Oct 24, 2016
@sapegin
Copy link
Member

sapegin commented Oct 24, 2016

:shipit:

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.

None yet

2 participants