contract.js 842 B

123456789101112131415161718192021222324252627
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. 'use strict';
  5. const { contract } = require('../../util/contract');
  6. const { isValidURI, URL, isLocalURL } = require('../../url');
  7. const { isNil, isObject, isString } = require('../../lang/type');
  8. exports.contract = contract({
  9. id: {
  10. is: [ 'string', 'undefined' ],
  11. ok: v => /^[a-z0-9-_]+$/i.test(v),
  12. msg: 'The option "id" must be a valid alphanumeric id (hyphens and ' +
  13. 'underscores are allowed).'
  14. },
  15. title: {
  16. is: [ 'string' ],
  17. ok: v => v.length
  18. },
  19. url: {
  20. is: [ 'string' ],
  21. ok: v => isLocalURL(v),
  22. map: function(v) v.toString(),
  23. msg: 'The option "url" must be a valid local URI.'
  24. }
  25. });