UI for Zipcoin Blue

ajv.absolutePath.js 780B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. const getErrorFor = (shouldBeAbsolute, data, schema) => {
  3. const message = shouldBeAbsolute ?
  4. `The provided value ${JSON.stringify(data)} is not an absolute path!`
  5. : `A relative path is expected. However the provided value ${JSON.stringify(data)} is an absolute path!`;
  6. return {
  7. keyword: "absolutePath",
  8. params: { absolutePath: data },
  9. message: message,
  10. parentSchema: schema,
  11. };
  12. };
  13. module.exports = (ajv) => ajv.addKeyword("absolutePath", {
  14. errors: true,
  15. type: "string",
  16. compile(expected, schema) {
  17. function callback(data) {
  18. const passes = expected === /^(?:[A-Za-z]:\\|\/)/.test(data);
  19. if(!passes) {
  20. callback.errors = [getErrorFor(expected, data, schema)];
  21. }
  22. return passes;
  23. }
  24. callback.errors = [];
  25. return callback;
  26. }
  27. });