Implementation of white space normalisation.#649
Conversation
|
is there a possibility to broaden this to also include the use case from #586? |
|
I don't see why not, assuming that you mean I can definitely tackle the first case, the latter might be a bit more than I can chew at the moment! WDYT? |
|
I gave a shot to implementing |
test/string.js
Outdated
There was a problem hiding this comment.
no need for this extra white line
|
I was wondering if this could be by any change merged :-) |
lib/string.js
Outdated
There was a problem hiding this comment.
It would be nice to also be able to provide a string and transform it to a regexp with flag g to replace everything. Don't forget to use Hoek.escapeRegex on the string.
…the loop up there without function calls. hapijs#649
…g from this rule, so just clone the current object. hapijs#649
|
@Marsup I've tried to address all your concerns/comments in the latest few commits! Let me know if there's anything else I should fix (at least Travis is happy)! |
lib/string.js
Outdated
There was a problem hiding this comment.
typeof is not a function, no parenthesis.
There was a problem hiding this comment.
Whops :-) I wish there was a esLint def for that! Fixed.
lib/string.js
Outdated
There was a problem hiding this comment.
I'm still thinking about it, convert is documented as a type coercing property, this is not the case here, I'm not sure we need it. (though we could argue about lowercase and others)
There was a problem hiding this comment.
To me, the string should be left untouched unless the convert flag was specified (at validation time)
True that replace IMPLIES a modification (does not execute any test) but when it is paired with regex, it makes for some interesting constructs. For example:
var schema = joi.string()
.regex(/^[^x]*$/)
.replace(/x/, 'y')
.trim();
function validateOrNormalize(input, loose) {
var result = joi.validate(input, schema, { convert: false } );
if (result.error) {
console.log("WARNING", result.error.details);
if (loose) {
return joi.validate(input, schema, { convert: true }).value;
} else {
throw result.error;
}
} else {
return input;
}
}Dunno, food for thought...
There was a problem hiding this comment.
Well then, move it back inside the if. Also can you squash your commits before I merge ?
- Provide a string and transform it to a regexp with flag g to replace everything. - Do not push functions, push parameters that will be used directly in the loop up there without function calls. - Rebuilt TOC. - Remove reference to convert in README. - Document parameters as in most of the other parts. - Reworked logic as this can not be considere a test like trim.
|
You should probably rebase it on the current master, there are way too many commits. |
|
Yup. Doing that right now.... On Sat, Jun 6, 2015 at 6:21 PM, Nicolas Morel notifications@github.com
|
|
All squashed and Travis is happy, too! |
Implementation of white space normalisation.
|
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
This is an implementation of the request made at #648
I have added the
string.normalize()function (basically inspired bytrim()) following the name XSLT/XPath/XQuery gave to it (I was in doubt whether to call thisnormalizeSpace()ornormalize_space(), but it seems JOI prefers shorter names).I'm always baffled by
normalisevs.normalize... I guess I'll go with the latter (again, XSLT/XPath/XQuery...)