addon-sdk/source/lib/sdk/ui/sidebar/contract.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/lib/sdk/ui/sidebar/contract.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,27 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +* License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +'use strict';
     1.8 +
     1.9 +const { contract } = require('../../util/contract');
    1.10 +const { isValidURI, URL, isLocalURL } = require('../../url');
    1.11 +const { isNil, isObject, isString } = require('../../lang/type');
    1.12 +
    1.13 +exports.contract = contract({
    1.14 +  id: {
    1.15 +  	is: [ 'string', 'undefined' ],
    1.16 +  	ok: v => /^[a-z0-9-_]+$/i.test(v),
    1.17 +    msg: 'The option "id" must be a valid alphanumeric id (hyphens and ' +
    1.18 +         'underscores are allowed).'
    1.19 +  },
    1.20 +  title: {
    1.21 +  	is: [ 'string' ],
    1.22 +  	ok: v => v.length
    1.23 +  },
    1.24 +  url: {
    1.25 +    is: [ 'string' ],
    1.26 +    ok: v => isLocalURL(v),
    1.27 +    map: function(v) v.toString(),
    1.28 +    msg: 'The option "url" must be a valid local URI.'
    1.29 +  }
    1.30 +});

mercurial