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

deckardcain

Package Overview
Dependencies
Maintainers
3
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.1.6 to 0.2.0

64

lib/deckardcain.js

@@ -7,2 +7,8 @@ '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;

@@ -21,23 +27,45 @@ var API_BLUEPRINT_RESPONSE = /\+\s+Response\s+\d{3}/i;

if (source.match(API_BLUEPRINT_HEADER)) {
// I spotted 'FORMAT: 1A' header. This is a clear clue that
// the file is API Blueprint.
return 'text/vnd.apiblueprint';
}
var identifiedType = null;
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';
}
try {
var json = JSON.parse(source);
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';
// 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 (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';
}
}
return identifiedType;
}
// I do not know. Very strange item!
return null;
}

@@ -44,0 +72,0 @@

{
"name": "deckardcain",
"version": "0.1.6",
"version": "0.2.0",
"description": "Identifies (media) type of API description files",

@@ -36,4 +36,4 @@ "main": "lib/deckardcain",

"chai": "^3.2.0",
"dedent": "^0.6.0",
"eslint": "^1.2.1",
"eslint-config-airbnb": "0.0.8",
"karma": "^0.13.3",

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

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

@@ -15,2 +15,3 @@ # Deckard Cain

- Legacy Apiary Blueprint (predecessor of API Blueprint) - `text/vnd.legacyblueprint`
- Swagger - `application/swagger+json` (according to [swagger-api/swagger-spec#110](https://github.com/swagger-api/swagger-spec/issues/110)) and `application/swagger+yaml`

@@ -17,0 +18,0 @@ ## Install

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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