-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Use trim method as trim isn't a property #9605
Use trim method as trim isn't a property #9605
Conversation
@bjarnef why not let JS do it's thing with type coercion, and check I guess that would fail if the string was whitespace only, but probably also worth checking where in the codebase we'd allow a whitespace string to be set (doesn't make sense to let that happen). Given all that, it's really two options - extension where we can't check null, or coercion where we don't check whitespace... |
@bjarnef how about adding it as a method in Utilities.js - not as clean as an extension, but can handle null/undefined without issue |
@nathanwoulfe yes, would could have a We already have a Maybe @nul800sebastiaan and @nielslyngsoe have some input on this? |
A |
FWIW - I realize it's easy to create function clutter, but personally I find negating tests to be more readable in many cases - e.g. isNotNullOrEmpty() |
@c9mbundy In that case I prefer to use |
Also easy enough to add both versions, where one just returns the negated result of the other. One of my first tasks in a new C# project is to add HasValue() and HasNoValue() string extensions, to roll up the IsNullOrEmpty and IsNullOrWhitespace check into convenience extensions. s.HasNoValue() just returns !s.HasValue() but helps to keep things readable, which is a win. Long story short, no reason both versions couldn't exist. |
@nathanwoulfe I have added two new functions to |
I didn't fully read this, but the rule is: utilities.js should not become a class for throwing random stuff in, it was specifically meant to catch AngularJS methods that can be removed from the rest of the codebase so as to make the dependencies on AngularJS less. Any new method you throw in there will need to be fully supported by HQ and we're not ready to commit to that. A comment at the top of |
@nul800sebastiaan yes, I agree with it could easily become a new "UmbracoHelper" class. For example in this PR we have the same local I'll revert the change for now. |
It might be something to consider in a rewrite of the backoffice though and mayve if TypeScript will be used. I saw this example |
Also worth remember too that a move to modular JS means we can import functions as required - either from NPM packages or including custom stuff. |
Alright, this one is good to go for now and I think, indeed, we'll be building a library for what we need in vNext. Thanks for the updates in this PR @bjarnef! 👍 |
Prerequisites
Description
I noticed this PR #8213 introduced a private method
isEmptyOrSpaces()
which usetrim
as property instead oftrim()
as a method.I also renamed the function to
isNullOrWhitespace()
.I considered adding this as a
String
prototype extension in Extensions.js, but is seems to throw an error if called asstr.isNullOrWhitespace()
andstr
isnull
.For now I have omitted this, but it could be useful as we use check for
null
,undefined
and empty string in many part of the code.