-
Notifications
You must be signed in to change notification settings - Fork 498
Some minor fixes to Node port + support for device, isMobile, isSpider #56
Conversation
obj.major = parseInt(majorVersionRep ? majorVersionRep : m[2]); | ||
obj.minor = m[3] ? parseInt(m[3]) : null; | ||
obj.patch = m[4] ? parseInt(m[4]) : null; | ||
obj.major = ~~parseInt(majorVersionRep ? majorVersionRep : m[2]); |
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.
add a code comment stating how ~~
works with numbers and NaN
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.
Added relevant information regarding the double bitwise not trick.
Can we please split up diffs for Fine for merging that part. The rest of the JS changes I'd like to review separately. I'm not fond of the bitwise operator trick, unless there are proven performance benefits in what's cleary a bottleneck of the code. Furthermore, @bluesmoon mentioned in #5 that version numbers should be presented as strings (and not ints) as we're sometimes loosing info in the process of parsing these. I welcome a proposition of how to go about changing this to ship it in a 0.3 version. Makes sense? |
I agree with your points except for the bitwise operator trick which is arguably more performant. But this is moot if we are not going to be parsing out integers in the first place. But, regarding #5, there is, I think, a problem with parsing out version numbers properly. The problem lies in regexes.yaml in which most of the regular expressions use |
Okay there are a few regexes in regexes.yaml which include parsing out prefixes (Firefox Namoroka/Minefield etc). So what you do propose? Is there a benefit in keeping it as string, apart from comparison between versions? If it needs to be around for comparison, should this feature be added to the module itself or should be taken care of by the user at the application level? |
Not sure what's best. Would like input from @bluesmoon as he reported the issue initially. |
Version number comparison should be left to something like |
What are the ports in the other languages doing? Strings or ints? What about providing both? |
My D port uses integers for versions (don't know about other ports. haven't read the code yet). Its trivial to rewrite to use strings. I vote for having both. It would facilitate simple comparisons at least ( |
I'm in need of the |
There's too much different things going on in this PR for it to be pulled directly. Happy to consider some more atomic changes. |
@closealert True, I missed out on documenting @tobie Can you tell me what to include (or not include) so I can push the changes again? |
@@ -6,10 +6,20 @@ var file = path.join(__dirname, '..', 'regexes.yaml'); | |||
var regexes = fs.readFileSync(file, 'utf8'); | |||
regexes = yaml.eval(regexes); | |||
|
|||
var mobile_agents = {}; | |||
var mobile_user_agent_families = regexes.mobile_user_agent_families.map(function(str) { | |||
mobile_agents[str] = true; |
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.
Are you not returning anything on purpose here?
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.
Ah! I should have just used a for-loop here. Thanks for pointing this out.
@shripadk The device property is returned as Object with isMobile and isSpider inside in other languages. For example, java: System.out.println(c.device.family); // => "iPhone"
System.out.println(c.device.isMobile); // => true
System.out.println(c.device.isSpider); // => false |
if(!!(d(ua))) { | ||
return device = d(ua); | ||
} | ||
}); | ||
|
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.
Overall, I don't understand why you're operating these style changes.
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.
I don't remember now as to why this was needed. Can revert back for the time being.
Commented in lots of places. Overall, would like to see this PR split up in 2-3 chunks taregting one thing only unless there's a compelling reason not to do so. |
I have replied to your comments. Most of the issues you have raised relate to whether |
Sounds good. I'm wary of backwards compatibility issues, can you suggest a more elegant API which would allow us to do both? |
@closealert Thanks will be fixed :) |
@tobie For backwards compatibility we can continue returning
AFAIK, returning a integer version of |
No, we can't extend the language like that in a lib. It's a Very Bad Practice(TM). |
True. I can't think of any other way. Every other way would make it verbose. The choice is either verbosity or bad practice :) |
I would suggest like @tobie to split this one up:
|
@closealert I have made changes to |
Can we please split this up. One feature per PR. Thanks. |
@shripadk The changes look good but I can still see tobie's point considering the fact that there are a lot of lines in there not directly related to this fix. (for example the expansion of the UserAgent function). If you look at the original file (https://github.com/tobie/ua-parser/blob/master/js/index.js) then there are simply too many changes to merge. @tobie, close this one up and then @shripadk can create three new PR's - one for each feature. |
@tobie , @closealert sure will do ASAP :) |
Even though I have read/write access to this repo, I'll continue to send pull requests so that the changes can be reviewed before merging. :) This should fix #53 and #54.