Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

macos-version

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

macos-version - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

59

index.js
'use strict';
const execa = require('execa');
const fs = require('fs');
const semver = require('semver');
module.exports = () => execa.stdout('sw_vers', ['-productVersion']);
const isMacos = process.platform === 'darwin';
let version;
const getVersion = () => {
if (!isMacos) {
throw new Error('Requires macOS');
}
if (!version) {
const file = fs.readFileSync('/System/Library/CoreServices/SystemVersion.plist', 'utf8');
const matches = /<key>ProductVersion<\/key>[\s\S]*<string>([\d.]+)<\/string>/.exec(file);
if (!matches) {
throw new Error('Couldn\'t find the macOS version');
}
version = matches[1];
}
return version;
};
module.exports = getVersion;
const clean = version => version.split('.').length === 2 ? `${version}.0` : version;
const x = module.exports;
x.is = input => {
if (!isMacos) {
return false;
}
return semver.satisfies(getVersion(), clean(input));
};
x.isGreaterThanOrEqualTo = input => {
if (!isMacos) {
return false;
}
return semver.gte(getVersion(), clean(input));
};
x.assert = input => {
if (!x.is(input)) {
throw new Error(`Requires macOS ${input}`);
}
};
x.assertGreaterThanOrEqualTo = input => {
if (!x.isGreaterThanOrEqualTo(input)) {
throw new Error(`Requires macOS ${input} or later`);
}
};

20

package.json
{
"name": "macos-version",
"version": "3.0.0",
"description": "Get the macOS version of the current system",
"version": "4.0.0",
"description": "Get or check the current macOS version",
"license": "MIT",

@@ -22,12 +22,17 @@ "repository": "sindresorhus/macos-version",

"keywords": [
"macos",
"os",
"macos",
"osx",
"darwin",
"operating",
"system",
"platform",
"version"
"version",
"release",
"semver",
"check",
"assert",
"condition"
],
"dependencies": {
"execa": "^0.4.0"
"semver": "^5.3.0"
},

@@ -37,6 +42,3 @@ "devDependencies": {

"xo": "*"
},
"xo": {
"esnext": true
}
}
# macos-version [![Build Status](https://travis-ci.org/sindresorhus/macos-version.svg?branch=master)](https://travis-ci.org/sindresorhus/macos-version)
> Get the macOS version of the current system. Example: `10.9.3`
> Get or check the current macOS version

@@ -18,13 +18,42 @@

macosVersion().then(version => {
console.log(version);
//=> '10.9.3'
});
macosVersion();
//=> '10.12.3'
macosVersion.is('>10.10');
//=> true
macosVersion.assertGreaterThanOrEqualTo('10.12.5');
//=> [Error: Requires macOS 10.10.5 or later]
```
## API
### macosVersion()
Returns the macOS version.
### macosVersion.is(semverRange)
Returns a `boolean` of whether the specified [semver range](https://github.com/npm/node-semver#ranges) matches the macOS version.
### macosVersion.isGreaterThanOrEqualTo(version)
Returns a `boolean` of whether the macOS version is greater than or equal to the specified version.
### macosVersion.assert(semverRange)
Throws an error if the specified [semver range](https://github.com/npm/node-semver#ranges) does not match the macOS version.
### macosVersion.assertGreaterThanOrEqualTo(version)
Throws an error if the macOS version is not greater than or equal to the specified version.
*Prefer this over `.assert()` whenever possible as it outputs a more user-friendly error message.*
## Related
- [macos-version-cli](https://github.com/sindresorhus/macos-version-cli) - CLI for this module
- [osx-release](https://github.com/sindresorhus/osx-release) - Get the name and version of a macOS release from the Darwin version
- [macos-release](https://github.com/sindresorhus/macos-release) - Get the name and version of a macOS release from the Darwin version

@@ -31,0 +60,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc