addon-sdk/source/lib/sdk/places/contract.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     5 "use strict";
     7 module.metadata = {
     8   "stability": "unstable"
     9 };
    11 const { Cc, Ci } = require('chrome');
    12 const { EventEmitter } = require('../deprecated/events');
    13 const { isValidURI, URL } = require('../url');
    14 const { contract } = require('../util/contract');
    15 const { extend } = require('../util/object');
    17 // map of property validations
    18 const validItem = {
    19   id: {
    20     is: ['number', 'undefined', 'null'],
    21   },
    22   group: {
    23     is: ['object', 'number', 'undefined', 'null'],
    24     ok: function (value) {
    25       return value && 
    26         (value.toString && value.toString() === '[object Group]') ||
    27         typeof value === 'number' ||
    28         value.type === 'group';
    29     },
    30     msg: 'The `group` property must be a valid Group object'
    31   },
    32   index: {
    33     is: ['undefined', 'null', 'number'],
    34     map: function (value) value == null ? -1 : value,
    35     msg: 'The `index` property must be a number.'
    36   },
    37   updated: {
    38     is: ['number', 'undefined']
    39   }
    40 };
    42 const validTitle = {
    43   title: {
    44     is: ['string'],
    45     msg: 'The `title` property must be defined.'
    46   }
    47 };
    49 const validURL = {
    50   url: {
    51     is: ['string'], 
    52     ok: isValidURI,
    53     msg: 'The `url` property must be a valid URL.'
    54   }
    55 };
    57 const validTags = {
    58   tags: {
    59     is: ['object'],
    60     ok: function (tags) tags instanceof Set,
    61     map: function (tags) {
    62       if (Array.isArray(tags))
    63         return new Set(tags);
    64       if (tags == null)
    65         return new Set();
    66       return tags;
    67     },
    68     msg: 'The `tags` property must be a Set, or an array'
    69   }
    70 };
    72 exports.bookmarkContract = contract(
    73   extend(validItem, validTitle, validURL, validTags));
    74 exports.separatorContract = contract(validItem);
    75 exports.groupContract = contract(extend(validItem, validTitle));

mercurial