2018-05-29 05:06:30 +02:00
|
|
|
/*
|
2021-01-20 02:52:56 +01:00
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
2021-02-04 03:12:39 +01:00
|
|
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
|
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
|
|
* Side Public License, v 1.
|
2018-05-29 05:06:30 +02:00
|
|
|
*/
|
|
|
|
|
2018-04-20 21:13:37 +02:00
|
|
|
exports.assert = function assert(truth, message) {
|
|
|
|
if (truth) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const error = new Error(message);
|
|
|
|
error.failedAssertion = true;
|
|
|
|
throw error;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.normalizeWhitespace = function normalizeWhitespace(string) {
|
|
|
|
return string.replace(/\s+/g, ' ');
|
|
|
|
};
|
|
|
|
|
2020-05-22 09:08:58 +02:00
|
|
|
exports.init = function (context, program, initStep) {
|
2018-04-20 21:13:37 +02:00
|
|
|
try {
|
|
|
|
return initStep();
|
|
|
|
} catch (error) {
|
|
|
|
if (error.failedAssertion) {
|
|
|
|
context.report({
|
|
|
|
node: program,
|
2019-03-23 01:12:14 +01:00
|
|
|
message: error.message,
|
2018-04-20 21:13:37 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|