<commit_before>'use strict';
/* A newable factory to handle xml files using the Perseus Treebank Schema
 *
 * The constructor functions takes a configuration object (that typically
 * contains a resource object for this service).
 *
 */
angular.module('arethusa').factory('TreebankRetriever', [
  'documentStore',
  'configurator',
  '$location',
  'idHandler',
  function (documentStore, configurator, $location, idHandler) {
    function xmlTokenToState(docIdentifier, token, sentenceId, artificials) {
      // One could formalize this to real rules that are configurable...
      //
      // Remember that attributes of the converted xml are prefixed with underscore
      var obj = {
        sentenceId: sentenceId,
        string: token._form,
        morphology: {
          lemma: token._lemma,
          postag: token._postag
        },
        relation: { label: token._relation || '' }

      };

      var gloss = token._gloss;
      if (gloss) {
        obj.morphology.gloss = gloss;
      }

      var sg = token._sg;
      if (sg && !sg.match(/^\s*$/)) {
        obj.sg = { ancestors: sg.split(' ') };
      }

      if (token._artificial) {
        obj.artificial = true;
        obj.type = token._artificial;
      }

      createId(obj, token, docIdentifier);
      createHead(obj, token, artificials);

      return obj;
    }

    function createId(stateToken, xmlToken, docIdentifier) {
      var idMap = new idHandler.Map();
      var internalId = xmlTokenId(xmlToken);
      var sourceId   = xmlToken._id;
      idMap.add(docIdentifier, internalId, sourceId);
      stateToken.id = internalId;
      stateToken.idMap = idMap;
    }

    function createHead(stateToken, xmlToken, artificials) {
      var head = xmlToken._head;
      if (angular.isDefined(head)) {
        var newHead = {};
        var artHead = artificials[head];
        newHead.id = artHead ? artHead : idHandler.getId(head);
        stateToken.head = newHead;
      }
    }

    function xmlTokenId(token) {
      return token._artificial ? token._insertion_id : idHandler.getId(token._id);
    }

    function extractArtificial(memo, token, i) {
      if (token._artificial) {
        memo[token._id] = token._insertion_id;
      }
    }

    function xmlSentenceToState(docIdentifier, words, id, cite) {
      var tokens = {};
      var artificials = arethusaUtil.inject({}, words, extractArtificial);
      angular.forEach(words, function (xmlToken, i) {
        var token = xmlTokenToState(docIdentifier, xmlToken, id, artificials);
        tokens[token.id] = token;
      });
      return {
        id: id,
        tokens: tokens,
        cite: cite
      };
    }

    function parseDocument(json, docIdentifier) {
      var sentences = arethusaUtil.toAry(json.treebank.sentence);
      return arethusaUtil.inject([], sentences, function (memo, sentence, k) {
        var cite = extractCiteInfo(sentence);
        memo.push(xmlSentenceToState(docIdentifier, sentence.word, sentence._id, cite));
      });
    }

    // Try to support the new as well as the old schema for now
    function extractCiteInfo(sentence) {
      var cite = sentence._cite;
      if (cite) {
        return cite;
      } else {

        var docId = sentence._document_id;
        var subdoc = sentence._subdoc;
        if (subdoc) {
          return docId + ':' + subdoc;
        } else {
          return docId;
        }
      }
    }

    function findAdditionalConfInfo(json) {
      var linkInfo = json.treebank.link;
      var links =  linkInfo ? arethusaUtil.toAry(linkInfo) : [];
      return arethusaUtil.inject({}, links, function(memo, link) {
        memo[link._title] = link._href;
      });
    }

    function parsePreselections(selector) {
      // after #191 is merged, also allow range strings here
      var preselections = arethusaUtil.toAry($location.search()[selector]);
      return arethusaUtil.map(preselections, function(id) {
        return idHandler.getId(id);
      });
    }

    function Doc(xml, json, conf) {
      this.xml = xml;
      this.json = json;
      this.conf = conf;
    }

    return function (conf) {
      var self = this;
      var resource = configurator.provideResource(conf.resource);
      var docIdentifier = conf.docIdentifier;

      this.preselections = parsePreselections(conf.preselector);
      this.getData = function (callback) {
        resource.get().then(function (res) {
          var xml = res.data;
          var json = arethusaUtil.xml2json(res.data);
          var moreConf = findAdditionalConfInfo(json);

          documentStore.addDocument(docIdentifier, new Doc(xml, json, moreConf));
          callback(parseDocument(json, docIdentifier));
        });
      };
    };
  }
]);
<commit_msg>Store format info in treebankRetriever<commit_after>'use strict';
/* A newable factory to handle xml files using the Perseus Treebank Schema
 *
 * The constructor functions takes a configuration object (that typically
 * contains a resource object for this service).
 *
 */
angular.module('arethusa').factory('TreebankRetriever', [
  'documentStore',
  'configurator',
  '$location',
  'idHandler',
  function (documentStore, configurator, $location, idHandler) {
    function xmlTokenToState(docIdentifier, token, sentenceId, artificials) {
      // One could formalize this to real rules that are configurable...
      //
      // Remember that attributes of the converted xml are prefixed with underscore
      var obj = {
        sentenceId: sentenceId,
        string: token._form,
        morphology: {
          lemma: token._lemma,
          postag: token._postag
        },
        relation: { label: token._relation || '' }

      };

      var gloss = token._gloss;
      if (gloss) {
        obj.morphology.gloss = gloss;
      }

      var sg = token._sg;
      if (sg && !sg.match(/^\s*$/)) {
        obj.sg = { ancestors: sg.split(' ') };
      }

      if (token._artificial) {
        obj.artificial = true;
        obj.type = token._artificial;
      }

      createId(obj, token, docIdentifier);
      createHead(obj, token, artificials);

      return obj;
    }

    function createId(stateToken, xmlToken, docIdentifier) {
      var idMap = new idHandler.Map();
      var internalId = xmlTokenId(xmlToken);
      var sourceId   = xmlToken._id;
      idMap.add(docIdentifier, internalId, sourceId);
      stateToken.id = internalId;
      stateToken.idMap = idMap;
    }

    function createHead(stateToken, xmlToken, artificials) {
      var head = xmlToken._head;
      if (angular.isDefined(head)) {
        var newHead = {};
        var artHead = artificials[head];
        newHead.id = artHead ? artHead : idHandler.getId(head);
        stateToken.head = newHead;
      }
    }

    function xmlTokenId(token) {
      return token._artificial ? token._insertion_id : idHandler.getId(token._id);
    }

    function extractArtificial(memo, token, i) {
      if (token._artificial) {
        memo[token._id] = token._insertion_id;
      }
    }

    function xmlSentenceToState(docIdentifier, words, id, cite) {
      var tokens = {};
      var artificials = arethusaUtil.inject({}, words, extractArtificial);
      angular.forEach(words, function (xmlToken, i) {
        var token = xmlTokenToState(docIdentifier, xmlToken, id, artificials);
        tokens[token.id] = token;
      });
      return {
        id: id,
        tokens: tokens,
        cite: cite
      };
    }

    function parseDocument(json, docIdentifier) {
      var sentences = arethusaUtil.toAry(json.treebank.sentence);
      return arethusaUtil.inject([], sentences, function (memo, sentence, k) {
        var cite = extractCiteInfo(sentence);
        memo.push(xmlSentenceToState(docIdentifier, sentence.word, sentence._id, cite));
      });
    }

    // Try to support the new as well as the old schema for now
    function extractCiteInfo(sentence) {
      var cite = sentence._cite;
      if (cite) {
        return cite;
      } else {

        var docId = sentence._document_id;
        var subdoc = sentence._subdoc;
        if (subdoc) {
          return docId + ':' + subdoc;
        } else {
          return docId;
        }
      }
    }

    function findAdditionalConfInfo(json) {
      var linkInfo = json.treebank.link;
      var links =  linkInfo ? arethusaUtil.toAry(linkInfo) : [];
      var confs = arethusaUtil.inject({}, links, function(memo, link) {
        memo[link._title] = link._href;
      });
      var format = json.treebank._format;
      if (format) {
        confs.fullFile = format;
      }
      return confs;
    }

    function parsePreselections(selector) {
      // after #191 is merged, also allow range strings here
      var preselections = arethusaUtil.toAry($location.search()[selector]);
      return arethusaUtil.map(preselections, function(id) {
        return idHandler.getId(id);
      });
    }

    function Doc(xml, json, conf) {
      this.xml = xml;
      this.json = json;
      this.conf = conf;
    }

    return function (conf) {
      var self = this;
      var resource = configurator.provideResource(conf.resource);
      var docIdentifier = conf.docIdentifier;

      this.preselections = parsePreselections(conf.preselector);
      this.getData = function (callback) {
        resource.get().then(function (res) {
          var xml = res.data;
          var json = arethusaUtil.xml2json(res.data);
          var moreConf = findAdditionalConfInfo(json);

          documentStore.addDocument(docIdentifier, new Doc(xml, json, moreConf));
          callback(parseDocument(json, docIdentifier));
        });
      };
    };
  }
]);
<|endoftext|>


<commit_before>/**
 * GwikiItem - an object representing a GoogleDrive object with extra fields pertinent to Gwiki
 */

GwikiItem = function(opts, debug) {
    var t, defaultParams = {
        id: null,
        name: null,
        displayName: null,
        mimeType: null,
        gwikiType: null,
        body: null,
        bodySrc: null,
        isTerminus: null,
        isConsumable: null,
        selected: false,
        children: null,
        parents: null,
        bridge: null,
        isHome: false
    };

    // Get cached item, if possible
    if (typeof opts.id != 'undefined') {
        if (typeof GwikiItem.cache[opts.id] == 'undefined') {
            Utils.merge(this, defaultParams, opts || {});
            GwikiItem.cache[opts.id] = this;
            t = this;
        } else {
            t = GwikiItem.cache[opts.id];
        }
    } else {
        t = this;
        Utils.merge(t, defaultParams, opts || {});
    }

    // Set extra attributes that might not already be set
    t.setExtraAttributes(debug);

    return t;
}

GwikiItem.prototype = Object.create(Object.prototype);
GwikiItem.interface = [ 'id', 'name', 'displayName', 'mimeType', 'gwikiType', 'body', 'bodySrc', 'isTerminus', 'isConsumable', 'selected', 'children', 'parents', 'getParents' ];

GwikiItem.prototype.setExtraAttributes = function() {
    // If it's not a folder, then it's a "terminus" page
    if (this.isTerminus === null) this.isTerminus = (this.mimeType != 'application/vnd.google-apps.folder');

    // If it's terminus, then it's its own bodySrc (otherwise we don't know)
    if (this.bodySrc === null) this.bodySrc = (this.isTerminus ? this : null);

    // See if it's "consumable" by our wiki
    if (this.isConsumable === null && this.mimeType && this.name) {
        this.isConsumable = (
            GwikiItem.consumableTypes.indexOf(this.mimeType) > -1 ||
            this.name.substr(-3) == '.md'
        );
    }

    // See if it's text format
    if (this.gwikiType === null && this.mimeType && this.name) {
        if (this.mimeType == 'text/x-markdown' || this.mimeType == 'text/markdown' || this.mimeType == 'text/plain' || this.name.substr(-3) == '.md') this.gwikiType = 'text/markdown';
        else if (this.mimeType == 'text/html' || this.mimeType == 'application/vnd.google-apps.document') this.gwikiType = 'text/html';
        else this.gwikiType = 'unknown';
    }

    // Remove prefixes and suffixes for display names
    if (this.displayName === null && this.name) {
        var displayName = this.name;
        var prefix = displayName.match(/^[0-9_. -]/);
        var suffix = displayName.match(/\..{1,4}$/);
        if (prefix) displayName = displayName.substr(prefix[0].length);
        if (suffix) displayName = displayName.substr(0, (displayName.length - suffix[0].length));
        this.displayName = displayName;
    }
}

GwikiItem.prototype.getChildren = function() {
    this.checkBridge();

    var t = this, children = [], callback;
    var go = { then: function(c) { c(t.children); } };
    var thenGo = { then: function(c) { callback = c; } };

    // If we've already gotten the children, return
    if (this.children !== null) return go;

    this.bridge.getChildrenFor(this).then(function(items) {
        // Instanitate, filter and sort
        items = t.prepareItemsCollection(items);

        // Now separate content child from regular children
        for (var i = 0; i < items.length; i++) {
            // Now, if child has same name as parent and isn't a folder, set it as the bodySrc of parent
            if (items[i].displayName == t.displayName && items[i].isTerminus) {
                if (items[i].isConsumable) t.bodySrc = items[i];

            // Else, add it to the children list
            } else children.push(items[i]);
        }

        t.children = children;

        // Then call callback
        if (callback) callback(t.children);
    });

    return { then: function(c) { callback = c; } };
}

GwikiItem.prototype.getBody = function() {
    this.checkBridge();

    var t = this, callback;
    var go = { then: function(c) { c(t.body); } };
    var thenGo = { then: function(c) { callback = c; } };

    // If no bodySrc, can't get body
    if (!this.bodySrc) {
        return go;
    }

    else {
        // If bodySrc not up to date, update it and try again
        if (!this.bodySrc.mimeType || !this.bodySrc.gwikiType) {
            this.bodySrc.update().then(function() {
                t.getBody().then(function() {
                    if (callback) callback(t.body);
                });
            });
            return thenGo;
        }

        // If it's markdown, download the content
        if (this.bodySrc.gwikiType == 'text/markdown' || this.bodySrc.mimeType == 'text/html') {
            this.bridge.downloadContent(this.bodySrc).then(function(body) {
                t.body = body;
                t.bodySrc.body = body;
                if (callback) callback(t.body);
            });

        // If it's a doc, export it as html
        } else if (this.bodySrc.mimeType == 'application/vnd.google-apps.document') {
            this.bridge.exportContent(this.bodySrc).then(function(body) {
                t.body = body;
                t.bodySrc.body = body;
                if (callback) callback(t.body);
            });

        // Otherwise, can't download body content, must embed (just return)
        } else {
            return go;
        }

        return thenGo;
    }
}

GwikiItem.prototype.prepareItemsCollection = function(items) {
    var children = [];

    // Complete info and filter for consumables
    for (var i = 0; i < items.length; i++) {
        // First, add "this" to parents array
        if (items[i].parents && items[i].parents.length) {
            for (j = 0; j < items[i].parents.length; j++) {
                if (items[i].parents[j] == this.id) {
                    items[i].parents[j] = this;
                    added = true;
                    break;
                }
            }
            if (j == items[i].parents[j].length) items[i].parents[j] = this;
        }

        items[i] = new GwikiItem(items[i], true);
        if (!items[i].isConsumable) continue;

        items[i].bridge = this.bridge;

        // Add to children array
        children.push(items[i]);
    }

    // Sort by name
    for (var i = 0; i < children.length - 1; i++) {
        for (var j = i+1; j < children.length; j++) {
            if (children[i].name > children[j].name) {
                var tmp = children[j];
                children[j] = children[i];
                children[i] = tmp;
            }
        }
    }

    return children;
}

GwikiItem.prototype.update = function() {
    var t = this, callback;
    this.checkBridge();
    this.bridge.getItemById(this.id).then(function(item) {
        for (var x in t) {
            if (typeof t[x] == 'function') continue;
            if (typeof item[x] != 'undefined') t[x] = item[x];
        }
        t.setExtraAttributes();
        if (callback) callback(t);
    });
    return { then: function(c) { callback = c; } };
}

GwikiItem.prototype.getParents = function() {
    var t = this, callback;
    var go = { then: function(c) { c(t.parents); } };
    var thenGo = { then: function(c) { callback = c; } };

    if (this.isHome) {
        this.parents = [];
        return go;
    }

    // If we don't have a parents collection, get one and try again
    if (!this.parents) {
        this.update().then(function() {
            t.getParents().then(function() {
                if (callback) callback(t.parents);
            });
        });
        return thenGo;
    }

    // If we do, make sure they're all instantiated
    var returnCounter = 0;
    for (var j = 0; j < this.parents.length; j++) {
        if (typeof this.parents[j] == 'string') {
            this.parents[j] = new GwikiItem({ "id" : this.parents[j], "bridge" : this.bridge });
            this.parents[j].update().then(function() {
                returnCounter++;
                if (returnCounter == t.parents.length && callback) callback(t.parents);
            });
        } else {
            if (!(this.parents[j] instanceof GwikiItem)) throw GwikiItem.strings['errParentInvalid'];
            returnCounter++;
        }
    }

    if (returnCounter == t.parents.length) return go;
    else return thenGo;
}

GwikiItem.prototype.checkBridge = function() {
    if (!Utils.implements(GwikiBridge.interface, this.bridge)) throw "If you pass a `bridge` property, it must be a valid GwikiBridge object (see `GwikiBridge.interface` for methods and properties that you must implement)";
}

GwikiItem.cache = {}
GwikiItem.consumableTypes = [
    'application/vnd.google-apps.folder',
    'application/vnd.google-apps.document',
    'application/vnd.google-apps.spreadsheet',
    'application/vnd.google-apps.presentation',
    'text/x-markdown',
    'text/markdown',
    'text/html',
    'application/rtf',
    'application/vnd.oasis.opendocument.text',
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    'application/vnd.oasis.opendocument.presentation',
    'application/vnd.openxmlformats-officedocument.presentationml.presentation',
    'application/pdf',
    'text/plain'
];

GwikiItem.strings = {
    'errParentInvalid' : "Objects in the parents collection must be either strings representing parentIds or fully instantiated GwikiItems."
}

<commit_msg>Fixed bug in display name parsing that didn't properly clear numeric prefixes<commit_after>/**
 * GwikiItem - an object representing a GoogleDrive object with extra fields pertinent to Gwiki
 */

GwikiItem = function(opts, debug) {
    var t, defaultParams = {
        id: null,
        name: null,
        displayName: null,
        mimeType: null,
        gwikiType: null,
        body: null,
        bodySrc: null,
        isTerminus: null,
        isConsumable: null,
        selected: false,
        children: null,
        parents: null,
        bridge: null,
        isHome: false
    };

    // Get cached item, if possible
    if (typeof opts.id != 'undefined') {
        if (typeof GwikiItem.cache[opts.id] == 'undefined') {
            Utils.merge(this, defaultParams, opts || {});
            GwikiItem.cache[opts.id] = this;
            t = this;
        } else {
            t = GwikiItem.cache[opts.id];
        }
    } else {
        t = this;
        Utils.merge(t, defaultParams, opts || {});
    }

    // Set extra attributes that might not already be set
    t.setExtraAttributes(debug);

    return t;
}

GwikiItem.prototype = Object.create(Object.prototype);
GwikiItem.interface = [ 'id', 'name', 'displayName', 'mimeType', 'gwikiType', 'body', 'bodySrc', 'isTerminus', 'isConsumable', 'selected', 'children', 'parents', 'getParents' ];

GwikiItem.prototype.setExtraAttributes = function() {
    // If it's not a folder, then it's a "terminus" page
    if (this.isTerminus === null) this.isTerminus = (this.mimeType != 'application/vnd.google-apps.folder');

    // If it's terminus, then it's its own bodySrc (otherwise we don't know)
    if (this.bodySrc === null) this.bodySrc = (this.isTerminus ? this : null);

    // See if it's "consumable" by our wiki
    if (this.isConsumable === null && this.mimeType && this.name) {
        this.isConsumable = (
            GwikiItem.consumableTypes.indexOf(this.mimeType) > -1 ||
            this.name.substr(-3) == '.md'
        );
    }

    // See if it's text format
    if (this.gwikiType === null && this.mimeType && this.name) {
        if (this.mimeType == 'text/x-markdown' || this.mimeType == 'text/markdown' || this.mimeType == 'text/plain' || this.name.substr(-3) == '.md') this.gwikiType = 'text/markdown';
        else if (this.mimeType == 'text/html' || this.mimeType == 'application/vnd.google-apps.document') this.gwikiType = 'text/html';
        else this.gwikiType = 'unknown';
    }

    // Remove prefixes and suffixes for display names
    if (this.displayName === null && this.name) {
        var displayName = this.name;
        var prefix = displayName.match(/^[0-9_. -]+/);
        var suffix = displayName.match(/\.[^ ]{1,4}$/);
        if (prefix) displayName = displayName.substr(prefix[0].length);
        if (suffix) displayName = displayName.substr(0, (displayName.length - suffix[0].length));
        this.displayName = displayName;
    }
}

GwikiItem.prototype.getChildren = function() {
    this.checkBridge();

    var t = this, children = [], callback;
    var go = { then: function(c) { c(t.children); } };
    var thenGo = { then: function(c) { callback = c; } };

    // If we've already gotten the children, return
    if (this.children !== null) return go;

    this.bridge.getChildrenFor(this).then(function(items) {
        // Instanitate, filter and sort
        items = t.prepareItemsCollection(items);

        // Now separate content child from regular children
        for (var i = 0; i < items.length; i++) {
            // Now, if child has same name as parent and isn't a folder, set it as the bodySrc of parent
            if (items[i].displayName == t.displayName && items[i].isTerminus) {
                if (items[i].isConsumable) t.bodySrc = items[i];

            // Else, add it to the children list
            } else children.push(items[i]);
        }

        t.children = children;

        // Then call callback
        if (callback) callback(t.children);
    });

    return { then: function(c) { callback = c; } };
}

GwikiItem.prototype.getBody = function() {
    this.checkBridge();

    var t = this, callback;
    var go = { then: function(c) { c(t.body); } };
    var thenGo = { then: function(c) { callback = c; } };

    // If no bodySrc, can't get body
    if (!this.bodySrc) {
        return go;
    }

    else {
        // If bodySrc not up to date, update it and try again
        if (!this.bodySrc.mimeType || !this.bodySrc.gwikiType) {
            this.bodySrc.update().then(function() {
                t.getBody().then(function() {
                    if (callback) callback(t.body);
                });
            });
            return thenGo;
        }

        // If it's markdown, download the content
        if (this.bodySrc.gwikiType == 'text/markdown' || this.bodySrc.mimeType == 'text/html') {
            this.bridge.downloadContent(this.bodySrc).then(function(body) {
                t.body = body;
                t.bodySrc.body = body;
                if (callback) callback(t.body);
            });

        // If it's a doc, export it as html
        } else if (this.bodySrc.mimeType == 'application/vnd.google-apps.document') {
            this.bridge.exportContent(this.bodySrc).then(function(body) {
                t.body = body;
                t.bodySrc.body = body;
                if (callback) callback(t.body);
            });

        // Otherwise, can't download body content, must embed (just return)
        } else {
            return go;
        }

        return thenGo;
    }
}

GwikiItem.prototype.prepareItemsCollection = function(items) {
    var children = [];

    // Complete info and filter for consumables
    for (var i = 0; i < items.length; i++) {
        // First, add "this" to parents array
        if (items[i].parents && items[i].parents.length) {
            for (j = 0; j < items[i].parents.length; j++) {
                if (items[i].parents[j] == this.id) {
                    items[i].parents[j] = this;
                    added = true;
                    break;
                }
            }
            if (j == items[i].parents[j].length) items[i].parents[j] = this;
        }

        items[i] = new GwikiItem(items[i], true);
        if (!items[i].isConsumable) continue;

        items[i].bridge = this.bridge;

        // Add to children array
        children.push(items[i]);
    }

    // Sort by name
    for (var i = 0; i < children.length - 1; i++) {
        for (var j = i+1; j < children.length; j++) {
            if (children[i].name > children[j].name) {
                var tmp = children[j];
                children[j] = children[i];
                children[i] = tmp;
            }
        }
    }

    return children;
}

GwikiItem.prototype.update = function() {
    var t = this, callback;
    this.checkBridge();
    this.bridge.getItemById(this.id).then(function(item) {
        for (var x in t) {
            if (typeof t[x] == 'function') continue;
            if (typeof item[x] != 'undefined') t[x] = item[x];
        }
        t.setExtraAttributes();
        if (callback) callback(t);
    });
    return { then: function(c) { callback = c; } };
}

GwikiItem.prototype.getParents = function() {
    var t = this, callback;
    var go = { then: function(c) { c(t.parents); } };
    var thenGo = { then: function(c) { callback = c; } };

    if (this.isHome) {
        this.parents = [];
        return go;
    }

    // If we don't have a parents collection, get one and try again
    if (!this.parents) {
        this.update().then(function() {
            t.getParents().then(function() {
                if (callback) callback(t.parents);
            });
        });
        return thenGo;
    }

    // If we do, make sure they're all instantiated
    var returnCounter = 0;
    for (var j = 0; j < this.parents.length; j++) {
        if (typeof this.parents[j] == 'string') {
            this.parents[j] = new GwikiItem({ "id" : this.parents[j], "bridge" : this.bridge });
            this.parents[j].update().then(function() {
                returnCounter++;
                if (returnCounter == t.parents.length && callback) callback(t.parents);
            });
        } else {
            if (!(this.parents[j] instanceof GwikiItem)) throw GwikiItem.strings['errParentInvalid'];
            returnCounter++;
        }
    }

    if (returnCounter == t.parents.length) return go;
    else return thenGo;
}

GwikiItem.prototype.checkBridge = function() {
    if (!Utils.implements(GwikiBridge.interface, this.bridge)) throw "If you pass a `bridge` property, it must be a valid GwikiBridge object (see `GwikiBridge.interface` for methods and properties that you must implement)";
}

GwikiItem.cache = {}
GwikiItem.consumableTypes = [
    'application/vnd.google-apps.folder',
    'application/vnd.google-apps.document',
    'application/vnd.google-apps.spreadsheet',
    'application/vnd.google-apps.presentation',
    'text/x-markdown',
    'text/markdown',
    'text/html',
    'application/rtf',
    'application/vnd.oasis.opendocument.text',
    'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    'application/vnd.oasis.opendocument.presentation',
    'application/vnd.openxmlformats-officedocument.presentationml.presentation',
    'application/pdf',
    'text/plain'
];

GwikiItem.strings = {
    'errParentInvalid' : "Objects in the parents collection must be either strings representing parentIds or fully instantiated GwikiItems."
}

<|endoftext|>


<commit_before>////////////////////////////////////////////////
/*   Provided Code - Please Don't Edit   */
////////////////////////////////////////////////
'use strict';

function getInput() {
    console.log("Please choose either 'rock', 'paper', or 'scissors'.")
    return prompt();
}
function randomPlay() {
    var randomNumber = Math.random();
    if (randomNumber < 0.33) {
        return "rock";
    } else if (randomNumber < 0.66) {
        return "paper";
    } else {
        return "scissors";
    }
}
////////////////////////////////////////////////
/*           Write Your Code Below            */
////////////////////////////////////////////////

function getPlayerMove(move) {
    // Write an expression that operates on a variable called `move`
    // If a `move` has a value, your expression should evaluate to that value.
    // However, if `move` is not specified / is null, your expression should equal `getInput()`.
    return move || getInput();
}

function getComputerMove(move) {
    // Write an expression that operates on a variable called `move`
    // If a `move` has a value, your expression should evaluate to that value.
    // However, if `move` is not specified / is null, your expression should equal `randomPlay()`.
    return move || randomPlay();
}

function getWinner(playerMove,computerMove) {
    var winner;
    // Write code that will set winner to either 'player', 'computer', or 'tie' based on the values of playerMove and computerMove.
    // Assume that the only values playerMove and computerMove can have are 'rock', 'paper', and 'scissors'.
    // The rules of the game are that 'rock' beats 'scissors', 'scissors' beats 'paper', and 'paper' beats 'rock'.
    if ((playerMove="rock" && computerMove="scissors") || (playerMove="scissors" && computerMove="paper") || (playerMove="paper" && computerMove="rock")) {
      winner="player";
    } else if ((computerMove="rock" && playerMove="paper") || (computerMove="scissors" && playerMove="paper") || (computerMove="paper" && playerMove="rock")) {
      winner="computer";
    } else {
      winner="tie";
    }
    return winner;
}

function playToFive() {
    console.log("Let's play Rock, Paper, Scissors");
    var playerWins = 0;
    var computerWins = 0;
    // Write code that plays 'Rock, Paper, Scissors' until either the player or the computer has won five times.
    /* YOUR CODE HERE */
    return [playerWins, computerWins];
}
<commit_msg>Added playto(x) function<commit_after>////////////////////////////////////////////////
/*   Provided Code - Please Don't Edit   */
////////////////////////////////////////////////
'use strict';

function getInput() {
    console.log("Please choose either 'rock', 'paper', or 'scissors'.")
    return prompt();
}
function randomPlay() {
    var randomNumber = Math.random();
    if (randomNumber < 0.33) {
        return "rock";
    } else if (randomNumber < 0.66) {
        return "paper";
    } else {
        return "scissors";
    }
}
////////////////////////////////////////////////
/*           Write Your Code Below            */
////////////////////////////////////////////////

function getPlayerMove(move) {
    // Write an expression that operates on a variable called `move`
    // If a `move` has a value, your expression should evaluate to that value.
    // However, if `move` is not specified / is null, your expression should equal `getInput()`.
    return move || getInput();
}

function getComputerMove(move) {
    // Write an expression that operates on a variable called `move`
    // If a `move` has a value, your expression should evaluate to that value.
    // However, if `move` is not specified / is null, your expression should equal `randomPlay()`.
    return move || randomPlay();
}

function getWinner(playerMove,computerMove) {
    var winner;
    // Write code that will set winner to either 'player', 'computer', or 'tie' based on the values of playerMove and computerMove.
    // Assume that the only values playerMove and computerMove can have are 'rock', 'paper', and 'scissors'.
    // The rules of the game are that 'rock' beats 'scissors', 'scissors' beats 'paper', and 'paper' beats 'rock'.
    if ((playerMove=="rock" && computerMove=="scissors") || (playerMove=="scissors" && computerMove=="paper") || (playerMove=="paper" && computerMove=="rock")) {
      winner="player";
    } else if ((computerMove=="rock" && playerMove=="paper") || (computerMove=="scissors" && playerMove=="paper") || (computerMove=="paper" && playerMove=="rock")) {
      winner="computer";
    } else {
      winner="tie";
    }
    return winner;
}

function playTo(x) {
    console.log("Let's play Rock, Paper, Scissors");
    var playerWins = 0;
    var computerWins = 0;
    var gameTie = 0;
    // Write code that plays 'Rock, Paper, Scissors' until either the player or the computer has won 'x' times.
    for (var i = 0; i < x; i += 1) {
      var winner = getWinner(getPlayerMove(),getComputerMove());
      switch (winner) {
        case "player":
          playerWins += 1;
          break;
        case "computer":
          computerWins += 1;
          break;
        default:
          gameTie += 1;
      }
    }
    return [playerWins, computerWins];
}
<|endoftext|>


<commit_before>const error = 2;
const warn = 1;
const ignore = 0;

module.exports = {
  root: true,
  extends: [
    'airbnb',
    'plugin:jest/recommended',
    'plugin:import/react-native',
    'prettier',
    'prettier/react',
  ],
  plugins: ['prettier', 'jest', 'import', 'react', 'jsx-a11y', 'json'],
  parser: 'babel-eslint',
  parserOptions: {
    ecmaVersion: 8,
    sourceType: 'module',
  },
  env: {
    es6: true,
    node: true,
    'jest/globals': true,
  },
  settings: {
    'import/core-modules': ['enzyme'],
    'import/ignore': ['node_modules\\/(?!@storybook)'],
    'import/resolver': {
      node: {
        extensions: ['.js'],
      },
    },
  },
  rules: {
    'prettier/prettier': [
      warn,
      {
        printWidth: 100,
        tabWidth: 2,
        bracketSpacing: true,
        trailingComma: 'es5',
        singleQuote: true,
      },
    ],
    'no-debugger': process.env.NODE_ENV === 'production' ? error : ignore,
    'class-methods-use-this': ignore,
    'import/extensions': [
      error,
      'always',
      {
        js: 'never',
        ts: 'never',
      },
    ],
    'import/no-extraneous-dependencies': [
      error,
      {
        devDependencies: [
          'examples/**',
          'examples-native/**',
          '**/example/**',
          '*.js',
          '**/*.test.js',
          '**/*.stories.js',
          '**/scripts/*.js',
          '**/stories/**/*.js',
          '**/__tests__/**/*.js',
          '**/.storybook/**/*.js',
        ],
        peerDependencies: true,
      },
    ],
    'import/prefer-default-export': ignore,
    'import/default': error,
    'import/named': error,
    'import/namespace': error,
    'react/jsx-filename-extension': [
      warn,
      {
        extensions: ['.js', '.jsx', '.tsx'],
      },
    ],
    'react/jsx-no-bind': [
      error,
      {
        ignoreDOMComponents: true,
        ignoreRefs: true,
        allowArrowFunctions: true,
        allowFunctions: true,
        allowBind: true,
      },
    ],
    'jsx-a11y/label-has-associated-control': [
      warn,
      {
        labelComponents: ['CustomInputLabel'],
        labelAttributes: ['label'],
        controlComponents: ['CustomInput'],
        depth: 3,
      },
    ],
    'react/no-unescaped-entities': ignore,
    'jsx-a11y/label-has-for': [
      error,
      {
        required: {
          some: ['nesting', 'id'],
        },
      },
    ],
    'jsx-a11y/anchor-is-valid': [
      error,
      {
        components: ['RoutedLink', 'MenuLink', 'LinkTo', 'Link'],
        specialLink: ['overrideParams', 'kind', 'story', 'to'],
      },
    ],
    'no-underscore-dangle': [
      error,
      {
        allow: ['__STORYBOOK_CLIENT_API__', '__STORYBOOK_ADDONS_CHANNEL__'],
      },
    ],
  },
  overrides: [
    {
      files: ['**/react-native*/**', '**/REACT_NATIVE*/**', '**/crna*/**'],
      rules: {
        'jsx-a11y/accessible-emoji': ignore,
      },
    },
    {
      files: '**/.storybook/config.js',
      rules: {
        'global-require': ignore,
      },
    },
  ],
};
<commit_msg>Re-added .ts to import/resolver in eslint<commit_after>const error = 2;
const warn = 1;
const ignore = 0;

module.exports = {
  root: true,
  extends: [
    'airbnb',
    'plugin:jest/recommended',
    'plugin:import/react-native',
    'prettier',
    'prettier/react',
  ],
  plugins: ['prettier', 'jest', 'import', 'react', 'jsx-a11y', 'json'],
  parser: 'babel-eslint',
  parserOptions: {
    ecmaVersion: 8,
    sourceType: 'module',
  },
  env: {
    es6: true,
    node: true,
    'jest/globals': true,
  },
  settings: {
    'import/core-modules': ['enzyme'],
    'import/ignore': ['node_modules\\/(?!@storybook)'],
    'import/resolver': {
      node: {
        extensions: ['.js', '.ts'],
      },
    },
  },
  rules: {
    'prettier/prettier': [
      warn,
      {
        printWidth: 100,
        tabWidth: 2,
        bracketSpacing: true,
        trailingComma: 'es5',
        singleQuote: true,
      },
    ],
    'no-debugger': process.env.NODE_ENV === 'production' ? error : ignore,
    'class-methods-use-this': ignore,
    'import/extensions': [
      error,
      'always',
      {
        js: 'never',
        ts: 'never',
      },
    ],
    'import/no-extraneous-dependencies': [
      error,
      {
        devDependencies: [
          'examples/**',
          'examples-native/**',
          '**/example/**',
          '*.js',
          '**/*.test.js',
          '**/*.stories.js',
          '**/scripts/*.js',
          '**/stories/**/*.js',
          '**/__tests__/**/*.js',
          '**/.storybook/**/*.js',
        ],
        peerDependencies: true,
      },
    ],
    'import/prefer-default-export': ignore,
    'import/default': error,
    'import/named': error,
    'import/namespace': error,
    'react/jsx-filename-extension': [
      warn,
      {
        extensions: ['.js', '.jsx', '.tsx'],
      },
    ],
    'react/jsx-no-bind': [
      error,
      {
        ignoreDOMComponents: true,
        ignoreRefs: true,
        allowArrowFunctions: true,
        allowFunctions: true,
        allowBind: true,
      },
    ],
    'jsx-a11y/label-has-associated-control': [
      warn,
      {
        labelComponents: ['CustomInputLabel'],
        labelAttributes: ['label'],
        controlComponents: ['CustomInput'],
        depth: 3,
      },
    ],
    'react/no-unescaped-entities': ignore,
    'jsx-a11y/label-has-for': [
      error,
      {
        required: {
          some: ['nesting', 'id'],
        },
      },
    ],
    'jsx-a11y/anchor-is-valid': [
      error,
      {
        components: ['RoutedLink', 'MenuLink', 'LinkTo', 'Link'],
        specialLink: ['overrideParams', 'kind', 'story', 'to'],
      },
    ],
    'no-underscore-dangle': [
      error,
      {
        allow: ['__STORYBOOK_CLIENT_API__', '__STORYBOOK_ADDONS_CHANNEL__'],
      },
    ],
  },
  overrides: [
    {
      files: ['**/react-native*/**', '**/REACT_NATIVE*/**', '**/crna*/**'],
      rules: {
        'jsx-a11y/accessible-emoji': ignore,
      },
    },
    {
      files: '**/.storybook/config.js',
      rules: {
        'global-require': ignore,
      },
    },
  ],
};
<|endoftext|>


<commit_before>////////////////////////////////////////////////
/*   Provided Code - Please Don't Edit   */
////////////////////////////////////////////////
'use strict';

function getInput() {
    console.log("Please choose either 'rock', 'paper', or 'scissors'.")
    return prompt();
}
function randomPlay() {
    var randomNumber = Math.random();
    if (randomNumber < 0.33) {
        return "rock";
    } else if (randomNumber < 0.66) {
        return "paper";
    } else {
        return "scissors";
    }
}
////////////////////////////////////////////////
/*           Write Your Code Below            */
////////////////////////////////////////////////

function getPlayerMove() {
    var i = 0
    while(i < 5){
        var move = getInput();
        if(move == "paper"){
            console.log("player chose "+move);
        	i+=5
        }else if(move == "rock"){
            console.log("player chose "+move);
        	i+=5
        }else if(move == "scissors"){
            console.log("player chose "+move);
        	i+=5
        }else{
        	console.log(move+" is not a valid input");
        }
    }
    return move;
}

function getComputerMove() {
    // Write an expression that operates on a variable called `move`
    var move = null;
    var computerMove;
    // If a `move` has a value, your expression should evaluate to that value.
	(move !== null)? computerMove = move : computerMove = randomPlay();
    // However, if `move` is not specified / is null, your expression should equal `randomPlay()`.
    return computerMove;
}

function getWinner(playerMove,computerMove) {
    var winner;
    // Write code that will set winner to either 'player', 'computer', or 'tie' based on the values of playerMove and computerMove.
    if (playerMove == "rock" && computerMove == "paper"){
    	winner = "computer";
    }else if (playerMove == "rock" && computerMove == "scissors"){
    	winner = "player";
    }else if (playerMove == computerMove){
    	winner = "tie";
    }else if (playerMove == "paper" && computerMove == "scissors"){
    	winner = "computer";
    }else if (playerMove == "paper" && computerMove == "rock"){
    	winner = "player";
    }else if (playerMove == "scissors" && computerMove == "rock"){
    	winner = "computer";
    }else if (playerMove == "scissors" && computerMove == "paper"){
    	winner = "player";
    }
    return winner;
}

function playToFive() {
	console.log('Let\'s play Rock Paper Scissors');
	var playerWins = 0;
	var computerWins = 0;

	while(count < 30){
    	console.log(playerWins+" "+computerWins);

        if(playerWins == 5){
            count+=31;
            console.log("Player wins!");
        }else if(computerWins){
        	count+=31;
            console.log("Computer wins!");
        }
	}
  // This function should continue to play Rock Paper Scissors until either the
  // player or the computer has won five times.
  // After each 'round', display some text in the console indicating who played
  // what, who won, and what the current scoreboard looks like.
  // For example,
  //  console.log('Player chose ' + playerMove + ' while Computer chose ' + computerMove);
  //  console.log('The score is currently ' + playerWins + ' to ' + computerWins + '\n');
  /* YOUR CODE HERE */
	return [playerWins, computerWins];
}

<commit_msg>checked my code and everything tested<commit_after>////////////////////////////////////////////////
/*   Provided Code - Please Don't Edit   */
////////////////////////////////////////////////
'use strict';

function getInput() {
    console.log("Please choose either 'rock', 'paper', or 'scissors'.")
    return prompt();
}
function randomPlay() {
    var randomNumber = Math.random();
    if (randomNumber < 0.33) {
        return "rock";
    } else if (randomNumber < 0.66) {
        return "paper";
    } else {
        return "scissors";
    }
}
////////////////////////////////////////////////
/*           Write Your Code Below            */
////////////////////////////////////////////////

function getPlayerMove() {
	var move = null;
	if(move === null){
    	var i = 0
    	while(i < 5){
        	move = getInput();
        	if(move == "paper"){
            	console.log("player chose "+move);
        		i+=5
        	}else if(move == "rock"){
        	    console.log("player chose "+move);
    	    	i+=5
	        }else if(move == "scissors"){
            	console.log("player chose "+move);
        		i+=5
    	    }else{
        		console.log(move+" is not a valid input");
        	}
    	}
	}
    return move;
}

function getComputerMove() {
    // Write an expression that operates on a variable called `move`
    var computerMove = null;
    // If a `move` has a value, your expression should evaluate to that value.
	if(computerMove === null){
		computerMove = randomPlay();
	}
	// However, if `move` is not specified / is null, your expression should equal `randomPlay()`.
    console.log("computer choses "+computerMove);
    return computerMove;
}

function getWinner(playerMove,computerMove) {
    var winner;
    // Write code that will set winner to either 'player', 'computer', or 'tie' based on the values of playerMove and computerMove.
    if (playerMove == "rock" && computerMove == "paper"){
    	winner = "computer";
    }else if (playerMove == "rock" && computerMove == "scissors"){
    	winner = "player";
    }else if (playerMove == computerMove){
    	winner = "tie";
    }else if (playerMove == "paper" && computerMove == "scissors"){
    	winner = "computer";
    }else if (playerMove == "paper" && computerMove == "rock"){
    	winner = "player";
    }else if (playerMove == "scissors" && computerMove == "rock"){
    	winner = "computer";
    }else if (playerMove == "scissors" && computerMove == "paper"){
    	winner = "player";
    }
    return winner;
}

function playToFive() {
	console.log('Let\'s play Rock Paper Scissors');
	var playerWins = 0;
	var computerWins = 0;
	var count = 0;
	while(count < 30){
		var atmwinner = getWinner(getPlayerMove(),getComputerMove())
		console.log(atmwinner+" wins this round");

		if(atmwinner === "player"){
			playerWins+=1;
		}else if(atmwinner === "computer" ){
			computerWins+=1;
		}
		console.log("player "+playerWins+"|"+"computer "+computerWins);

        if(computerWins == 5){
        	console.log("computer wins the match!");
        	count += 31;
        }else if(playerWins == 5){
        	console.log("player wins the match!");
        	count += 31;
        }
	}

	return [playerWins, computerWins];
}

<|endoftext|>


<commit_before>/* global module */
module.exports = {
	root: true,

	// Based on the recommended rules
	extends: "eslint:recommended",

	// Default environments
	env: {
		es6: false,
		browser: true,
		jquery: true
	},

	// Globals
	globals: {
		"jasmineTree": false
	},

	parserOptions: {
		ecmaFeatures: {
			// Enable let and const
			blockBindings: true
		}
	},

	plugins: ['ie11'],

	rules: {
		"camelcase": ["error"],
		"eqeqeq": ["error"],

		"indent": [
			"error",
			"tab",
			{"SwitchCase": 1}
		],

		"new-cap": ["warn"],

		"no-array-constructor": ["error"],
		"no-bitwise": ["error"],
		"no-console": ["warn"],
		"no-caller": ["error"],
		"no-extend-native": ["error"],
		"no-implicit-globals": ["error"],
		"no-multi-assign": ["error"],
		"no-new-func": ["error"],
		"no-new-object": ["error"],
		"no-new-wrappers": ["error"],
		"no-param-reassign": ["warn"],
		"no-proto": ["error"],
		"no-return-assign": ["error", "always"],
		"no-sequences": ["error"],
		"no-shadow": ["warn"],
		"no-ternary": ["warn"],
		"no-undef": ["error"],
		"no-underscore-dangle": ["error"],
		"no-unused-vars": ["error", {"vars": "all", "args": "none", "ignoreRestSiblings": false}],
		"no-void": ["error"],
		"no-with": ["error"],

		"quotes": [
			"error",
			"double"
		],

		"semi": ["error"],

		// Strict at function level (at least)
		"strict": [
			"error",
			"function"
		],

		// New features, we se "const" always if not possible use "let"
		"prefer-const": ["warn"],

		// JSDoc
		"require-jsdoc": ["warn"],
		"valid-jsdoc": [
			"warn",
			{
				prefer: {
					// Use the right string instead of the left one
					"returns": "return",
					"arg": "param",
					"argument": "param",
					"class": "constructor",
					"virtual": "abstract"
				},
				preferType: {
					// Use the right string instead of the left one
					'object': 'Object',
					'boolean': 'Boolean',
					'number': 'Number',
					'string': 'String',
					'array': 'Array'
				},

				// If and only if the function or method has a return statement (this option value does apply to constructors)
				requireReturn: false,
				requireReturnType: true,
				requireParamDescription: false,
				requireReturnDescription: false
			}
		],

		// IE11 specific rules
		'ie11/no-for-in-const': ['error'], // Error in IE11
		'ie11/no-weak-collections': ['error'], // Error in IE11
		'ie11/no-collection-args': ['error']
	}
};<commit_msg>Updated ESLint config<commit_after>/* global module */
module.exports = {
	root: true,

	// Based on the recommended rules
	extends: "eslint:recommended",

	// Default environments
	env: {
		es6: false,
		browser: true,
		jquery: true
	},

	// Globals
	globals: {
		"jasmineTree": false
	},

	parserOptions: {
		ecmaFeatures: {
			// Enable let and const
			blockBindings: true
		}
	},

	plugins: ['ie11'],

	rules: {
		"camelcase": ["error"],
		"eqeqeq": ["error"],

		"indent": [
			"error",
			"tab",
			{"SwitchCase": 1}
		],

		"new-cap": ["warn"],

		"no-array-constructor": ["error"],
		"no-bitwise": ["error"],
		"no-console": ["warn"],
		"no-caller": ["error"],
		"no-extend-native": ["error"],
		"no-implicit-globals": ["error"],
		"no-multi-assign": ["error"],
		"no-new-func": ["error"],
		"no-new-object": ["error"],
		"no-new-wrappers": ["error"],
		"no-proto": ["error"],
		"no-return-assign": ["error", "always"],
		"no-sequences": ["error"],
		"no-shadow": ["warn"],
		"no-ternary": ["warn"],
		"no-undef": ["error"],
		"no-underscore-dangle": ["error"],
		"no-unused-vars": ["error", {"vars": "all", "args": "none", "ignoreRestSiblings": false}],
		"no-void": ["error"],
		"no-with": ["error"],

		"quotes": [
			"error",
			"double"
		],

		"semi": ["error"],

		// Strict at function level (at least)
		"strict": [
			"error",
			"function"
		],

		// New features, we se "const" always if not possible use "let"
		"prefer-const": ["warn"],

		// JSDoc
		"require-jsdoc": ["warn"],
		"valid-jsdoc": [
			"warn",
			{
				prefer: {
					// Use the right string instead of the left one
					"returns": "return",
					"arg": "param",
					"argument": "param",
					"class": "constructor",
					"virtual": "abstract"
				},
				preferType: {
					// Use the right string instead of the left one
					'object': 'Object',
					'boolean': 'Boolean',
					'number': 'Number',
					'string': 'String',
					'array': 'Array'
				},

				// If and only if the function or method has a return statement (this option value does apply to constructors)
				requireReturn: false,
				requireReturnType: true,
				requireParamDescription: false,
				requireReturnDescription: false
			}
		],

		// IE11 specific rules
		'ie11/no-for-in-const': ['error'], // Error in IE11
		'ie11/no-weak-collections': ['error'], // Error in IE11
		'ie11/no-collection-args': ['error']
	}
};<|endoftext|>


<commit_before>module.exports = {
  parser: 'babel-eslint',
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    }
  },
  extends: [
    'eslint:recommended',
    'airbnb',
    'plugin:react/recommended'
  ],
  plugins: [
    'react'
  ],
  env: {
    browser: true,
    node: true,
    es6: true
  },
  globals: {
    __: true,
    axios: true,
    __I18N_LANG__: true
  },
  rules: {
    'max-len': [1, 120],
    'no-console': 0,
    'camelcase': 1,
    'quotes': [1, 'single'],
    'no-unused-vars': 1,
    'arrow-body-style': [1, 'as-needed'],
    'react/prop-types': 0,
    'react/prefer-stateless-function': 1,
    'react/sort-comp': 1,
    'react/jsx-boolean-value': 0,
    'import/no-unresolved': 0,
    'newline-per-chained-call': 0,
    'jsx-quotes': [1, 'prefer-single'],
    'one-var': 0,
    'comma-dangle': 0,
    'consistent-return': 1,
    'spaced-comment': 1,
    'no-underscore-dangle': 1,
    'no-param-reassign': 1,
    'no-sequences': 0,
    'no-use-before-define': 1,
    'no-unused-expressions': 0,
    'no-useless-constructor': 1,
    'one-var-declaration-per-line': 0
  }
};
<commit_msg>eslint<commit_after>module.exports = {
  parser: 'babel-eslint',
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    }
  },
  extends: [
    'eslint:recommended',
    'airbnb',
    'plugin:react/recommended'
  ],
  plugins: [
    'react'
  ],
  env: {
    browser: true,
    node: true,
    es6: true
  },
  globals: {
    __: true,
    axios: true,
    __I18N_LANG__: true
  },
  rules: {
    'max-len': [1, 120],
    'no-console': 0,
    'camelcase': 1,
    'quotes': [1, 'single'],
    'no-unused-vars': 1,
    'no-empty-function': 1,
    'arrow-body-style': [1, 'as-needed'],
    'react/prop-types': 0,
    'react/prefer-stateless-function': 1,
    'react/sort-comp': 1,
    'react/jsx-boolean-value': 0,
    'import/no-unresolved': 0,
    'newline-per-chained-call': 0,
    'jsx-quotes': [1, 'prefer-single'],
    'one-var': 0,
    'comma-dangle': 0,
    'consistent-return': 1,
    'spaced-comment': 1,
    'no-underscore-dangle': 1,
    'no-param-reassign': 1,
    'no-sequences': 0,
    'no-use-before-define': 1,
    'no-unused-expressions': 0,
    'no-useless-constructor': 1,
    'one-var-declaration-per-line': 0
  }
};
<|endoftext|>


<commit_before>////////////////////////////////////////////////
/*   Provided Code - Please Don't Edit   */
////////////////////////////////////////////////
'use strict';

function getInput() {
    console.log("Please choose either 'rock', 'paper', or 'scissors'.")
    return prompt();
}
function randomPlay() {
    var randomNumber = Math.random();
    if (randomNumber < 0.33) {
        return "rock";
    } else if (randomNumber < 0.66) {
        return "paper";
    } else {
        return "scissors";
    }
}
////////////////////////////////////////////////
/*           Write Your Code Below            */
////////////////////////////////////////////////

function getPlayerMove(move) {
    // Write an expression that operates on a variable called `move`
    // If a `move` has a value, your expression should evaluate to that value.
    // However, if `move` is not specified / is null, your expression should equal `getInput()`.
    return move || getInput();
}

function getComputerMove(move) {
    // Write an expression that operates on a variable called `move`
    // If a `move` has a value, your expression should evaluate to that value.
    // However, if `move` is not specified / is null, your expression should equal `randomPlay()`.
    return move || randomPlay();
}

function getWinner(playerMove,computerMove) {
    var winner;
    // Write code that will set winner to either 'player', 'computer', or 'tie' based on the values of playerMove and computerMove.
    // Assume that the only values playerMove and computerMove can have are 'rock', 'paper', and 'scissors'.
    // The rules of the game are that 'rock' beats 'scissors', 'scissors' beats 'paper', and 'paper' beats 'rock'.
     if (playerMove === 'rock' && computerMove === 'scissors'){
        winner = 'player';
    } else if (playerMove === 'scissors' && computerMove === 'paper') {
        winner = 'player';
    } else if (playerMove === 'paper' && computerMove === 'rock') {
        winner = 'player';
    } else if (computerMove === 'rock' && playerMove === 'scissors') {
        winner = 'computer';
    } else if (computerMove === 'scissors' && playerMove === 'paper') {
        winner = 'computer';
    } else if (computerMove === 'paper' && playerMove === 'rock') {
        winner = 'computer';
    } else {
        winner = 'tie'
    }
    return winner;
}

function playToFive() {
    console.log("Let's play Rock, Paper, Scissors");
    var playerWins = 0;
    var computerWins = 0;
    // Write code that plays 'Rock, Paper, Scissors' until either the player or the computer has won five times.
    /* YOUR CODE HERE */
    return [playerWins, computerWins];
}

<commit_msg>Unit 5 HW - Added to playToFive() function<commit_after>////////////////////////////////////////////////
/*   Provided Code - Please Don't Edit   */
////////////////////////////////////////////////
'use strict';

function getInput() {
    console.log("Please choose either 'rock', 'paper', or 'scissors'.")
    return prompt();
}
function randomPlay() {
    var randomNumber = Math.random();
    if (randomNumber < 0.33) {
        return "rock";
    } else if (randomNumber < 0.66) {
        return "paper";
    } else {
        return "scissors";
    }
}
////////////////////////////////////////////////
/*           Write Your Code Below            */
////////////////////////////////////////////////

function getPlayerMove(move) {
    // Write an expression that operates on a variable called `move`
    // If a `move` has a value, your expression should evaluate to that value.
    // However, if `move` is not specified / is null, your expression should equal `getInput()`.
    return move || getInput();
}

function getComputerMove(move) {
    // Write an expression that operates on a variable called `move`
    // If a `move` has a value, your expression should evaluate to that value.
    // However, if `move` is not specified / is null, your expression should equal `randomPlay()`.
    return move || randomPlay();
}

function getWinner(playerMove,computerMove) {
    var winner;
    // Write code that will set winner to either 'player', 'computer', or 'tie' based on the values of playerMove and computerMove.
    // Assume that the only values playerMove and computerMove can have are 'rock', 'paper', and 'scissors'.
    // The rules of the game are that 'rock' beats 'scissors', 'scissors' beats 'paper', and 'paper' beats 'rock'.
     if (playerMove === 'rock' && computerMove === 'scissors'){
        winner = 'player';
    } else if (playerMove === 'scissors' && computerMove === 'paper') {
        winner = 'player';
    } else if (playerMove === 'paper' && computerMove === 'rock') {
        winner = 'player';
    } else if (computerMove === 'rock' && playerMove === 'scissors') {
        winner = 'computer';
    } else if (computerMove === 'scissors' && playerMove === 'paper') {
        winner = 'computer';
    } else if (computerMove === 'paper' && playerMove === 'rock') {
        winner = 'computer';
    } else {
        winner = 'tie';
    }
    return winner;
}

function playToFive() {
    console.log("Let's play Rock, Paper, Scissors");
    var playerWins = 0;
    var computerWins = 0;
    var playerMove = getPlayerMove();
    var computerMove = getComputerMove();
    var winner = getWinner(playerMove,computerMove);
    // Write code that plays 'Rock, Paper, Scissors' until either the player or the computer has won five times.
        while (playerWins < 5 && computerWins < 5){
        if (winner === 'player'){
            playerWins += 1;
        } else if (winner === 'computer'){
            computerWins += 1;
        } else {
            playerWins += 0;
            computerWins += 0;
        }
    console.log('Player chose ' + playerMove + ' while Computer chose ' + computerMove);
    console.log('The score is currently ' + playerWins + ' to ' + computerWins + '\n')

    }
    return [playerWins, computerWins];
}

<|endoftext|>


<commit_before>/*
 * Copyright (c) 2014-2021 Bjoern Kimminich.
 * SPDX-License-Identifier: MIT
 */

module.exports = {
  extends: 'standard',
  env: {
    browser: true,
    jasmine: true,
    mocha: true,
    protractor: true
  },
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly'
  },
  parserOptions: {
    ecmaVersion: 2018
  },
  ignorePatterns: [
    'app/private/**',
    'vagrant/**',
    'frontend/**'
  ]
}
<commit_msg>Ignore /dist from eslintrc<commit_after>/*
 * Copyright (c) 2014-2021 Bjoern Kimminich.
 * SPDX-License-Identifier: MIT
 */

module.exports = {
  extends: 'standard',
  env: {
    browser: true,
    jasmine: true,
    mocha: true,
    protractor: true
  },
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly'
  },
  parserOptions: {
    ecmaVersion: 2018
  },
  ignorePatterns: [
    'app/private/**',
    'vagrant/**',
    'frontend/**',
    'dist/**'
  ]
}
<|endoftext|>


<commit_before>module.exports = {
  "extends": "airbnb",
  "plugins": [
      "react"
  ],
  "parserOptions": {
   "ecmaVersion": 6,
   "sourceType": "module",
   "ecmaFeatures": {
     "jsx": true,
     "experimentalObjectRestSpread": true
   }
 },
 "env": {
   "browser": true
 },
// See ESLint Rules: http://eslint.org/docs/rules/
"rules": {
  "prefer-const": "off",
  "semi": ["error", "always"],
  "comma-dangle": ["off", "always-multiline"],
  "arrow-body-style": ["error", "as-needed"],
  "no-unused-vars": "warn",
  "no-redeclare": "error",
  "no-console": "warn",
  "react/prop-types": "error",
  "react/no-multi-comp": "error",
  "react/jsx-closing-bracket-location": "warn",
  "no-unused-vars": "warn",
  "no-mixed-operators": ["error", {"allowSamePrecedence": true}],
  "import/no-extraneous-dependencies": ["error", {"devDependencies": true, "optionalDependencies": false, "peerDependencies": false}]
}
};
<commit_msg>work around some ESlint incompatibility<commit_after>module.exports = {
  "extends": "airbnb",
  "plugins": [
      "react"
  ],
  "parserOptions": {
   "ecmaVersion": 6,
   "sourceType": "module",
   "ecmaFeatures": {
     "jsx": true,
     "experimentalObjectRestSpread": true
   }
 },
 "env": {
   "browser": true
 },
// See ESLint Rules: http://eslint.org/docs/rules/
"rules": {
  "prefer-const": "off",
  "semi": ["error", "always"],
  "comma-dangle": ["off", "always-multiline"],
  "arrow-body-style": ["error", "as-needed"],
  "no-unused-vars": "warn",
  "no-redeclare": "error",
  "no-console": "warn",
  "react/prop-types": "error",
  "react/no-multi-comp": "error",
  "react/jsx-closing-bracket-location": "warn",
  "no-unused-vars": "warn",
  "no-mixed-operators": ["error", {"allowSamePrecedence": true}],
  "import/no-extraneous-dependencies": ["error", {"devDependencies": true, "optionalDependencies": false, "peerDependencies": false}],
  "jsx-a11y/href-no-hash": "off", // Added to work around an incompatible peer dependency. see https://github.com/facebookincubator/create-react-app/issues/2631#issuecomment-317207675
  "jsx-a11y/anchor-is-valid": ["warn", { "aspects": ["invalidHref"] }]
}
};
<|endoftext|>


<commit_before>module.exports = {
    root: true,

    env: {
        'browser': true,
        'es6': true
    },

    parserOptions: {
        ecmaFeatures: {
            'jsx': true
        },
        ecmaVersion: 6,
        sourceType: 'module'
    },

    settings: {
        react: {
            version: 'detect'
        }
    },

    extends: [
        'eslint:recommended',
        'plugin:react/recommended'
    ],

    rules: {
        'quotes': ['error', 'single'],
        'comma-dangle': ['error', 'never']
    },

    overrides: [
        {
            files: ['babel.config.js', 'postcss.config.js'],
            env: {
                node: true
            }
        }
    ]
};
<commit_msg>ecma version 6 -> 9<commit_after>module.exports = {
    root: true,

    env: {
        'browser': true,
        'es6': true
    },

    parserOptions: {
        ecmaFeatures: {
            'jsx': true
        },
        ecmaVersion: 9,
        sourceType: 'module'
    },

    settings: {
        react: {
            version: 'detect'
        }
    },

    extends: [
        'eslint:recommended',
        'plugin:react/recommended'
    ],

    rules: {
        'quotes': ['error', 'single'],
        'comma-dangle': ['error', 'never']
    },

    overrides: [
        {
            files: ['babel.config.js', 'postcss.config.js'],
            env: {
                node: true
            }
        }
    ]
};
<|endoftext|>


<commit_before>module.exports = {
  "env": {
    "browser": true,
    "es6": true,
    "node": true
  },
  "extends": ["eslint:recommended", "plugin:react/recommended"],
  "parserOptions": {
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true,
      "jsx": true
    },
    "sourceType": "module"
  },
  "plugins": [
    "react"
  ],
  "rules": {
    "indent": [
      "error",
      2
    ],
    "linebreak-style": [
      "error",
      "unix"
    ],
    "quotes": [
      "error",
      "double"
    ],
    "semi": [
      "error",
      "never"
    ]
  }
}
<commit_msg>Whitelist describe and it in eslint config<commit_after>module.exports = {
  "env": {
    "browser": true,
    "es6": true,
    "node": true
  },
  "globals": {
    "describe": false,
    "it": false
  },
  "extends": ["eslint:recommended", "plugin:react/recommended"],
  "parserOptions": {
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true,
      "jsx": true
    },
    "sourceType": "module"
  },
  "plugins": [
    "react"
  ],
  "rules": {
    "indent": [
      "error",
      2
    ],
    "linebreak-style": [
      "error",
      "unix"
    ],
    "quotes": [
      "error",
      "double"
    ],
    "semi": [
      "error",
      "never"
    ]
  }
}
<|endoftext|>


<commit_before>module.exports = {
  "env": {
    "browser": true,
    "es6": true
  },
  "parser": "babel-eslint",
  "extends": "eslint:recommended",
  "parserOptions": {
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true,
      "jsx": true
    },
    "sourceType": "module"
  },
  "plugins": [
    "react"
  ],
  "rules": {
    "comma-dangle": ["error", "always-multiline"],
    "no-console":  "error",
    "no-debugger": "error",
    "indent": [
      "error",
      2
    ],
    "no-unused-vars": [2, {'varsIgnorePattern': '_+'}],
    "consistent-return": ["error", { "treatUndefinedAsUnspecified": true }],
    "object-curly-spacing": ["error", "always"],
    "quotes": ["error", "double"],
    "no-multiple-empty-lines": [2, { "max": 2, "maxEOF": 0, "maxEOF": 0 }],
    "no-multi-spaces": [2, {
      "exceptions": {
        "Identifier": true,
        "ClassProperty": true,
        "ImportDeclaration": true,
        "VariableDeclarator": true,
        "AssignmentExpression": true,
        "ReturnStatement": true,
        "BlockStatement": true,
        "IfStatement": true,
      }
    }],
    "linebreak-style": [
      "error",
      "unix"
    ],
    "quotes": [
      "error",
      "single"
    ],
    "semi": [
      "error",
      "always"
    ],
    "react/prefer-stateless-function": [2, {
      "ignorePureComponents": true
    }],
    "react/prop-types": 2,
    "react/jsx-uses-vars": [2],
    "react/jsx-indent": [2, 2],
    "react/jsx-indent-props": [2, 2],
    "key-spacing": [2, {
      "singleLine": {
        "beforeColon": false,
        "afterColon":  true
      },
      "multiLine": {
        "beforeColon": false,
        "afterColon":  true,
        "mode": "minimum"
      }
    }],
  }
};
<commit_msg>allow JSX to have extra spacing for alignment<commit_after>module.exports = {
  "env": {
    "browser": true,
    "es6": true
  },
  "parser": "babel-eslint",
  "extends": "eslint:recommended",
  "parserOptions": {
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true,
      "jsx": true
    },
    "sourceType": "module"
  },
  "plugins": [
    "react"
  ],
  "rules": {
    "comma-dangle": ["error", "always-multiline"],
    "no-console":  "error",
    "no-debugger": "error",
    "indent": [
      "error",
      2
    ],
    "no-unused-vars": [2, {'varsIgnorePattern': '_+'}],
    "consistent-return": ["error", { "treatUndefinedAsUnspecified": true }],
    "object-curly-spacing": ["error", "always"],
    "quotes": ["error", "double"],
    "no-multiple-empty-lines": [2, { "max": 2, "maxEOF": 0, "maxEOF": 0 }],
    "no-multi-spaces": [2, {
      "exceptions": {
        "Identifier": true,
        "ClassProperty": true,
        "ImportDeclaration": true,
        "VariableDeclarator": true,
        "AssignmentExpression": true,
        "ReturnStatement": true,
        "BlockStatement": true,
        "IfStatement": true,
        "JSXAttribute": true,
        "JSXIdentifier": true,
        "JSXOpeningElement": true,
        "JSXClosingElement": true
      }
    }],
    "linebreak-style": [
      "error",
      "unix"
    ],
    "quotes": [
      "error",
      "single"
    ],
    "semi": [
      "error",
      "always"
    ],
    "react/prefer-stateless-function": [2, {
      "ignorePureComponents": true
    }],
    "react/prop-types": 2,
    "react/jsx-uses-vars": [2],
    "react/jsx-indent": [2, 2],
    "react/jsx-indent-props": [2, 2],
    "key-spacing": [2, {
      "singleLine": {
        "beforeColon": false,
        "afterColon":  true
      },
      "multiLine": {
        "beforeColon": false,
        "afterColon":  true,
        "mode": "minimum"
      }
    }],
  }
};
<|endoftext|>


<commit_before>// Edit this file to add your cloud design!

// Just write a function with a unique name like:
// function perlinNoiseCloud() {}
// and then add a line of code that "registers" it:
// register(perlinNoiseCloud, "Perlin Noise Cloud", "Daniel Shiffman");
// Here's an example below!

// Example rounded rectangle cloud
function rectangle() {
  // Draw your cloud here
  rect(50, 50, width - 100, height - 100, 50);
  // Return an internal rectangle that it is safe to draw text within. Of the
  // form [top_left, top_right, width, height]
  return [100, 100, width - 200, height - 200];
}

// Register your function with register(function, style_name, author_name)
register(rectangle, "Example", "example");

/* ------  Add your custom cloud generators below! ------ */

function ellipseCloud() {
  const circleRadius = width / 8;

  const cloudWidth = width - 100 - circleRadius;
  const cloudHeight = height - 100 - circleRadius;

  // Getting number of circles based on the width of the cloud and the cloud radius size.
  const circleAmount = cloudWidth / (circleRadius * 0.5) * 2;

  push();
  translate(width / 2, height / 2);

  // Drawing outside circles (with stroke)
  for (let i = 0; i < circleAmount; i++) {
    drawOuterCirc(i);
  }

  // Drawing inner circles which hide the inner stroke of the outer circles
  for (let i = 0; i < circleAmount; i++) {
    drawInnerCirc(i);
  }

  // Filling the middle with white for name
  noStroke();
  ellipse(0, 0, cloudWidth, cloudHeight);
  pop();

  function drawOuterCirc(num) {
    const angle = TWO_PI / circleAmount * num;

    const circleX = cloudWidth / 2 * cos(angle);
    const circleY = cloudHeight / 2 * sin(angle);

    push();
    translate(circleX, circleY);
    ellipse(0, 0, circleRadius, circleRadius);
    pop();
  }

  function drawInnerCirc(num) {
    const angle = TWO_PI / circleAmount * num;

    // * 0.99 to still show the stroke of the outer circles
    const circleX = cloudWidth / 2 * cos(angle) * 0.99;
    const circleY = cloudHeight / 2 * sin(angle) * 0.99;

    push();
    noStroke();
    translate(circleX, circleY);
    ellipse(0, 0, circleRadius, circleRadius);
    pop();
  }

  return [100, 100, width - 200, height - 200];
}

register(ellipseCloud, "Ellipse Cloud", "Raqbit");

// Unicode Cloud by Sergio Fernández
function unicodeCloud() {
  var size = floor(min(width, height * 2));
  textSize(size);

  var widthOfCloud = size;
  var heightOfCloud = widthOfCloud * 0.37;
  var textX = (width - widthOfCloud) / 2;
  var textY = height - (height - heightOfCloud) / 2;
  textAlign(LEFT, BASELINE);
  text("☁", textX, textY);

  return [
    textX + (widthOfCloud * 0.25),
    textY - (heightOfCloud * 0.7),
    widthOfCloud * 0.6,
    heightOfCloud * 0.6
  ];
}
register(unicodeCloud, "Unicode", "Sergio Fernández");

function flatBottomCloud() {
  let radius = width / 4; // I don't really know where I messed up but for now just don't change the radius...
  let cloudWidth = width - radius - 100;
  let cloudHeight = height - radius - 100;
  let circleCount  = cloudWidth / (radius*0.5);

  push();
  translate(width / 2, height / 1.75);
  ellipse(0,radius/4,cloudWidth,radius);

  for (let i = 0; i < circleCount; i++) {
    let angle = -PI / circleCount * i;

    let x = cloudWidth / 2 * cos(angle);
    let y = cloudHeight / 2 * sin(angle);

    ellipse(x, y, radius, radius);
  }

  noStroke();
  ellipse(0, -radius/5, cloudWidth+radius/2, cloudHeight+radius/10);
  pop();

  return [100, 200, width - 200, height - 400];
}

register(flatBottomCloud, "Flat Bottom", "Merijn_DH");

function kazakhCloud(radius = 200, min = 8, max = 10) {
    // This function draws a cloud which margins are inside of a "circle" with
    // a given radius. The circle is not perfect, its boundaries may vary
    // according to the value offset. Number of "peak" points is determined via
    // min and max values.
    let points = [];
    let offset = radius / 5;
    let numPoints = Math.round(Math.random()*(max-min)+min);
    for (let i = 0; i < numPoints; i++) {
        // generating "peak" points of a cloud away from the center
        let angle = (TWO_PI / numPoints) * i;
        let away;
        while (true) {
            away = Math.round(Math.random() * radius + offset);
            if (Math.abs(away - radius) <= offset) {
                break;
            }
        }
        let x = width / 2 + away * Math.cos(angle);
        let y = height / 2 - away * Math.sin(angle);
        points.push([x, y]);
    }
    noStroke();
    fill("#FFF");
    ellipse(width / 2, height / 2, 2.3*radius, 2.3*radius);
    for (let i = 0; i < points.length; i++) {
        // drawing arcs with the center inbetween every pair of points
        let center = [];
        let circleRadius;
        if (i == points.length - 1) {
            center = [(points[i][0] + points[0][0]) / 2, (points[i][1] + points[0][1]) / 2];
            circleRadius = dist(points[i][0], points[i][1], points[0][0], points[0][1]);
        } else {
            center = [(points[i][0] + points[i+1][0]) / 2, (points[i][1] + points[i+1][1]) / 2];
            circleRadius = dist(points[i][0], points[i][1], points[i+1][0], points[i+1][1]);
        }
        // finding slope and y-intercept for a line between center and point
        let mCircle = (center[1] - points[i][1]) / (center[0] - points[i][0]);
        let bCircle = center[1] - mCircle * center[0];
        let x1Origin = (0 - bCircle) / mCircle; // finding line's intercept with X-axis
        let x2Origin = center[0]; // another line is a projection of previous on X
        // finally getting the angle using found 2 lines and trigonometry
        let angle = Math.acos(dist(x2Origin, 0, x1Origin, 0) / dist(center[0], center[1], x1Origin, 0));
        // drawing arcs with right angle offset according to the placement of the center
        strokeWeight(10);
        stroke("#000");
        fill("#FFF");
        if (center[0] > width / 2 && center[1] < height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, PI+angle, angle);
        } else if (center[0] < width / 2 && center[1] < height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, PI-angle, -angle);
        } else if (center[0] < width / 2 && center[1] > height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, angle, PI+angle);
        } else if (center[0] > width / 2 && center[1] > height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, -angle, PI-angle);
        } else if (center[0] == width / 2 && center[1] < height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, PI, 0);
        } else if (center[0] == width / 2 && center[1] > height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, 0, PI);
        } else if (center[0] < width / 2 && center[1] == height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, HALF_PI, PI + HALF_PI);
        } else if (center[0] > width / 2 && center[1] == height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, PI + HALF_PI, HALF_PI);
        }
    }
    let rectSide = Math.round(Math.sqrt(2) * (radius - offset));
    return [width/2 - rectSide/2, height/2 - rectSide/2, radius+offset, radius+offset];
}

register(kazakhCloud, "Cloud from Kazakhstan", "Ilyas triple-o-zero");

function fluffyCloud(){
  var cloudradius = 0.7*(width/2);
  var angle = PI/2;
  fill(255);
  while(angle<(2.5*PI)){
    ellipse(width/2+cos(angle)*cloudradius,height/2+sin(angle)*0.5*cloudradius,(width/2-sin(angle)*cloudradius)/3);
    angle += (width/2-sin(angle)*cloudradius)/(3.9*cloudradius);
  }
  noStroke();
  ellipse(width/2-4,height/2-cloudradius*0.075,cloudradius*2.4,cloudradius*1.24);
  stroke(0);
  return [120, 180, width - 240, height - 400];
}

register(fluffyCloud, "Fluffy", "egg303");

//Draw a nice round cloud by Brandon Blaschke
function proudRoundCloud() {

  //Amount of circles in the cloud
  let circleAmou = 15;

  //Radius for surrounding clouds
  let radius = 200;

  strokeWeight(5);
  fill(255);

  //Position and set up drawing
  push();
  angleMode(DEGREES);
  translate(width / 2, height / 2);

  //Make outer edge of cloud by going in a circle around the name
  for(let i = 0; i < circleAmou; i++) {
    let angle = map(i, 0, circleAmou, 0, 360);
    let x = 400 * cos(angle);
    let y = 250 * sin(angle);
    ellipse(x,y, radius, radius);
  }

  //Fill the inside with white circles to fill it
  noStroke();
  for(let i = 0; i < circleAmou; i++) {
    let angle = map(i, 0, circleAmou, 0, 360);
    let x = 200 * cos(angle);
    let y = 200 * sin(angle);
    ellipse(x,y, radius, radius);
  }

  //Fill the middle section
  ellipse(0,0,950, 550);
  pop();

  return [100, 100, width - 200, height - 200];
}

register(proudRoundCloud, "Proud Round Cloud", "Brandon Blaschke");

// rndCloud
// Generates a cloud, by drawing ellipses of random width and height on locus of a regular ellipse
// Couldn't add a nice looking stroke to the cloud :( TODO: Add a beautiful stroke
function rndCloud(){
  // Randomess - The main variable of the algorithm.
  // Randomness is inversely proportional to time taken to generate
  // Randomness is directly proportional to beauty (depends on viewers taste)

  const randomness = random(20,100);
  const r = width/2 - randomness;
  let x, y;
  push();
    translate(width / 2, height / 2);
    angleMode(DEGREES)
    noStroke();
    for(let i = 0; i <=360;)
        {
          x = r*cos(i);
          y = 0.5* r*sin(i);
          w = random(1,2) * randomness;
          h = random(1,2) * randomness;
            ellipse(x,y,w,h); //Draw the random ellipses
            ellipse(0,0,r*2,r); //Draw main ellipse
          i += randomness / 10;
        }
  pop();
  return [100, 100, width - 200, height - 200];
}

register(rndCloud, "RNDCloud", "Haider Ali Punjabi (@haideralipunjabi)")
<commit_msg>Added change from Pull Request #11, fixed line endings<commit_after>// Edit this file to add your cloud design!

// Just write a function with a unique name like:
// function perlinNoiseCloud() {}
// and then add a line of code that "registers" it:
// register(perlinNoiseCloud, "Perlin Noise Cloud", "Daniel Shiffman");
// Here's an example below!

// Example rounded rectangle cloud
function rectangle() {
  // Draw your cloud here
  rect(50, 50, width - 100, height - 100, 50);
  // Return an internal rectangle that it is safe to draw text within. Of the
  // form [top_left, top_right, width, height]
  return [100, 100, width - 200, height - 200];
}

// Register your function with register(function, style_name, author_name)
register(rectangle, "Example", "example");

/* ------  Add your custom cloud generators below! ------ */

function ellipseCloud() {
  const circleRadius = width / 8;

  const cloudWidth = width - 100 - circleRadius;
  const cloudHeight = height - 100 - circleRadius;

  // Getting number of circles based on the width of the cloud and the cloud radius size.
  const circleAmount = cloudWidth / (circleRadius * 0.5) * 2;

  push();
  translate(width / 2, height / 2);

  // Drawing outside circles (with stroke)
  for (let i = 0; i < circleAmount; i++) {
    drawOuterCirc(i);
  }

  // Drawing inner circles which hide the inner stroke of the outer circles
  for (let i = 0; i < circleAmount; i++) {
    drawInnerCirc(i);
  }

  // Filling the middle with white for name
  noStroke();
  ellipse(0, 0, cloudWidth, cloudHeight);
  pop();

  function drawOuterCirc(num) {
    const angle = TWO_PI / circleAmount * num;

    const circleX = cloudWidth / 2 * cos(angle);
    const circleY = cloudHeight / 2 * sin(angle);

    push();
    translate(circleX, circleY);
    ellipse(0, 0, circleRadius, circleRadius);
    pop();
  }

  function drawInnerCirc(num) {
    const angle = TWO_PI / circleAmount * num;

    // * 0.99 to still show the stroke of the outer circles
    const circleX = cloudWidth / 2 * cos(angle) * 0.99;
    const circleY = cloudHeight / 2 * sin(angle) * 0.99;

    push();
    noStroke();
    translate(circleX, circleY);
    ellipse(0, 0, circleRadius, circleRadius);
    pop();
  }

  return [100, 100, width - 200, height - 200];
}

register(ellipseCloud, "Ellipse Cloud", "Raqbit");

// Unicode Cloud by Sergio Fernández
function unicodeCloud() {
  var size = floor(min(width, height * 2));
  textSize(size);

  var widthOfCloud = size;
  var heightOfCloud = widthOfCloud * 0.37;
  var textX = (width - widthOfCloud) / 2;
  var textY = height - (height - heightOfCloud) / 2;
  textAlign(LEFT, BASELINE);
  text("☁", textX, textY);

  return [
    textX + (widthOfCloud * 0.25),
    textY - (heightOfCloud * 0.7),
    widthOfCloud * 0.6,
    heightOfCloud * 0.6
  ];
}
register(unicodeCloud, "Unicode", "Sergio Fernández");

function flatBottomCloud() {
  let radius = width / 4; // I don't really know where I messed up but for now just don't change the radius...
  let cloudWidth = width - radius - 100;
  let cloudHeight = height - radius - 100;
  let circleCount  = cloudWidth / (radius*0.5);

  push();
  translate(width / 2, height / 1.75);
  ellipse(0,radius/4,cloudWidth,radius);

  for (let i = 0; i < circleCount; i++) {
    let angle = -PI / circleCount * i;

    let x = cloudWidth / 2 * cos(angle);
    let y = cloudHeight / 2 * sin(angle);

    ellipse(x, y, radius, radius);
  }

  noStroke();
  ellipse(0, -radius/5, cloudWidth+radius/2, cloudHeight+radius/10);
  pop();

  return [100, 200, width - 200, height - 400];
}

register(flatBottomCloud, "Flat Bottom", "Merijn_DH");

function kazakhCloud(radius = 200, min = 8, max = 10) {
    // This function draws a cloud which margins are inside of a "circle" with
    // a given radius. The circle is not perfect, its boundaries may vary
    // according to the value offset. Number of "peak" points is determined via
    // min and max values.
    let points = [];
    let offset = radius / 5;
    let numPoints = Math.round(Math.random()*(max-min)+min);
    for (let i = 0; i < numPoints; i++) {
        // generating "peak" points of a cloud away from the center
        let angle = (TWO_PI / numPoints) * i;
        let away;
        while (true) {
            away = Math.round(Math.random() * radius + offset);
            if (Math.abs(away - radius) <= offset) {
                break;
            }
        }
        let x = width / 2 + away * Math.cos(angle);
        let y = height / 2 - away * Math.sin(angle);
        points.push([x, y]);
    }
    noStroke();
    fill("#FFF");
    ellipse(width / 2, height / 2, 2.3*radius, 2.3*radius);
    for (let i = 0; i < points.length; i++) {
        // drawing arcs with the center inbetween every pair of points
        let center = [];
        let circleRadius;
        if (i == points.length - 1) {
            center = [(points[i][0] + points[0][0]) / 2, (points[i][1] + points[0][1]) / 2];
            circleRadius = dist(points[i][0], points[i][1], points[0][0], points[0][1]);
        } else {
            center = [(points[i][0] + points[i+1][0]) / 2, (points[i][1] + points[i+1][1]) / 2];
            circleRadius = dist(points[i][0], points[i][1], points[i+1][0], points[i+1][1]);
        }
        // finding slope and y-intercept for a line between center and point
        let mCircle = (center[1] - points[i][1]) / (center[0] - points[i][0]);
        let bCircle = center[1] - mCircle * center[0];
        let x1Origin = (0 - bCircle) / mCircle; // finding line's intercept with X-axis
        let x2Origin = center[0]; // another line is a projection of previous on X
        // finally getting the angle using found 2 lines and trigonometry
        let angle = Math.acos(dist(x2Origin, 0, x1Origin, 0) / dist(center[0], center[1], x1Origin, 0));
        // drawing arcs with right angle offset according to the placement of the center
        strokeWeight(10);
        stroke("#000");
        fill("#FFF");
        if (center[0] > width / 2 && center[1] < height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, PI+angle, angle);
        } else if (center[0] < width / 2 && center[1] < height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, PI-angle, -angle);
        } else if (center[0] < width / 2 && center[1] > height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, angle, PI+angle);
        } else if (center[0] > width / 2 && center[1] > height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, -angle, PI-angle);
        } else if (center[0] == width / 2 && center[1] < height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, PI, 0);
        } else if (center[0] == width / 2 && center[1] > height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, 0, PI);
        } else if (center[0] < width / 2 && center[1] == height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, HALF_PI, PI + HALF_PI);
        } else if (center[0] > width / 2 && center[1] == height / 2) {
            arc(center[0], center[1], circleRadius, circleRadius, PI + HALF_PI, HALF_PI);
        }
    }
    let rectSide = Math.round(Math.sqrt(2) * (radius - offset));
    return [width/2 - rectSide/2, height/2 - rectSide/2, radius+offset, radius+offset];
}

register(kazakhCloud, "Cloud from Kazakhstan", "Ilyas triple-o-zero");

function fluffyCloud(){
  var cloudradius = 0.7*(width/2);
  var angle = PI/2;
  fill(255);
  while(angle<(2.5*PI)){
    ellipse(width/2+cos(angle)*cloudradius,height/2+sin(angle)*0.5*cloudradius,(width/2-sin(angle)*cloudradius)/3);
    angle += (width/2-sin(angle)*cloudradius)/(3.9*cloudradius);
  }
  noStroke();
  ellipse(width/2-4,height/2-cloudradius*0.075,cloudradius*2.4,cloudradius*1.24);
  stroke(0);
  return [120, 180, width - 240, height - 400];
}

register(fluffyCloud, "Fluffy", "egg303");

//Draw a nice round cloud by Brandon Blaschke
function proudRoundCloud() {

  //Amount of circles in the cloud
  let circleAmou = 15;

  //Radius for surrounding clouds
  let radius = 200;

  strokeWeight(5);
  fill(255);

  //Position and set up drawing
  push();
  angleMode(DEGREES);
  translate(width / 2, height / 2);

  //Make outer edge of cloud by going in a circle around the name
  for(let i = 0; i < circleAmou; i++) {
    let angle = map(i, 0, circleAmou, 0, 360);
    let x = 400 * cos(angle);
    let y = 250 * sin(angle);
    ellipse(x,y, radius, radius);
  }

  //Fill the inside with white circles to fill it
  noStroke();
  for(let i = 0; i < circleAmou; i++) {
    let angle = map(i, 0, circleAmou, 0, 360);
    let x = 200 * cos(angle);
    let y = 200 * sin(angle);
    ellipse(x,y, radius, radius);
  }

  //Fill the middle section
  ellipse(0,0,950, 550);
  pop();

  return [100, 100, width - 200, height - 200];
}

register(proudRoundCloud, "Proud Round Cloud", "Brandon Blaschke");

// rndCloud
// Generates a cloud, by drawing ellipses of random width and height on locus of a regular ellipse
// Couldn't add a nice looking stroke to the cloud :( TODO: Add a beautiful stroke
function rndCloud(){
  // Randomess - The main variable of the algorithm.
  // Randomness is inversely proportional to time taken to generate
  // Randomness is directly proportional to beauty (depends on viewers taste)

  const randomness = random(20,100);
  const r = width/2 - randomness;
  let x, y;
  push();
    translate(width / 2, height / 2);
    angleMode(DEGREES)
    noStroke();
    for(let i = 0; i <=360;)
        {
          x = r*cos(i);
          y = 0.5* r*sin(i);
          w = random(1,2) * randomness;
          h = random(1,2) * randomness;
            ellipse(x,y,w,h); //Draw the random ellipses
            ellipse(0,0,r*2,r); //Draw main ellipse
          i += randomness / 10;
        }
  pop();
  return [100, 100, width - 200, height - 200];
}

register(rndCloud, "RNDCloud", "Haider Ali Punjabi (@haideralipunjabi)")

function cartoonCloud() {
  //Inspired by the cloud drawing from Processing Day organizer Taeyoon Choi
  function getRandMiniA() {
    return random(0, PI/24);
  }
  let radius = height/2.4;
  let angles = [0];
  angleMode(RADIANS);

  push();
  translate(width/2, height/2);

  //Fills the array with random angles that progressivly get bigger up until 2*PI
  //This creates the bigger and smaller cloud blobs, making it feel more natural
  let totalA = 0;
  while (totalA < 2*PI) {
    let a = random(PI/20, PI/6);
    if (totalA + a > 2*PI) {
      a = 2*PI - totalA;
    }
    totalA += a;
    angles.push(totalA);
  }

  //We first draw the cloud using begin/endShape() so we can fill() it
  noStroke();
  fill(255);
  beginShape();
  vertex(2*radius*cos(angles[0]), 2*radius*sin(angles[0]));
  for (let i = 0; i < angles.length; i++) {
    let a = angles[i];
    let deltaA = angles[(i+1)%angles.length] - a;
    if (deltaA < 0)deltaA+=2*PI;
    bezierVertex(
      2*1.2*radius*cos(a + deltaA/3), 1.2*radius*sin(a + deltaA/3),
      2*1.2*radius*cos(a + 2*deltaA/3), 1.2*radius*sin(a + 2*deltaA/3),
      2*radius*cos(angles[(i+1)%angles.length]), radius*sin(angles[(i+1)%angles.length])
    );
  }
  endShape();

  //Now we draw the cloud 4 times, each time with a random offset
  //This gives the cloud a cartoony feeling
  stroke(0, 200);
  for (let l = 0; l < 4; l++) {
    for (let i = 0; i < angles.length; i++) {
      //Draw a bezier curve with a random stroke, a touch of alpha and some RNG
      let a = angles[i];
      let deltaA = angles[(i+1)%angles.length] - a;
      if (deltaA < 0){deltaA+=2*PI;}
      strokeWeight(random(1,4));
      bezier(
        2*radius*cos(a), radius*sin(a),
        2*1.2*radius*cos(a + deltaA/3- getRandMiniA()), 1.2*radius*sin(a + deltaA/3- getRandMiniA()),
        2*1.2*radius*cos(a + 2*deltaA/3+ getRandMiniA()), 1.2*radius*sin(a + 2*deltaA/3+ getRandMiniA()),
        2*radius*cos(angles[(i+1)%angles.length]), radius*sin(angles[(i+1)%angles.length])
      );
    }
  }
  pop();
  return [width/2 - 2*radius/1.4, height/2 - radius / 1.4, 4 * radius / 1.4, 2 * radius / 1.4];
}

register(cartoonCloud, "Cartoon cloud", "@JeBoyJurriaan");
<|endoftext|>


<commit_before>module.exports = {
	"root": true,
	"plugins": [
		"prettier",
		"node"
	],
	"extends": ["eslint:recommended", "plugin:node/recommended"],
	"env": {
		"node": true,
		"es6": true,
	},
	"parserOptions": { "ecmaVersion": 2017 },
	"rules": {
		"prettier/prettier": "error",
		"no-undef": "error",
		"no-extra-semi": "error",
		"semi": "error",
		"no-template-curly-in-string": "error",
		"no-caller": "error",
		"yoda": "error",
		"eqeqeq": "error",
		"global-require": "off",
		"brace-style": "error",
		"eol-last": "error",
		"no-extra-bind": "warn",
		"no-process-exit": "warn",
		"no-use-before-define": "off",
		"no-unused-vars": ["error", { "args": "none" }],
		"no-unsafe-negation": "error",
		"no-loop-func": "warn",
		"indent": "off",
		"no-console": "off",
		"valid-jsdoc": "error",
		"node/no-unsupported-features": "error",
		"node/no-deprecated-api": "error",
		"node/no-missing-import": "error",
		"node/no-missing-require": [
			"error",
			{
				"allowModules": [
					"webpack"
				]
			}
		],
		"node/no-unpublished-bin": "error",
		"node/no-unpublished-require": "error",
		"node/process-exit-as-throw": "error"
	}
};
<commit_msg>Ensure runtime code is written in ES5<commit_after>module.exports = {
	root: true,
	plugins: ["prettier", "node"],
	extends: ["eslint:recommended", "plugin:node/recommended"],
	env: {
		node: true,
		es6: true
	},
	parserOptions: {
		ecmaVersion: 2017
	},
	rules: {
		"prettier/prettier": "error",
		"no-undef": "error",
		"no-extra-semi": "error",
		"semi": "error",
		"no-template-curly-in-string": "error",
		"no-caller": "error",
		"yoda": "error",
		"eqeqeq": "error",
		"global-require": "off",
		"brace-style": "error",
		"eol-last": "error",
		"no-extra-bind": "warn",
		"no-process-exit": "warn",
		"no-use-before-define": "off",
		"no-unused-vars": ["error", { args: "none" }],
		"no-unsafe-negation": "error",
		"no-loop-func": "warn",
		"indent": "off",
		"no-console": "off",
		"valid-jsdoc": "error",
		"node/no-unsupported-features": "error",
		"node/no-deprecated-api": "error",
		"node/no-missing-import": "error",
		"node/no-missing-require": ["error", { allowModules: ["webpack"] }],
		"node/no-unpublished-bin": "error",
		"node/no-unpublished-require": "error",
		"node/process-exit-as-throw": "error"
	},
	overrides: [
		{
			files: ["lib/**/*.runtime.js", "buildin/*.js", "hot/*.js"],
			env: {
				es6: false
			},
			globals: {
				Promise: false,
			},
			parserOptions: {
				ecmaVersion: 5
			}
		}
	]
};
<|endoftext|>