Open openjck opened 6 years ago
Yeah, not sure if there'd be an easy way to specify a basic regex, like new RegExp("^Darwin-15\\.")
. JSON doesn't support native RegExp (I don't think), so we'd need to wrap it in a string and use a RegExp constructor or something.
const obj ={
"replacementGroups": [
{
"name": "macOS El Capitan",
"members": "^Darwin-15\\."
},
{
"name": "macOS Sierra",
"members": "^Darwin-16\\."
},
{
"name": "macOS High Sierra",
"members": "^Darwin-17\\."
},
{
"name": "macOS Mojave",
"members": "^Darwin-18\\."
}
]
};
const kernel = "darwin-16.22.4";
function kernelToOS(k) {
return obj.replacementGroups.find(g => new RegExp(g.members, "i").test(k)) || {};
}
console.log(kernelToOS(kernel).name, `(${kernel})`); // macOS Sierra (darwin-16.22.4)
Good thinking. I was thinking we could even specify it just by the major version. Something like...
"macOSVersions": [
{ "name": "El Capitan", "majorVersion": 15 },
{ "name": "Sierra", "majorVersion": 16 },
]
But we'll see if that works in practice. :smiley:
Oh yeah, your solution is waaay better than my string regex. 👍
Right now, we need to specify which named macOS release each Darwin version belongs to. For example...
https://github.com/mozilla/workshop/blob/9dc5ef270f0f669663987ae2dfaf96c07ce2a19b/population-modifications.json#L125-L139
It would be easier to specify a range or even simply a major version number for each named release. Each named version of macOS appears to have its own major version number: Darwin 15 is El Capitan, Darwin 16 is Sierra, etc.
I should also create some kind of calendar item to myself to remind myself to update population-modifications.js when new named versions of macOS are announced. Otherwise, those new versions will show up as Darwin-#-#-# in the Data Report.