New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

speculate

Package Overview
Dependencies
Maintainers
22
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

speculate - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

test/fixtures/my-cool-api-with-hyphenated-version-and-override-underscore.json

15

lib/spec.js

@@ -23,4 +23,17 @@ 'use strict';

const replaceHyphens = getValueFromSpec(spec, 'replaceHyphens', false);
const allowedReplacements = ['~', '_', '+'];
let newVersion;
return replaceHyphens ? version.replace(/-/g, '~') : version;
if (replaceHyphens === true) {
// Stay backwards compatible. Previous version was true -> tilde.
newVersion = version.replace(/-/g, '~');
} else if (typeof replaceHyphens === 'string') {
if (allowedReplacements.includes(replaceHyphens)) {
newVersion = version.replace(/-/g, replaceHyphens);
} else {
throw new Error(`replaceHyphens was given a forbidden string, so no replacement was done. Please use one of ${allowedReplacements.join('')}`);
}
}
return newVersion || version;
}

@@ -27,0 +40,0 @@

2

package.json
{
"name": "speculate",
"version": "2.0.0",
"version": "2.1.0",
"description": "Automatically generates an RPM Spec file for your Node.js project",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -353,2 +353,12 @@ # speculate

}
```
```
Or you can explicitly tell speculate to replace hyphens with tildes `"~"`, underscores `"_"` or plus signs `"+"`:
```json
{
"spec": {
"replaceHyphens": "_"
}
}
```

@@ -107,3 +107,5 @@ 'use strict';

const pkg = require('./fixtures/my-cool-api-with-hyphenated-version-and-override.json');
const expected = loadFixture('my-cool-api-with-version-hyphens-replaced.spec');
const expected = loadFixture(
'my-cool-api-with-version-hyphens-replaced.spec'
);
const spec = createSpecFile(pkg);

@@ -114,2 +116,20 @@

it('replaces hyphens in the package version number with spec.replaceHyphens if it is a valid character', () => {
const pkg = require('./fixtures/my-cool-api-with-hyphenated-version-and-override-underscore.json');
const expected = loadFixture(
'my-cool-api-with-version-hyphens-replaced-underscores.spec'
);
const spec = createSpecFile(pkg);
assert.equal(spec, expected);
});
it('errors if spec.replaceHyphens is not a valid character', () => {
const pkg = require('./fixtures/my-cool-api-with-hyphenated-version-and-override-underscore.json');
pkg.spec.replaceHyphens = 'invalid';
const erroringSpecCall = createSpecFile.bind(null, pkg);
assert.throws(erroringSpecCall);
});
it('does not replace hyphens in the package version number if spec.replaceHyphens is not defined in package.json', () => {

@@ -116,0 +136,0 @@ const pkg = require('./fixtures/my-cool-api-with-hyphenated-version.json');

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