routie dev init since i didn't adhere to any proper guidance up until now
This commit is contained in:
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import type { Plugin } from "../types/index.js";
|
||||
declare const _default: Plugin;
|
||||
export default _default;
|
||||
Generated
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const BINARY_REGEXP = /\.(jpeg|jpg|gif|png|bmp|ico)$/i;
|
||||
exports.default = {
|
||||
/**
|
||||
* The order that this parser will run, in relation to other parsers.
|
||||
*/
|
||||
order: 400,
|
||||
/**
|
||||
* Whether to allow "empty" files (zero bytes).
|
||||
*/
|
||||
allowEmpty: true,
|
||||
/**
|
||||
* Determines whether this parser can parse a given file reference.
|
||||
* Parsers that return true will be tried, in order, until one successfully parses the file.
|
||||
* Parsers that return false will be skipped, UNLESS all parsers returned false, in which case
|
||||
* every parser will be tried.
|
||||
*/
|
||||
canParse(file) {
|
||||
// Use this parser if the file is a Buffer, and has a known binary extension
|
||||
return Buffer.isBuffer(file.data) && BINARY_REGEXP.test(file.url);
|
||||
},
|
||||
/**
|
||||
* Parses the given data as a Buffer (byte array).
|
||||
*/
|
||||
parse(file) {
|
||||
if (Buffer.isBuffer(file.data)) {
|
||||
return file.data;
|
||||
}
|
||||
else {
|
||||
// This will reject if data is anything other than a string or typed array
|
||||
return Buffer.from(file.data);
|
||||
}
|
||||
},
|
||||
};
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import type { Plugin } from "../types/index.js";
|
||||
declare const _default: Plugin;
|
||||
export default _default;
|
||||
Generated
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const errors_js_1 = require("../util/errors.js");
|
||||
exports.default = {
|
||||
/**
|
||||
* The order that this parser will run, in relation to other parsers.
|
||||
*/
|
||||
order: 100,
|
||||
/**
|
||||
* Whether to allow "empty" files. This includes zero-byte files, as well as empty JSON objects.
|
||||
*/
|
||||
allowEmpty: true,
|
||||
/**
|
||||
* Determines whether this parser can parse a given file reference.
|
||||
* Parsers that match will be tried, in order, until one successfully parses the file.
|
||||
* Parsers that don't match will be skipped, UNLESS none of the parsers match, in which case
|
||||
* every parser will be tried.
|
||||
*/
|
||||
canParse: ".json",
|
||||
/**
|
||||
* Allow JSON files with byte order marks (BOM)
|
||||
*/
|
||||
allowBOM: true,
|
||||
/**
|
||||
* Parses the given file as JSON
|
||||
*/
|
||||
async parse(file) {
|
||||
let data = file.data;
|
||||
if (Buffer.isBuffer(data)) {
|
||||
data = data.toString();
|
||||
}
|
||||
if (typeof data === "string") {
|
||||
if (data.trim().length === 0) {
|
||||
return; // This mirrors the YAML behavior
|
||||
}
|
||||
else {
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
}
|
||||
catch (e) {
|
||||
if (this.allowBOM) {
|
||||
try {
|
||||
// find the first curly brace
|
||||
const firstCurlyBrace = data.indexOf("{");
|
||||
// remove any characters before the first curly brace
|
||||
data = data.slice(firstCurlyBrace);
|
||||
return JSON.parse(data);
|
||||
}
|
||||
catch (e) {
|
||||
throw new errors_js_1.ParserError(e.message, file.url);
|
||||
}
|
||||
}
|
||||
throw new errors_js_1.ParserError(e.message, file.url);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// data is already a JavaScript value (object, array, number, null, NaN, etc.)
|
||||
return data;
|
||||
}
|
||||
},
|
||||
};
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import type { Plugin } from "../types/index.js";
|
||||
declare const _default: Plugin;
|
||||
export default _default;
|
||||
Generated
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const errors_js_1 = require("../util/errors.js");
|
||||
const TEXT_REGEXP = /\.(txt|htm|html|md|xml|js|min|map|css|scss|less|svg)$/i;
|
||||
exports.default = {
|
||||
/**
|
||||
* The order that this parser will run, in relation to other parsers.
|
||||
*/
|
||||
order: 300,
|
||||
/**
|
||||
* Whether to allow "empty" files (zero bytes).
|
||||
*/
|
||||
allowEmpty: true,
|
||||
/**
|
||||
* The encoding that the text is expected to be in.
|
||||
*/
|
||||
encoding: "utf8",
|
||||
/**
|
||||
* Determines whether this parser can parse a given file reference.
|
||||
* Parsers that return true will be tried, in order, until one successfully parses the file.
|
||||
* Parsers that return false will be skipped, UNLESS all parsers returned false, in which case
|
||||
* every parser will be tried.
|
||||
*/
|
||||
canParse(file) {
|
||||
// Use this parser if the file is a string or Buffer, and has a known text-based extension
|
||||
return (typeof file.data === "string" || Buffer.isBuffer(file.data)) && TEXT_REGEXP.test(file.url);
|
||||
},
|
||||
/**
|
||||
* Parses the given file as text
|
||||
*/
|
||||
parse(file) {
|
||||
if (typeof file.data === "string") {
|
||||
return file.data;
|
||||
}
|
||||
else if (Buffer.isBuffer(file.data)) {
|
||||
return file.data.toString(this.encoding);
|
||||
}
|
||||
else {
|
||||
throw new errors_js_1.ParserError("data is not text", file.url);
|
||||
}
|
||||
},
|
||||
};
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import type { Plugin } from "../types/index.js";
|
||||
declare const _default: Plugin;
|
||||
export default _default;
|
||||
Generated
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const errors_js_1 = require("../util/errors.js");
|
||||
const js_yaml_1 = __importDefault(require("js-yaml"));
|
||||
const js_yaml_2 = require("js-yaml");
|
||||
exports.default = {
|
||||
/**
|
||||
* The order that this parser will run, in relation to other parsers.
|
||||
*/
|
||||
order: 200,
|
||||
/**
|
||||
* Whether to allow "empty" files. This includes zero-byte files, as well as empty JSON objects.
|
||||
*/
|
||||
allowEmpty: true,
|
||||
/**
|
||||
* Determines whether this parser can parse a given file reference.
|
||||
* Parsers that match will be tried, in order, until one successfully parses the file.
|
||||
* Parsers that don't match will be skipped, UNLESS none of the parsers match, in which case
|
||||
* every parser will be tried.
|
||||
*/
|
||||
canParse: [".yaml", ".yml", ".json"], // JSON is valid YAML
|
||||
/**
|
||||
* Parses the given file as YAML
|
||||
*
|
||||
* @param file - An object containing information about the referenced file
|
||||
* @param file.url - The full URL of the referenced file
|
||||
* @param file.extension - The lowercased file extension (e.g. ".txt", ".html", etc.)
|
||||
* @param file.data - The file contents. This will be whatever data type was returned by the resolver
|
||||
* @returns
|
||||
*/
|
||||
async parse(file) {
|
||||
let data = file.data;
|
||||
if (Buffer.isBuffer(data)) {
|
||||
data = data.toString();
|
||||
}
|
||||
if (typeof data === "string") {
|
||||
try {
|
||||
return js_yaml_1.default.load(data, { schema: js_yaml_2.JSON_SCHEMA });
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
// fallback to non JSON_SCHEMA
|
||||
return js_yaml_1.default.load(data);
|
||||
}
|
||||
catch (e) {
|
||||
throw new errors_js_1.ParserError(e?.message || "Parser Error", file.url);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// data is already a JavaScript value (object, array, number, null, NaN, etc.)
|
||||
return data;
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user