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.1 to 0.3.0

38

lib/deckardcain.js

@@ -7,9 +7,17 @@ 'use strict';

var API_BLUEPRINT_HEADER = /^[\uFEFF]?(((VERSION:( |\t)2)|(FORMAT:( |\t)(X-)?1A))([\n\r]{1,2}|$))/i;
var API_BLUEPRINT_RESPONSE = /\+\s+(?:[Rr]esponse|[Rr]equest)\s+\d{3}/i;
var API_BLUEPRINT_RESPONSE = /\+\s+(?:response|request)\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_JSON = /^[\uFEFF]?{\n?[\n\t ]*["']swagger["']: ?["']\d\.\d["'],/i;
var SWAGGER_YAML = /(?:^|\n)swagger: ["']\d\.\d["']\n/i;
var REFRACT_API_DESCRIPTION_ELEMENT_JSON = /[\uFEFF]?\n?\s*["']element["']: ?["']category["']/i;
var REFRACT_API_DESCRIPTION_CLASS_JSON = /(\s*["'][meta|classes]+["']: ?[\{|\[]){2}(\s*["'][api]+["']){1}/i;
var REFRACT_PARSE_RESULT_ELEMENT_JSON = /[\uFEFF]?\n?\s*["']element["']: ?["']parseResult["']/i;
var REFRACT_API_DESCRIPTION_ELEMENT_YAML = /[\uFEFF]?\n?\s*element: ?["']category["']/i;
var REFRACT_API_DESCRIPTION_CLASS_YAML = /(\s*[meta|classes]+: ?){2}(\s*- ["'][api]+["']){1}/i;
var REFRACT_PARSE_RESULT_ELEMENT_YAML = /[\uFEFF]?\n?\s*element: ?["']parseResult["']/i;
/**

@@ -21,6 +29,5 @@ * Identifies given source.

function identify(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.
// There is 'FORMAT: 1A' present at the begining,
// so we can say it is API Blueprint
return 'text/vnd.apiblueprint';

@@ -30,3 +37,2 @@ }

if (source.match(SWAGGER_YAML)) {
// Indeed, we are dealing with Swagger file!
return 'application/swagger+yaml';

@@ -36,9 +42,21 @@ }

if (source.match(SWAGGER_JSON)) {
// Indeed, we are dealing with Swagger file!
return 'application/swagger+json';
}
if (source.match(REFRACT_API_DESCRIPTION_ELEMENT_JSON) && source.match(REFRACT_API_DESCRIPTION_CLASS_JSON) && !source.match(REFRACT_PARSE_RESULT_ELEMENT_JSON)) {
// File contains element `category` with class `api`, but
// does not contain element `parseResult`
// which would mean that file is `vnd.refract.parse-result
return 'application/vnd.refract.api-description+json';
}
if (source.match(REFRACT_API_DESCRIPTION_ELEMENT_YAML) && source.match(REFRACT_API_DESCRIPTION_CLASS_YAML) && !source.match(REFRACT_PARSE_RESULT_ELEMENT_YAML)) {
// File contains element `category` with class `api`, but
// does not contain element `parseResult`
// which would mean that file is `vnd.refract.parse-result
return 'application/vnd.refract.api-description+yaml';
}
if (source.match(LEGACY_BLUEPRINT_TITLE)) {
// I spotted '--- Sample Title ---' title. This looks like
// we are dealing with the legacy Apiary Blueprint.
// Found '--- Sample Title ---' title which indicates legacy blueprint
return 'text/vnd.legacyblueprint';

@@ -48,3 +66,3 @@ }

if (source.match(API_BLUEPRINT_RESPONSE)) {
// I can not see the '--- Sample Title ---' and at the same time
// Didn't find '--- Sample Title ---' and at the same time
// there is something like '+ Response 200' in the document, which is

@@ -51,0 +69,0 @@ // pretty distinctive for API Blueprint.

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

@@ -5,0 +5,0 @@ "main": "lib/deckardcain",

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

- Swagger - `application/swagger+json` (according to [swagger-api/swagger-spec#110](https://github.com/swagger-api/swagger-spec/issues/110)) and `application/swagger+yaml`
- [API Description Namespace](https://github.com/refractproject/refract-spec/blob/master/namespaces/api-description-namespace.md) - `application/vnd.refract.api-description+json` and `application/vnd.refract.api-description+yaml`

@@ -77,3 +78,3 @@ ## Install

Source code is located in the `./src` folder and gets automatically transpiled into `./lib` folder when `npm install`, `npm test` or `npm publish` is invoked. However, should you need to transpile it manually, use `npm run compile`.
Source code is located in the `./src` folder and gets automatically transpiled into `./lib` folder when `npm install` or `npm publish` is invoked. However, should you need to transpile it manually, use `npm run compile`.

@@ -80,0 +81,0 @@ ## Name

const API_BLUEPRINT_HEADER = /^[\uFEFF]?(((VERSION:( |\t)2)|(FORMAT:( |\t)(X-)?1A))([\n\r]{1,2}|$))/i;
const API_BLUEPRINT_RESPONSE = /\+\s+(?:[Rr]esponse|[Rr]equest)\s+\d{3}/i;
const API_BLUEPRINT_RESPONSE = /\+\s+(?:response|request)\s+\d{3}/i;
const LEGACY_BLUEPRINT_TITLE = /\-{3} ([^\n\r]+ )?\-{3}([\n\r]{1,2}|$)/;
const SWAGGER_JSON = /^[\uFEFF]?{\n?[\n\t ]*["']swagger["']: ["']\d\.\d["'],/i;
const SWAGGER_JSON = /^[\uFEFF]?{\n?[\n\t ]*["']swagger["']: ?["']\d\.\d["'],/i;
const SWAGGER_YAML = /(?:^|\n)swagger: ["']\d\.\d["']\n/i;
const REFRACT_API_DESCRIPTION_ELEMENT_JSON = /[\uFEFF]?\n?\s*["']element["']: ?["']category["']/i;
const REFRACT_API_DESCRIPTION_CLASS_JSON = /(\s*["'][meta|classes]+["']: ?[\{|\[]){2}(\s*["'][api]+["']){1}/i;
const REFRACT_PARSE_RESULT_ELEMENT_JSON = /[\uFEFF]?\n?\s*["']element["']: ?["']parseResult["']/i;
const REFRACT_API_DESCRIPTION_ELEMENT_YAML = /[\uFEFF]?\n?\s*element: ?["']category["']/i;
const REFRACT_API_DESCRIPTION_CLASS_YAML = /(\s*[meta|classes]+: ?){2}(\s*- ["'][api]+["']){1}/i;
const REFRACT_PARSE_RESULT_ELEMENT_YAML = /[\uFEFF]?\n?\s*element: ?["']parseResult["']/i;
/**

@@ -15,6 +23,5 @@ * Identifies given source.

function identify(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.
// There is 'FORMAT: 1A' present at the begining,
// so we can say it is API Blueprint
return 'text/vnd.apiblueprint';

@@ -24,3 +31,2 @@ }

if (source.match(SWAGGER_YAML)) {
// Indeed, we are dealing with Swagger file!
return 'application/swagger+yaml';

@@ -30,9 +36,25 @@ }

if (source.match(SWAGGER_JSON)) {
// Indeed, we are dealing with Swagger file!
return 'application/swagger+json';
}
if (source.match(REFRACT_API_DESCRIPTION_ELEMENT_JSON) &&
source.match(REFRACT_API_DESCRIPTION_CLASS_JSON) &&
!source.match(REFRACT_PARSE_RESULT_ELEMENT_JSON)) {
// File contains element `category` with class `api`, but
// does not contain element `parseResult`
// which would mean that file is `vnd.refract.parse-result
return 'application/vnd.refract.api-description+json';
}
if (source.match(REFRACT_API_DESCRIPTION_ELEMENT_YAML) &&
source.match(REFRACT_API_DESCRIPTION_CLASS_YAML) &&
!source.match(REFRACT_PARSE_RESULT_ELEMENT_YAML)) {
// File contains element `category` with class `api`, but
// does not contain element `parseResult`
// which would mean that file is `vnd.refract.parse-result
return 'application/vnd.refract.api-description+yaml';
}
if (source.match(LEGACY_BLUEPRINT_TITLE)) {
// I spotted '--- Sample Title ---' title. This looks like
// we are dealing with the legacy Apiary Blueprint.
// Found '--- Sample Title ---' title which indicates legacy blueprint
return 'text/vnd.legacyblueprint';

@@ -42,3 +64,3 @@ }

if (source.match(API_BLUEPRINT_RESPONSE)) {
// I can not see the '--- Sample Title ---' and at the same time
// Didn't find '--- Sample Title ---' and at the same time
// there is something like '+ Response 200' in the document, which is

@@ -45,0 +67,0 @@ // pretty distinctive for API Blueprint.

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