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

deckardcain

Package Overview
Dependencies
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deckardcain - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

src/deckardcain.js

76

lib/deckardcain.js

@@ -6,14 +6,10 @@ 'use strict';

});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _jsYaml = require('js-yaml');
var _jsYaml2 = _interopRequireDefault(_jsYaml);
var API_BLUEPRINT_HEADER = /^[\uFEFF]?(((VERSION:( |\t)2)|(FORMAT:( |\t)(X-)?1A))([\n\r]{1,2}|$))/i;
var API_BLUEPRINT_RESPONSE = /\+\s+Response\s+\d{3}/i;
var API_BLUEPRINT_RESPONSE = /\+\s+(?:[Rr]esponse|[Rr]equest)\s+\d{3}/i;
var LEGACY_BLUEPRINT_TITLE = /\-{3} ([^\n\r]+ )?\-{3}([\n\r]{1,2}|$)/;
var SWAGGER_JSON = /^[\uFEFF]?{\n?[\n\t ]*["']swagger["']: ["']\d\.\d["'],/i;
var SWAGGER_YAML = /(?:^|\n)swagger: ["']\d\.\d["']\n/i;
/**

@@ -26,46 +22,32 @@ * Identifies given source.

// Stay awhile and listen!
if (source.match(API_BLUEPRINT_HEADER)) {
// I spotted 'FORMAT: 1A' header, which gives us a clear clue that
// the file is API Blueprint.
return 'text/vnd.apiblueprint';
}
var identifiedType = null;
if (source.match(SWAGGER_YAML)) {
// Indeed, we are dealing with Swagger file!
return 'application/swagger+yaml';
}
try {
var json = JSON.parse(source);
if (source.match(SWAGGER_JSON)) {
// Indeed, we are dealing with Swagger file!
return 'application/swagger+json';
}
// It looks like the source is a valid JSON file. I suspect it to
// be a Swagger file.
if (json.swagger) {
// Indeed, we are dealing with Swagger file!
identifiedType = 'application/swagger+json';
}
} catch (jsonException) {
// Well ok, it's not a JSON...Maybe we're dealing with YAML file?
try {
var yaml = _jsYaml2['default'].safeLoad(source);
if (source.match(LEGACY_BLUEPRINT_TITLE)) {
// I spotted '--- Sample Title ---' title. This looks like
// we are dealing with the legacy Apiary Blueprint.
return 'text/vnd.legacyblueprint';
}
if (yaml.swagger) {
// Indeed, we are dealing with Swagger file!
identifiedType = 'application/swagger+yaml';
}
} catch (yamlException) {
// Well ok I am sorry, it's not a Swaggerish
}
} finally {
if (identifiedType === null) {
if (source.match(API_BLUEPRINT_HEADER)) {
// I spotted 'FORMAT: 1A' header, which gives us a clear clue that
// the file is API Blueprint.
identifiedType = 'text/vnd.apiblueprint';
} else if (source.match(LEGACY_BLUEPRINT_TITLE)) {
// I spotted '--- Sample Title ---' title. This looks like
// we are dealing with the legacy Apiary Blueprint.
identifiedType = 'text/vnd.legacyblueprint';
} else if (source.match(API_BLUEPRINT_RESPONSE)) {
// I can not see the '--- Sample Title ---' and at the same time
// there is something like '+ Response 200' in the document, which is
// pretty distinctive for API Blueprint.
identifiedType = 'text/vnd.apiblueprint';
}
}
if (source.match(API_BLUEPRINT_RESPONSE)) {
// I can not see the '--- Sample Title ---' and at the same time
// there is something like '+ Response 200' in the document, which is
// pretty distinctive for API Blueprint.
return 'text/vnd.apiblueprint';
}
return identifiedType;
}
return null;
}

@@ -72,0 +54,0 @@

{
"name": "deckardcain",
"version": "0.2.0",
"version": "0.2.1",
"description": "Identifies (media) type of API description files",
"main": "lib/deckardcain",
"scripts": {
"lint": "eslint src --ext .js,.es6 src",
"lint": "eslint src --ext .js src",
"precompile": "npm run lint",
"compile": "babel src/ --out-dir lib/",
"prepublish": "npm run compile",
"preserver-test": "npm run compile",
"prebrowser-test": "npm run compile",
"server-test": "mocha --compilers es6:babel/register -R spec --recursive",
"browser-test": "karma start",
"test": "npm run server-test && npm run browser-test"
"test": "npm run server-test && npm run browser-test && npm run lint"
},

@@ -38,2 +36,3 @@ "repository": {

"eslint": "^1.2.1",
"eslint-config-airbnb": "^1.0.0",
"karma": "^0.13.3",

@@ -45,8 +44,5 @@ "karma-browserify": "^4.2.1",

"karma-mocha-reporter": "^1.0.4",
"eslint-config-airbnb": "^1.0.0",
"mocha": "^2.2.1"
},
"dependencies": {
"js-yaml": "^3.4.3"
}
"dependencies": {}
}

@@ -36,3 +36,3 @@ # Deckard Cain

< 200
`) // 'text/vnd.legacyblueprint
`) // 'text/vnd.legacyblueprint'

@@ -39,0 +39,0 @@ identify(`

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