string_score
string_score copied to clipboard
Don't patch string prototype
Patching prototypes of global objects is a bad practice. Would it be possible to get a version of this module that just exports the scoring function, with a UMD wrapper so it can be used in a CommonJS environment? That would also make it possible to pass the function directly to array.sort()
const score = require('string_score')
let word = "Hello World"
console.log(word.score("Hell"))
world would be undefined in this example so you cannot score it.
Sent from my iPhone
On Dec 6, 2017, at 6:08 AM, Lucas Reis [email protected] wrote:
const score = require('string_score')
let word = "Hello World"
console.log(world.score("Hell")) — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
Sorry for the typo hehe
This would be nice! Planning on using this lib in a large production app but would like to get rid of the prototype patching. Created a local version which doesn't have the prototype patching, we could do an import like:
// Usage without prototype patching
const score = require('string_score/no-prototype')
const word = "Hello World"
console.log(score(word, "Hell")
// Normal usage with prototype patching
require("string_score");
This will allow us to release a new non-breaking version of this lib. Got a local version ready to go, are you interested in me doing a PR for this?
@joshaven What's your opinion on this topic?
I think you are right to recommend the change. I haven’t done much with the package lately, I’ll look into it and respond better later. Thanks.
Sent from my iPhone
On Jan 4, 2018, at 7:21 AM, Danny van der Jagt [email protected] wrote:
This would be nice! Planning on using this lib in a large production app but would like to get rid of the prototype patching. Created a local version which doesn't have the prototype patching, we could do an import like:
// Usage without prototype patching const score = require('string_score/no-prototype')
const word = "Hello World"
console.log(score(word, "Hell") // Normal usage with prototype patching require("string_score"); This will allow us to release a new non-breaking version of this lib. Got a local version ready to go, are you interested in me doing a PR for this?
@joshaven What's your opinion on this topic?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Thanks! Sounds good. I will make a PR so you can take a look at it, maybe it helps. It can be quite a small change.
@DannyvanderJagt could you push your code on a PR? At least it would be accessible to the community!