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

add .data() function. cleaned up PR #221 from @rafaelrinaldi, added tests, updated readme #264

Merged
merged 3 commits into from
Sep 16, 2013

Conversation

andineck
Copy link
Contributor

@andineck andineck commented Sep 4, 2013

Since the .data() function was implemented by @rafaelrinaldi PR#221, but on an older version of cheerio, it didn't make it back into the original cheerio.

I couldn't wait for a solution on this, therefore I fixed this thing now.

I cleaned it up (with the up to date version), added tests and updated the readme.

* @param {String} str String to be converted.
* @return {String} String in camel case notation.
*/
exports.toCamelCase = function(str) {
Copy link
Member

Choose a reason for hiding this comment

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

This one looks a bit simpler: https://github.com/substack/camelize/blob/master/index.js#L12. not sure about correctness though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, substack's one is simpler and works just fine, cool.

@andineck
Copy link
Contributor Author

andineck commented Sep 5, 2013

Thank you for your feedback on this.
When you can give me guidance on the readme example, I can submit another PR. In the meanwhile I removed the underscore dependency from test/api.attributes.js and changed toCamelCase to the camelCase function by substack (tests are passing).

@@ -23,6 +23,8 @@ var formatAttrs = function(attributes) {

// Loop through the attributes
for (var key in attributes) {
// Make sure it doesn't format data attributes.
if (key.match('data-')) continue;
Copy link
Member

Choose a reason for hiding this comment

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

Also matches attributes like foo-data-bar. key.substr(0,5)==="data-" is what you want to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct. Since this piece of code key.substr(0,5)==="data-" is used in parse.js as well as in render.js, would you move it into utils.isDataAttribute() ?

Copy link
Member

Choose a reason for hiding this comment

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

From my perspective, the inline variant is more readable and not significantly longer. ES6's String#startsWith method will shorten this further as soon as it's enabled per default in node.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for the inline variant.

matthewmueller added a commit that referenced this pull request Sep 16, 2013
add .data() function. cleaned up PR #221 from @rafaelrinaldi, added tests, updated readme
@matthewmueller matthewmueller merged commit 152ec3c into cheeriojs:master Sep 16, 2013
@matthewmueller
Copy link
Member

thanks @andi-neck

@rafaelrinaldi
Copy link

Thanks @matthewmueller and @andi-neck. I was finishing the college at the time so I didn't had much of it to spare on this 😔 Glad it make it to master!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants