Sha256: 854ca07e90e900caccaff5d8784045d53ff7bb5af2f12cb8ec8a5bcfcd1e14d1

Contents?: true

Size: 1.33 KB

Versions: 10

Compression:

Stored size: 1.33 KB

Contents

"use strict";

const errorMessage = (schema, data, message) => ({
	keyword: "absolutePath",
	params: { absolutePath: data },
	message: message,
	parentSchema: schema
});

const getErrorFor = (shouldBeAbsolute, data, schema) => {
	const message = shouldBeAbsolute
		? `The provided value ${JSON.stringify(data)} is not an absolute path!`
		: `A relative path is expected. However, the provided value ${JSON.stringify(
				data
		  )} is an absolute path!`;

	return errorMessage(schema, data, message);
};

module.exports = ajv =>
	ajv.addKeyword("absolutePath", {
		errors: true,
		type: "string",
		compile(expected, schema) {
			function callback(data) {
				let passes = true;
				const isExclamationMarkPresent = data.includes("!");
				const isCorrectAbsoluteOrRelativePath =
					expected === /^(?:[A-Za-z]:\\|\/)/.test(data);

				if (isExclamationMarkPresent) {
					callback.errors = [
						errorMessage(
							schema,
							data,
							`The provided value ${JSON.stringify(
								data
							)} contains exclamation mark (!) which is not allowed because it's reserved for loader syntax.`
						)
					];
					passes = false;
				}

				if (!isCorrectAbsoluteOrRelativePath) {
					callback.errors = [getErrorFor(expected, data, schema)];
					passes = false;
				}

				return passes;
			}
			callback.errors = [];

			return callback;
		}
	});

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/webpack/schemas/ajv.absolutePath.js
disco_app-0.18.2 test/dummy/node_modules/webpack/schemas/ajv.absolutePath.js
enju_library-0.3.8 spec/dummy/node_modules/webpack/schemas/ajv.absolutePath.js
jester-data-8.0.0 node_modules/webpack/schemas/ajv.absolutePath.js
ezii-os-5.2.1 node_modules/webpack/schemas/ajv.absolutePath.js
ezii-os-2.0.1 node_modules/webpack/schemas/ajv.absolutePath.js
ezii-os-1.1.0 node_modules/webpack/schemas/ajv.absolutePath.js
ezii-os-1.0.0 node_modules/webpack/schemas/ajv.absolutePath.js
ezii-os-0.0.0.1.0 node_modules/webpack/schemas/ajv.absolutePath.js
ezii-os-0.0.0.0.1 node_modules/webpack/schemas/ajv.absolutePath.js