<commit_before>define(['sprd/entity/DesignConfiguration', "sprd/util/ProductUtil", "js/core/Bindable", 'sprd/pimp/data/PimpImageService', "sprd/entity/Size", 'sprd/data/ImageUploadService', "flow", 'sprd/util/UnitUtil', 'sprd/pimp/data/PimpDataSourceClass', 'js/data/Collection', 'sprd/pimp/model/Commission', 'sprd/pimp/model/Font', 'sprd/entity/Price', 'underscore'], function (DesignConfiguration, ProductUtil, Bindable, PimpImageService, Size, ImageUploadService, flow, UnitUtil, PimpDataSourceClass, Collection, Commission, Font, Price, _) {

    var previewSizeRatio = 3;

    return DesignConfiguration.inherit('sprd.model.SpecialTextConfiguration', {

        defaults: {
            text: null,
            font: null,
            _size: Size,
            aspectRatio: 1,
            _allowScale: true,
            loading: false,
            align: null,
            initialized: false,
            commission: null,

            renderedText: null,
            renderedFontId: null
        },

        schema: {
            text: String,
            font: Font,
            /**
             * The image width used for the pimp image
             * Needed to calculate scale while parsing
             */
            generatedWidth: Number
        },

        type: "specialText",

        inject: {
            pimpImageService: PimpImageService,
            pimpDataSource: PimpDataSourceClass,
            context: "context"
        },

        _postConstruct: function () {
            this.callBase();
            this.fetchCommissions();
        },

        ctor: function () {
            this.$designCache = {};
            this.callBase();
        },

        /***
         * saves assets asynchronously
         * @param callback
         */
        save: function (callback) {

            var self = this,
                cacheId = [self.$.text, self.$.align, self.get("font.id")].join("#");

            flow()
                .seq("design", function (cb) {

                    if (self.$designCache.hasOwnProperty(cacheId)) {
                        cb(null, self.$designCache[cacheId]);
                    } else {
                        // create a full font size image
                        self.$.pimpImageService.generateDesign({
                            text: self.$.text,
                            font: self.$.font,
                            taskId: self.$.taskId
                        }, cb);
                    }

                })
                .seq(function () {

                    var design = this.vars.design;

                    self.$designCache[cacheId] = design;
                    self.set("design", design);
                })
                .exec(callback);
        },

        _commitChangedAttributes: function ($, options) {
            this.callBase($, options);

            if (!this.$.initialized) {
                return;
            }

            if (this._hasSome($, ["pimpImageService", "text", "font"]) && !options.initial) {
                this._debounceFunctionCall(this.fetchImage, "fetchImage", 430, this, [], "DELAY");
            }

            if (this._hasSome($, ["text", "font"])) {
                this.validateChars();
            }
        },

        previewImageUrl: function () {
            return this.$.loading ? null : this._previewImageUrl;
        }.onChange('loading'),

        validateChars: function () {

            var font = this.$.font,
                text = (this.$.text || "").replace(/[\n\r\s\t]/g, "");

            if (!(font && font.$.supportedGlyphs)) {
                return;
            }

            var unsupportedGlyph = null,
                ret = {
                    invalidChar: false
                };

            for (var i = 0; i < text.length; i++) {
                var glyph = text.substr(i, 1).toLowerCase();

                if (_.indexOf(font.$.supportedGlyphs, glyph) === -1) {
                    unsupportedGlyph = glyph;
                    ret.invalidChar = true;
                    break;
                }
            }

            this._setError(ret);
        },

        fetchImage: function (callback) {
            var self = this,
                text = this.$.text,
                font = this.$.font,
                pimpImageService = this.$.pimpImageService;

            if (pimpImageService && text && font) {
                var oldSize = this.$._size;
                this.set({
                    loading: true
                });
                if (this.$lastListener) {
                    this.$lastListener.cancelled = true;
                }

                var listener = {
                    cancelled: false
                };

                this.$lastListener = listener;

                pimpImageService.generateImage({
                    text: text,
                    size: "M",
                    font: font,
                    taskId: this.$.taskId
                }, function (err, data) {
                    if (listener.cancelled) {
                        return;
                    }

                    data = data || {
                        image: {},
                        task: {}
                    };

                    if (!err) {

                        var width = (parseInt(data.image.width) || 1) * previewSizeRatio,
                            height = (parseInt(data.image.height) || 1) * previewSizeRatio,
                            design = self.$.design;

                        var pxSize = new Size({width: width, height: height, unit: "px"}),
                            scale = self.$.scale;
                        if (design) {
                            var s = (design.$.size.$.width / width) * scale.x;
                            scale = {
                                x: s,
                                y: s
                            };
                        }
                        var size = UnitUtil.convertSizeToMm(pxSize, self.$.printType.$.dpi);
                        self._previewImageUrl = data.image.src;

                        self.set({
                            generatedWidth: width,
                            taskId: data.task.id,
                            renderedText: text,
                            renderedFontId: font.$.id,
                            _size: size,
                            scale: scale,
                            design: null
                        });
                    } else {
                        self._previewImageUrl = null;
                    }

                    if (oldSize.$.width > 0 && !design) {
                        self.$.offset.set('x', self.$.offset.$.x + 0.5 * self.$.scale.x * (oldSize.$.width - self.$._size.$.width));
                    }

                    self.set('loading', false);
                    self.trigger('configurationChanged');

                    self._setError(self._validateTransform(self.$));
                    callback && callback(err);
                });
            } else {
                callback && callback();
            }
        },

        init: function (callback) {

            this.synchronizeFunctionCall(function (callback) {

                var self = this;

                flow()
                    .seq(function (cb) {
                        DesignConfiguration.prototype.init.call(self, cb);
                    })
                    .seq(function () {
                        var printType = self.$.printType,
                            design = self.$.design;

                        if (design) {

                            var split = design.$.name.split(";");
                            self.set({
                                font: self.$.pimpDataSource.createEntity(Font, split[1]),
                                align: split
                            }, {
                                silent: true
                            });

                            if (design.$.size && printType && printType.$.dpi) {
                                var dpi = printType.$.dpi;
                                self.set("_size", UnitUtil.convertSizeToMm(design.$.size, dpi), {
                                    silent: true
                                });
                            }
                        } else {
                            var fontId = self.get('font.id');
                            if (fontId) {
                                self.set({
                                    font: self.$.pimpDataSource.createEntity(Font, fontId)
                                });
                            }
                        }
                    })
                    .seq(function (cb) {
                        self.fetchImage(function () {
                            cb();
                        });
                    })
                    .exec(function (err) {
                        self.set("initialized", true);
                        callback(err);
                    });

            }, "init", callback, this);

        },

        price: function () {
            var price = this.get('printType.price'),
                _designCommission = this.get("design.price") || this.get("commission.price");

            if (price) {
                price = price.clone();
            } else {
                price = new Price();
            }

            if (_designCommission) {
                price.add(_designCommission);
            } else {
                this.fetchCommissions();
            }

            return price;
        }.onChange("_printTypePrice", "commission"),

        fetchCommissions: function () {

            var self = this,
                contextCurrency = this.get("context.currency.id");
            this.synchronizeFunctionCall(function (callback) {

                this.$.pimpDataSource.createCollection(Collection.of(Commission)).fetch(null, function (err, collection) {
                    var commission;
                    if (!err) {
                        commission = collection.find(function (commission) {
                            return commission.get("price.currency.id") === contextCurrency;
                        });
                    }

                    self.set("commission", commission);
                    self.trigger("priceChanged");

                    callback(err, commission);
                });

            }, "commissions", null, this);

        },

        height: function (scale) {
            return this.callBase(scale);
        }.onChange("_size"),

        width: function (scale) {
            return this.callBase(scale);
        }.onChange("_size"),

        size: function () {
            return this.$._size;
        }.onChange("_size"),

        getPossiblePrintTypes: function (appearance) {
            var ret = [],
                printArea = this.$.printArea;

            if (printArea && appearance) {
                ret = ProductUtil.getPossiblePrintTypesForSpecialText(printArea, appearance.$.id);
            }

            return ret;
        }.onChange("printArea"),

        getSizeForPrintType: function (printType) {
            if (printType && printType.$.dpi) {
                var dpi = printType.$.dpi;
                return UnitUtil.convertSizeToMm(this.$._size, dpi);
            }

            return Size.empty;
        },

        isAllowedOnPrintArea: function (printArea) {
            return printArea && printArea.get("restrictions.designAllowed") == true &&
                printArea.get("restrictions.textAllowed") == true;
        },

        getPossiblePrintTypesForPrintArea: function (printArea, appearanceId) {
            return ProductUtil.getPossiblePrintTypesForSpecialText(printArea, appearanceId);
        },

        minimumScale: function () {
            // TODO:
            return this.callBase();
        },
        _validatePrintTypeSize: function (printType, width, height, scale) {
            var ret = {};
            var design = this.$.design;

            if (!printType || !scale) {
                return ret;
            }

            if (design) {
                return this.callBase();
            } else {

            }

            ret.minBound = !printType.isShrinkable();
            ret.dpiBound = printType.isShrinkable() && Math.max(Math.abs(scale.x), Math.abs(scale.y)) > 1;

            return ret;

        },
        clone: function () {
            var ret = this.callBase();

            return ret;
        }
    });
})
;
<commit_msg>removed unnecessary import of ImageUploadService<commit_after>define(['sprd/entity/DesignConfiguration', "sprd/util/ProductUtil", "js/core/Bindable", 'sprd/pimp/data/PimpImageService', "sprd/entity/Size", "flow", 'sprd/util/UnitUtil', 'sprd/pimp/data/PimpDataSourceClass', 'js/data/Collection', 'sprd/pimp/model/Commission', 'sprd/pimp/model/Font', 'sprd/entity/Price', 'underscore'], function (DesignConfiguration, ProductUtil, Bindable, PimpImageService, Size, flow, UnitUtil, PimpDataSourceClass, Collection, Commission, Font, Price, _) {

    var previewSizeRatio = 3;

    return DesignConfiguration.inherit('sprd.model.SpecialTextConfiguration', {

        defaults: {
            text: null,
            font: null,
            _size: Size,
            aspectRatio: 1,
            _allowScale: true,
            loading: false,
            align: null,
            initialized: false,
            commission: null,

            renderedText: null,
            renderedFontId: null
        },

        schema: {
            text: String,
            font: Font,
            /**
             * The image width used for the pimp image
             * Needed to calculate scale while parsing
             */
            generatedWidth: Number
        },

        type: "specialText",

        inject: {
            pimpImageService: PimpImageService,
            pimpDataSource: PimpDataSourceClass,
            context: "context"
        },

        _postConstruct: function () {
            this.callBase();
            this.fetchCommissions();
        },

        ctor: function () {
            this.$designCache = {};
            this.callBase();
        },

        /***
         * saves assets asynchronously
         * @param callback
         */
        save: function (callback) {

            var self = this,
                cacheId = [self.$.text, self.$.align, self.get("font.id")].join("#");

            flow()
                .seq("design", function (cb) {

                    if (self.$designCache.hasOwnProperty(cacheId)) {
                        cb(null, self.$designCache[cacheId]);
                    } else {
                        // create a full font size image
                        self.$.pimpImageService.generateDesign({
                            text: self.$.text,
                            font: self.$.font,
                            taskId: self.$.taskId
                        }, cb);
                    }

                })
                .seq(function () {

                    var design = this.vars.design;

                    self.$designCache[cacheId] = design;
                    self.set("design", design);
                })
                .exec(callback);
        },

        _commitChangedAttributes: function ($, options) {
            this.callBase($, options);

            if (!this.$.initialized) {
                return;
            }

            if (this._hasSome($, ["pimpImageService", "text", "font"]) && !options.initial) {
                this._debounceFunctionCall(this.fetchImage, "fetchImage", 430, this, [], "DELAY");
            }

            if (this._hasSome($, ["text", "font"])) {
                this.validateChars();
            }
        },

        previewImageUrl: function () {
            return this.$.loading ? null : this._previewImageUrl;
        }.onChange('loading'),

        validateChars: function () {

            var font = this.$.font,
                text = (this.$.text || "").replace(/[\n\r\s\t]/g, "");

            if (!(font && font.$.supportedGlyphs)) {
                return;
            }

            var unsupportedGlyph = null,
                ret = {
                    invalidChar: false
                };

            for (var i = 0; i < text.length; i++) {
                var glyph = text.substr(i, 1).toLowerCase();

                if (_.indexOf(font.$.supportedGlyphs, glyph) === -1) {
                    unsupportedGlyph = glyph;
                    ret.invalidChar = true;
                    break;
                }
            }

            this._setError(ret);
        },

        fetchImage: function (callback) {
            var self = this,
                text = this.$.text,
                font = this.$.font,
                pimpImageService = this.$.pimpImageService;

            if (pimpImageService && text && font) {
                var oldSize = this.$._size;
                this.set({
                    loading: true
                });
                if (this.$lastListener) {
                    this.$lastListener.cancelled = true;
                }

                var listener = {
                    cancelled: false
                };

                this.$lastListener = listener;

                pimpImageService.generateImage({
                    text: text,
                    size: "M",
                    font: font,
                    taskId: this.$.taskId
                }, function (err, data) {
                    if (listener.cancelled) {
                        return;
                    }

                    data = data || {
                        image: {},
                        task: {}
                    };

                    if (!err) {

                        var width = (parseInt(data.image.width) || 1) * previewSizeRatio,
                            height = (parseInt(data.image.height) || 1) * previewSizeRatio,
                            design = self.$.design;

                        var pxSize = new Size({width: width, height: height, unit: "px"}),
                            scale = self.$.scale;
                        if (design) {
                            var s = (design.$.size.$.width / width) * scale.x;
                            scale = {
                                x: s,
                                y: s
                            };
                        }
                        var size = UnitUtil.convertSizeToMm(pxSize, self.$.printType.$.dpi);
                        self._previewImageUrl = data.image.src;

                        self.set({
                            generatedWidth: width,
                            taskId: data.task.id,
                            renderedText: text,
                            renderedFontId: font.$.id,
                            _size: size,
                            scale: scale,
                            design: null
                        });
                    } else {
                        self._previewImageUrl = null;
                    }

                    if (oldSize.$.width > 0 && !design) {
                        self.$.offset.set('x', self.$.offset.$.x + 0.5 * self.$.scale.x * (oldSize.$.width - self.$._size.$.width));
                    }

                    self.set('loading', false);
                    self.trigger('configurationChanged');

                    self._setError(self._validateTransform(self.$));
                    callback && callback(err);
                });
            } else {
                callback && callback();
            }
        },

        init: function (callback) {

            this.synchronizeFunctionCall(function (callback) {

                var self = this;

                flow()
                    .seq(function (cb) {
                        DesignConfiguration.prototype.init.call(self, cb);
                    })
                    .seq(function () {
                        var printType = self.$.printType,
                            design = self.$.design;

                        if (design) {

                            var split = design.$.name.split(";");
                            self.set({
                                font: self.$.pimpDataSource.createEntity(Font, split[1]),
                                align: split
                            }, {
                                silent: true
                            });

                            if (design.$.size && printType && printType.$.dpi) {
                                var dpi = printType.$.dpi;
                                self.set("_size", UnitUtil.convertSizeToMm(design.$.size, dpi), {
                                    silent: true
                                });
                            }
                        } else {
                            var fontId = self.get('font.id');
                            if (fontId) {
                                self.set({
                                    font: self.$.pimpDataSource.createEntity(Font, fontId)
                                });
                            }
                        }
                    })
                    .seq(function (cb) {
                        self.fetchImage(function () {
                            cb();
                        });
                    })
                    .exec(function (err) {
                        self.set("initialized", true);
                        callback(err);
                    });

            }, "init", callback, this);

        },

        price: function () {
            var price = this.get('printType.price'),
                _designCommission = this.get("design.price") || this.get("commission.price");

            if (price) {
                price = price.clone();
            } else {
                price = new Price();
            }

            if (_designCommission) {
                price.add(_designCommission);
            } else {
                this.fetchCommissions();
            }

            return price;
        }.onChange("_printTypePrice", "commission"),

        fetchCommissions: function () {

            var self = this,
                contextCurrency = this.get("context.currency.id");
            this.synchronizeFunctionCall(function (callback) {

                this.$.pimpDataSource.createCollection(Collection.of(Commission)).fetch(null, function (err, collection) {
                    var commission;
                    if (!err) {
                        commission = collection.find(function (commission) {
                            return commission.get("price.currency.id") === contextCurrency;
                        });
                    }

                    self.set("commission", commission);
                    self.trigger("priceChanged");

                    callback(err, commission);
                });

            }, "commissions", null, this);

        },

        height: function (scale) {
            return this.callBase(scale);
        }.onChange("_size"),

        width: function (scale) {
            return this.callBase(scale);
        }.onChange("_size"),

        size: function () {
            return this.$._size;
        }.onChange("_size"),

        getPossiblePrintTypes: function (appearance) {
            var ret = [],
                printArea = this.$.printArea;

            if (printArea && appearance) {
                ret = ProductUtil.getPossiblePrintTypesForSpecialText(printArea, appearance.$.id);
            }

            return ret;
        }.onChange("printArea"),

        getSizeForPrintType: function (printType) {
            if (printType && printType.$.dpi) {
                var dpi = printType.$.dpi;
                return UnitUtil.convertSizeToMm(this.$._size, dpi);
            }

            return Size.empty;
        },

        isAllowedOnPrintArea: function (printArea) {
            return printArea && printArea.get("restrictions.designAllowed") == true &&
                printArea.get("restrictions.textAllowed") == true;
        },

        getPossiblePrintTypesForPrintArea: function (printArea, appearanceId) {
            return ProductUtil.getPossiblePrintTypesForSpecialText(printArea, appearanceId);
        },

        minimumScale: function () {
            // TODO:
            return this.callBase();
        },
        _validatePrintTypeSize: function (printType, width, height, scale) {
            var ret = {};
            var design = this.$.design;

            if (!printType || !scale) {
                return ret;
            }

            if (design) {
                return this.callBase();
            } else {

            }

            ret.minBound = !printType.isShrinkable();
            ret.dpiBound = printType.isShrinkable() && Math.max(Math.abs(scale.x), Math.abs(scale.y)) > 1;

            return ret;

        },
        clone: function () {
            var ret = this.callBase();

            return ret;
        }
    });
})
;
<|endoftext|>


<commit_before>const userAgent = navigator.userAgent;

const checkHasExternalDisplay = () => (
  new Promise((resolve, reject) => {
    if (navigator.getVRDisplays === undefined) {
      resolve(false);
      return;
    }
    navigator.getVRDisplays().then(
      (displays) => {
        resolve(
          !!displays[0] &&
          !!displays[0].capabilities &&
          !!displays[0].capabilities.hasExternalDisplay
        );
      }
    ).catch(reject);
  })
);

const checkHasVR = () => (
  new Promise((resolve, reject) => {
    if (navigator.getVRDisplays === undefined) {
      resolve(false);
      return;
    }
    navigator.getVRDisplays().then(() => {
      resolve(true);
    })
    .catch(reject);
  })
);

const checkHas6DOF = () => (
  new Promise((resolve, reject) => {
    if (navigator.getVRDisplays === undefined) {
      resolve(false);
      return;
    }
    navigator.getVRDisplays().then(
      (displays) => {
        resolve(
          !!displays[0] &&
          !!displays[0].capabilities &&
          !!displays[0].capabilities.hasPosition &&
          !!displays[0].capabilities.hasOrientation
        );
      }
    ).catch(reject);
  })
);

const version = window.localStorage.getItem('version');

const feature = {
  isMobile: /android|ipad|iphone|iemobile/i.test(userAgent),
  isAndroid: /android/i.test(userAgent),
  isChrome: /chrome/i.test(userAgent),
  isIODaydream: version === 'io-daydream',
  isIOVive: version === 'io-vive',
  prepare: () => (
    Promise.all([
      checkHasExternalDisplay().then((hasExternalDisplay) => {
        feature.hasExternalDisplay = hasExternalDisplay;
      }),
      checkHasVR().then((hasVR) => {
        feature.hasVR = hasVR;
      }),
      checkHas6DOF().then((has6DOF) => {
        feature.has6DOF = has6DOF;
      }),
    ])
  ),
};

feature.isIO = !!feature.isIODaydream || !!feature.isIOVive;

export default feature;
<commit_msg>Resolve instead of reject on !getVRDisplays()<commit_after>const userAgent = navigator.userAgent;

const checkHasExternalDisplay = () => (
  new Promise((resolve, reject) => {
    if (navigator.getVRDisplays === undefined) {
      resolve(false);
      return;
    }
    navigator.getVRDisplays().then(
      (displays) => {
        resolve(
          !!displays[0] &&
          !!displays[0].capabilities &&
          !!displays[0].capabilities.hasExternalDisplay
        );
      }
    ).catch(reject);
  })
);

const checkHasVR = () => (
  new Promise((resolve) => {
    if (!navigator.getVRDisplays) {
      resolve(false);
      return;
    }
    navigator
      .getVRDisplays()
      .then(() => {
        resolve(true);
      })
      .catch((error) => {
        console.log(error);
        resolve(false);
      });
  })
);

const checkHas6DOF = () => (
  new Promise((resolve, reject) => {
    if (navigator.getVRDisplays === undefined) {
      resolve(false);
      return;
    }
    navigator.getVRDisplays().then(
      (displays) => {
        resolve(
          !!displays[0] &&
          !!displays[0].capabilities &&
          !!displays[0].capabilities.hasPosition &&
          !!displays[0].capabilities.hasOrientation
        );
      }
    ).catch(reject);
  })
);

const feature = {
  isMobile: /android|ipad|iphone|iemobile/i.test(userAgent),
  isAndroid: /android/i.test(userAgent),
  isChrome: /chrome/i.test(userAgent),
  stats: /fps/.test(window.location.hash),
  prepare: () => (
    Promise.all([
      checkHasExternalDisplay().then((hasExternalDisplay) => {
        feature.hasExternalDisplay = hasExternalDisplay;
      }),
      checkHasVR().then((hasVR) => {
        feature.hasVR = hasVR;
      }),
      checkHas6DOF().then((has6DOF) => {
        feature.has6DOF = has6DOF;
      }),
    ])
  ),
};

export default feature;
<|endoftext|>


<commit_before>module.exports = {
    "rules": {
        "array-bracket-spacing": [2, "never"],
        "block-spacing": [2, "always"],
        "brace-style": [2, "allman", { "allowSingleLine": true }],
        "camelcase": 0,
        "comma-spacing": [2, { "before": false, "after": true }],
        "comma-style": [2, "last"],
        "computed-property-spacing": [2, "never"],
        "consistent-this": 0,
        "eol-last": 2,
        "func-names": 1,
        "func-style": 0,
        "id-blacklist": 0,
        "id-length": 0,
        "id-match": 0,
        "indent": [2, 4, { "SwitchCase": 1 }],
        "jsx-quotes": [2, "prefer-double"],
        "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
        "keyword-spacing": [2, {
            "before": true,
            "after": true,
            "overrides": {
                "return": { "after": true },
                "throw": { "after": true },
                "case": { "after": true }
            }
        }],
        "linebreak-style": 0,
        "lines-around-comment": 0,
        "max-depth": 0,
        "max-len": 0,
        "max-nested-callbacks": 0,
        "max-params": 0,
        "max-statements": 0,
        "max-statements-per-line": 2,
        "new-cap": [2, { "newIsCap": true }],
        "new-parens": 2,
        "newline-after-var": 0,
        "newline-before-return": 0,
        "newline-per-chained-call": [2, { "ignoreChainWithDepth": 3 }],
        "no-array-constructor": 2,
        "no-bitwise": 0,
        "no-continue": 0,
        "no-inline-comments": 0,
        "no-lonely-if": 0,
        "no-mixed-spaces-and-tabs": 2,
        "no-multiple-empty-lines": [1, { "max": 2, "maxEOF": 1 }],
        "no-negated-condition": 0,
        "no-nested-ternary": 2,
        "no-new-object": 2,
        "no-plusplus": 0,
        "no-restricted-syntax": [
            2,
            "DebuggerStatement",
            "ForInStatement",
            "LabeledStatement",
            "WithStatement",
        ],
        "no-spaced-func": 2,
        "no-ternary": 0,
        "no-trailing-spaces": 2,
        "no-underscore-dangle": 0,
        "no-unneeded-ternary": 2,
        "no-whitespace-before-property": 2,
        "object-curly-spacing": [2, "always"],
        "one-var": [2, "never"],
        "one-var-declaration-per-line": [2, "always"],
        "operator-assignment": 0,
        "operator-linebreak": 0,
        "padded-blocks": [2, "never"],
        "quote-props": [2, "as-needed", { "keywords": false, "unnecessary": false, "numbers": false }],
        "quotes": [2, "double"],
        "require-jsdoc": 0,
        "semi": [2, "always"],
        "semi-spacing": [2, { "before": false, "after": true }],
        "sort-vars": 0,
        "space-before-blocks": 2,
        "space-before-function-paren": [2, { "anonymous": "always", "named": "never" }],
        "space-in-parens": [2, "never"],
        "space-infix-ops": 2,
        "space-unary-ops": 0,
        "spaced-comment": [2, "always", {
            "exceptions": ["-", "+"],
            "markers": ["=", "!"]
        }],
        "wrap-regex": 0
    }
};
<commit_msg>ignore express.Router<commit_after>module.exports = {
    "rules": {
        "array-bracket-spacing": [2, "never"],
        "block-spacing": [2, "always"],
        "brace-style": [2, "allman", { "allowSingleLine": true }],
        "camelcase": 0,
        "comma-spacing": [2, { "before": false, "after": true }],
        "comma-style": [2, "last"],
        "computed-property-spacing": [2, "never"],
        "consistent-this": 0,
        "eol-last": 2,
        "func-names": 1,
        "func-style": 0,
        "id-blacklist": 0,
        "id-length": 0,
        "id-match": 0,
        "indent": [2, 4, { "SwitchCase": 1 }],
        "jsx-quotes": [2, "prefer-double"],
        "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
        "keyword-spacing": [2, {
            "before": true,
            "after": true,
            "overrides": {
                "return": { "after": true },
                "throw": { "after": true },
                "case": { "after": true }
            }
        }],
        "linebreak-style": 0,
        "lines-around-comment": 0,
        "max-depth": 0,
        "max-len": 0,
        "max-nested-callbacks": 0,
        "max-params": 0,
        "max-statements": 0,
        "max-statements-per-line": 2,
        "new-cap": [2, {
            "newIsCap": true,
            "capIsNewExceptions": [
                "Router"
            ]
        }],
        "new-parens": 2,
        "newline-after-var": 0,
        "newline-before-return": 0,
        "newline-per-chained-call": [2, { "ignoreChainWithDepth": 3 }],
        "no-array-constructor": 2,
        "no-bitwise": 0,
        "no-continue": 0,
        "no-inline-comments": 0,
        "no-lonely-if": 0,
        "no-mixed-spaces-and-tabs": 2,
        "no-multiple-empty-lines": [1, { "max": 2, "maxEOF": 1 }],
        "no-negated-condition": 0,
        "no-nested-ternary": 2,
        "no-new-object": 2,
        "no-plusplus": 0,
        "no-restricted-syntax": [
            2,
            "DebuggerStatement",
            "ForInStatement",
            "LabeledStatement",
            "WithStatement",
        ],
        "no-spaced-func": 2,
        "no-ternary": 0,
        "no-trailing-spaces": 2,
        "no-underscore-dangle": 0,
        "no-unneeded-ternary": 2,
        "no-whitespace-before-property": 2,
        "object-curly-spacing": [2, "always"],
        "one-var": [2, "never"],
        "one-var-declaration-per-line": [2, "always"],
        "operator-assignment": 0,
        "operator-linebreak": 0,
        "padded-blocks": [2, "never"],
        "quote-props": [2, "as-needed", { "keywords": false, "unnecessary": false, "numbers": false }],
        "quotes": [2, "double"],
        "require-jsdoc": 0,
        "semi": [2, "always"],
        "semi-spacing": [2, { "before": false, "after": true }],
        "sort-vars": 0,
        "space-before-blocks": 2,
        "space-before-function-paren": [2, { "anonymous": "always", "named": "never" }],
        "space-in-parens": [2, "never"],
        "space-infix-ops": 2,
        "space-unary-ops": 0,
        "spaced-comment": [2, "always", {
            "exceptions": ["-", "+"],
            "markers": ["=", "!"]
        }],
        "wrap-regex": 0
    }
};
<|endoftext|>


<commit_before>module.exports = {
  rules: {
    // enforce consistent spacing inside array brackets
    // http://eslint.org/docs/rules/array-bracket-spacing
    'array-bracket-spacing': 'error',

    // enforce consistent spacing inside single-line blocks
    // http://eslint.org/docs/rules/block-spacing
    'block-spacing': 'error',

    // enforce consistent brace style for blocks
    // http://eslint.org/docs/rules/brace-style
    'brace-style': 'error',

    // enforce camelcase naming convention
    // http://eslint.org/docs/rules/camelcase
    'camelcase': 'error',

    // require or disallow trailing commas
    // http://eslint.org/docs/rules/comma-dangle
    'comma-dangle': 'error',

    // enforce consistent spacing before and after commas
    // http://eslint.org/docs/rules/comma-spacing
    'comma-spacing': 'error',

    // enforce consistent comma style
    // http://eslint.org/docs/rules/comma-style
    'comma-style': 'error',

    // enforce consistent spacing inside computed property brackets
    // http://eslint.org/docs/rules/computed-property-spacing
    'computed-property-spacing': 'error',

    // enforce consistent naming when capturing the current execution context
    // http://eslint.org/docs/rules/consistent-this
    'consistent-this': ['error', 'self'],

    // enforce at least one newline at the end of files
    // http://eslint.org/docs/rules/eol-last
    'eol-last': 'error',

    // require or disallow spacing between function identifiers and their invocations
    // http://eslint.org/docs/rules/func-call-spacing
    'func-call-spacing': 'error',

    // require or disallow named function expressions
    // http://eslint.org/docs/rules/func-names
    'func-names': 'warn',

    // enforce the consistent use of either function declarations or expressions
    // http://eslint.org/docs/rules/func-style
    'func-style': ['error', 'declaration', {
      'allowArrowFunctions': true
    }],

    // disallow specified identifiers
    // http://eslint.org/docs/rules/id-blacklist
    'id-blacklist': 'off',

    // enforce minimum and maximum identifier lengths
    // http://eslint.org/docs/rules/id-length
    'id-length': 'off',

    // require identifiers to match a specified regular expression
    // http://eslint.org/docs/rules/id-match
    'id-match': 'off',

    // enforce consistent indentation
    // http://eslint.org/docs/rules/indent
    'indent': ['error', 2],

    // enforce the consistent use of either double or single quotes in JSX attributes
    // http://eslint.org/docs/rules/jsx-quotes
    'jsx-quotes': 'error',

    // enforce consistent spacing between keys and values in object literal properties
    // http://eslint.org/docs/rules/key-spacing
    'key-spacing': 'error',

    // enforce consistent spacing before and after keywords
    // http://eslint.org/docs/rules/keyword-spacing
    'keyword-spacing': 'error',

    // enforce consistent linebreak style
    // http://eslint.org/docs/rules/linebreak-style
    'linebreak-style': 'error',

    // require empty lines around comments
    // http://eslint.org/docs/rules/lines-around-comment
    'lines-around-comment': 'error',

    // enforce a maximum depth that blocks can be nested
    // http://eslint.org/docs/rules/max-depth
    'max-depth': 'error',

    // enforce a maximum line length
    // http://eslint.org/docs/rules/max-len
    'max-len': ['error', 120],

    // enforce a maximum number of lines per file
    // http://eslint.org/docs/rules/max-lines
    'max-lines': ['error', 500],

    // enforce a maximum depth that callbacks can be nested
    // http://eslint.org/docs/rules/max-nested-callbacks
    'max-nested-callbacks': ['error', 4],

    // enforce a maximum number of parameters in function definitions
    // http://eslint.org/docs/rules/max-params
    'max-params': ['error', 4],

    // enforce a maximum number of statements allowed per line
    // http://eslint.org/docs/rules/max-statements-per-line
    'max-statements-per-line': 'error',

    // enforce a maximum number of statements allowed in function blocks
    // http://eslint.org/docs/rules/max-statements
    'max-statements': ['error', 10, {
      'ignoreTopLevelFunctions': true
    }],

    // enforce newlines between operands of ternary expressions
    // http://eslint.org/docs/rules/multiline-ternary
    'multiline-ternary': 'error',

    // require constructor function names to begin with a capital letter
    // http://eslint.org/docs/rules/new-cap
    'new-cap': 'error',

    // require parentheses when invoking a constructor with no arguments
    // http://eslint.org/docs/rules/new-parens
    'new-parens': 'error',

    // require or disallow an empty line after var declarations
    // http://eslint.org/docs/rules/newline-after-var
    'newline-after-var': 'error',

    // require an empty line before return statements
    // http://eslint.org/docs/rules/newline-before-return
    'newline-before-return': 'error',

    // require a newline after each call in a method chain
    // http://eslint.org/docs/rules/newline-per-chained-call
    'newline-per-chained-call': 'error',

    // disallow Array constructors
    // http://eslint.org/docs/rules/no-array-constructor
    'no-array-constructor': 'error',

    // disallow bitwise operators
    // http://eslint.org/docs/rules/no-bitwise
    'no-bitwise': 'error',

    // disallow continue statements
    // http://eslint.org/docs/rules/no-continue
    'no-continue': 'error',

    // disallow inline comments after code
    // http://eslint.org/docs/rules/no-inline-comments
    'no-inline-comments': 'off',

    // disallow if statements as the only statement in else blocks
    // http://eslint.org/docs/rules/no-lonely-if
    'no-lonely-if': 'error',

    // disallow mixed binary operators
    // http://eslint.org/docs/rules/no-mixed-operators
    'no-mixed-operators': 'error',

    // disallow mixed spaces and tabs for indentation
    // http://eslint.org/docs/rules/no-mixed-spaces-and-tabs
    'no-mixed-spaces-and-tabs': 'error',

    // disallow multiple empty lines
    // http://eslint.org/docs/rules/no-multiple-empty-lines
    'no-multiple-empty-lines': 'error',

    // disallow negated conditions
    // http://eslint.org/docs/rules/no-negated-condition
    'no-negated-condition': 'warn',

    // disallow nested ternary expressions
    // http://eslint.org/docs/rules/no-nested-ternary
    'no-nested-ternary': 'error',

    // disallow Object constructors
    // http://eslint.org/docs/rules/no-new-object
    'no-new-object': 'error',

    // disallow the unary operators ++ and -- except when in a for loop
    // http://eslint.org/docs/rules/no-plusplus
    'no-plusplus': ['error', {
      'allowForLoopAfterthoughts': true
    }],

    // disallow specified syntax
    // http://eslint.org/docs/rules/no-restricted-syntax
    'no-restricted-syntax': 'off',

    // disallow tabs in file
    // http://eslint.org/docs/rules/no-tabs
    'no-tabs': 'error',

    // disallow ternary operators
    // http://eslint.org/docs/rules/no-ternary
    'no-ternary': 'off',

    // disallow trailing whitespace at the end of lines
    // http://eslint.org/docs/rules/no-trailing-spaces
    'no-trailing-spaces': 'error',

    // disallow dangling underscores in identifiers
    // http://eslint.org/docs/rules/no-underscore-dangle
    'no-underscore-dangle': 'error',

    // disallow ternary operators when simpler alternatives exist
    // http://eslint.org/docs/rules/no-unneeded-ternary
    'no-unneeded-ternary': 'error',

    // disallow whitespace before properties
    // http://eslint.org/docs/rules/no-whitespace-before-property
    'no-whitespace-before-property': 'error',

    // enforce consistent line breaks inside braces
    // http://eslint.org/docs/rules/object-curly-newline
    'object-curly-newline': ['error', 'always'],

    // enforce consistent spacing inside braces
    // http://eslint.org/docs/rules/object-curly-spacing
    'object-curly-spacing': 'error',

    // enforce placing object properties on separate lines
    // http://eslint.org/docs/rules/object-property-newline
    'object-property-newline': 'error',

    // require or disallow newlines around var declarations
    // http://eslint.org/docs/rules/one-var-declaration-per-line
    'one-var-declaration-per-line': 'error',

    // enforce variables to be declared either together or separately in functions
    // http://eslint.org/docs/rules/one-var
    'one-var': ['error', {
      'uninitialized': 'always',
      'initialized': 'never'
    }],

    // require or disallow assignment operator shorthand where possible
    // http://eslint.org/docs/rules/operator-assignment
    'operator-assignment': 'error',

    // enforce consistent linebreak style for operators
    // http://eslint.org/docs/rules/operator-linebreak
    'operator-linebreak': ['error', 'after', {
      'overrides': {
        '?': 'after',
        ':': 'after'
      }
    }],

    // require or disallow padding within blocks
    // http://eslint.org/docs/rules/padded-blocks
    'padded-blocks': 'off',

    // require quotes around object literal property names
    // http://eslint.org/docs/rules/quote-props
    'quote-props': ['error', 'consistent'],

    // enforce the consistent use of single quotes
    // http://eslint.org/docs/rules/quotes
    'quotes': ['error', 'single'],

    // require JSDoc comments
    // http://eslint.org/docs/rules/require-jsdoc
    'require-jsdoc': 'off',

    // enforce consistent spacing before and after semicolons
    // http://eslint.org/docs/rules/semi-spacing
    'semi-spacing': 'error',

    // require or disallow semicolons instead of ASI
    // http://eslint.org/docs/rules/semi
    'semi': 'error',

    // requires object keys to be sorted
    // http://eslint.org/docs/rules/sort-keys
    'sort-keys': 'off',

    // require variables within the same declaration block to be sorted
    // http://eslint.org/docs/rules/sort-vars
    'sort-vars': 'off',

    // enforce consistent spacing before blocks
    // http://eslint.org/docs/rules/space-before-blocks
    'space-before-blocks': 'off',

    // enforce consistent spacing before function definition opening parenthesis
    // http://eslint.org/docs/rules/space-before-function-paren
    'space-before-function-paren': ['error', {
      'anonymous': 'always',
      'named': 'never'
    }],

    // enforce consistent spacing inside parentheses
    // http://eslint.org/docs/rules/space-in-parens
    'space-in-parens': 'error',

    // require spacing around operators
    // http://eslint.org/docs/rules/space-infix-ops
    'space-infix-ops': 'error',

    // enforce consistent spacing before or after unary operators
    // http://eslint.org/docs/rules/space-unary-ops
    'space-unary-ops': 'error',

    // enforce consistent spacing after the // or /* in a comment
    // http://eslint.org/docs/rules/spaced-comment
    'spaced-comment': 'error',

    // require or disallow Unicode byte order mark (BOM)
    // http://eslint.org/docs/rules/unicode-bom
    'unicode-bom': 'error',

    // require parenthesis around regex literals
    // http://eslint.org/docs/rules/wrap-regex
    'wrap-regex': 'error'
  }
};
<commit_msg>Fix a bug where empty objects needed new lines<commit_after>module.exports = {
  rules: {
    // enforce consistent spacing inside array brackets
    // http://eslint.org/docs/rules/array-bracket-spacing
    'array-bracket-spacing': 'error',

    // enforce consistent spacing inside single-line blocks
    // http://eslint.org/docs/rules/block-spacing
    'block-spacing': 'error',

    // enforce consistent brace style for blocks
    // http://eslint.org/docs/rules/brace-style
    'brace-style': 'error',

    // enforce camelcase naming convention
    // http://eslint.org/docs/rules/camelcase
    'camelcase': 'error',

    // require or disallow trailing commas
    // http://eslint.org/docs/rules/comma-dangle
    'comma-dangle': 'error',

    // enforce consistent spacing before and after commas
    // http://eslint.org/docs/rules/comma-spacing
    'comma-spacing': 'error',

    // enforce consistent comma style
    // http://eslint.org/docs/rules/comma-style
    'comma-style': 'error',

    // enforce consistent spacing inside computed property brackets
    // http://eslint.org/docs/rules/computed-property-spacing
    'computed-property-spacing': 'error',

    // enforce consistent naming when capturing the current execution context
    // http://eslint.org/docs/rules/consistent-this
    'consistent-this': ['error', 'self'],

    // enforce at least one newline at the end of files
    // http://eslint.org/docs/rules/eol-last
    'eol-last': 'error',

    // require or disallow spacing between function identifiers and their invocations
    // http://eslint.org/docs/rules/func-call-spacing
    'func-call-spacing': 'error',

    // require or disallow named function expressions
    // http://eslint.org/docs/rules/func-names
    'func-names': 'warn',

    // enforce the consistent use of either function declarations or expressions
    // http://eslint.org/docs/rules/func-style
    'func-style': ['error', 'declaration', {
      'allowArrowFunctions': true
    }],

    // disallow specified identifiers
    // http://eslint.org/docs/rules/id-blacklist
    'id-blacklist': 'off',

    // enforce minimum and maximum identifier lengths
    // http://eslint.org/docs/rules/id-length
    'id-length': 'off',

    // require identifiers to match a specified regular expression
    // http://eslint.org/docs/rules/id-match
    'id-match': 'off',

    // enforce consistent indentation
    // http://eslint.org/docs/rules/indent
    'indent': ['error', 2],

    // enforce the consistent use of either double or single quotes in JSX attributes
    // http://eslint.org/docs/rules/jsx-quotes
    'jsx-quotes': 'error',

    // enforce consistent spacing between keys and values in object literal properties
    // http://eslint.org/docs/rules/key-spacing
    'key-spacing': 'error',

    // enforce consistent spacing before and after keywords
    // http://eslint.org/docs/rules/keyword-spacing
    'keyword-spacing': 'error',

    // enforce consistent linebreak style
    // http://eslint.org/docs/rules/linebreak-style
    'linebreak-style': 'error',

    // require empty lines around comments
    // http://eslint.org/docs/rules/lines-around-comment
    'lines-around-comment': 'error',

    // enforce a maximum depth that blocks can be nested
    // http://eslint.org/docs/rules/max-depth
    'max-depth': 'error',

    // enforce a maximum line length
    // http://eslint.org/docs/rules/max-len
    'max-len': ['error', 120],

    // enforce a maximum number of lines per file
    // http://eslint.org/docs/rules/max-lines
    'max-lines': ['error', 500],

    // enforce a maximum depth that callbacks can be nested
    // http://eslint.org/docs/rules/max-nested-callbacks
    'max-nested-callbacks': ['error', 4],

    // enforce a maximum number of parameters in function definitions
    // http://eslint.org/docs/rules/max-params
    'max-params': ['error', 4],

    // enforce a maximum number of statements allowed per line
    // http://eslint.org/docs/rules/max-statements-per-line
    'max-statements-per-line': 'error',

    // enforce a maximum number of statements allowed in function blocks
    // http://eslint.org/docs/rules/max-statements
    'max-statements': ['error', 10, {
      'ignoreTopLevelFunctions': true
    }],

    // enforce newlines between operands of ternary expressions
    // http://eslint.org/docs/rules/multiline-ternary
    'multiline-ternary': 'error',

    // require constructor function names to begin with a capital letter
    // http://eslint.org/docs/rules/new-cap
    'new-cap': 'error',

    // require parentheses when invoking a constructor with no arguments
    // http://eslint.org/docs/rules/new-parens
    'new-parens': 'error',

    // require or disallow an empty line after var declarations
    // http://eslint.org/docs/rules/newline-after-var
    'newline-after-var': 'error',

    // require an empty line before return statements
    // http://eslint.org/docs/rules/newline-before-return
    'newline-before-return': 'error',

    // require a newline after each call in a method chain
    // http://eslint.org/docs/rules/newline-per-chained-call
    'newline-per-chained-call': 'error',

    // disallow Array constructors
    // http://eslint.org/docs/rules/no-array-constructor
    'no-array-constructor': 'error',

    // disallow bitwise operators
    // http://eslint.org/docs/rules/no-bitwise
    'no-bitwise': 'error',

    // disallow continue statements
    // http://eslint.org/docs/rules/no-continue
    'no-continue': 'error',

    // disallow inline comments after code
    // http://eslint.org/docs/rules/no-inline-comments
    'no-inline-comments': 'off',

    // disallow if statements as the only statement in else blocks
    // http://eslint.org/docs/rules/no-lonely-if
    'no-lonely-if': 'error',

    // disallow mixed binary operators
    // http://eslint.org/docs/rules/no-mixed-operators
    'no-mixed-operators': 'error',

    // disallow mixed spaces and tabs for indentation
    // http://eslint.org/docs/rules/no-mixed-spaces-and-tabs
    'no-mixed-spaces-and-tabs': 'error',

    // disallow multiple empty lines
    // http://eslint.org/docs/rules/no-multiple-empty-lines
    'no-multiple-empty-lines': 'error',

    // disallow negated conditions
    // http://eslint.org/docs/rules/no-negated-condition
    'no-negated-condition': 'warn',

    // disallow nested ternary expressions
    // http://eslint.org/docs/rules/no-nested-ternary
    'no-nested-ternary': 'error',

    // disallow Object constructors
    // http://eslint.org/docs/rules/no-new-object
    'no-new-object': 'error',

    // disallow the unary operators ++ and -- except when in a for loop
    // http://eslint.org/docs/rules/no-plusplus
    'no-plusplus': ['error', {
      'allowForLoopAfterthoughts': true
    }],

    // disallow specified syntax
    // http://eslint.org/docs/rules/no-restricted-syntax
    'no-restricted-syntax': 'off',

    // disallow tabs in file
    // http://eslint.org/docs/rules/no-tabs
    'no-tabs': 'error',

    // disallow ternary operators
    // http://eslint.org/docs/rules/no-ternary
    'no-ternary': 'off',

    // disallow trailing whitespace at the end of lines
    // http://eslint.org/docs/rules/no-trailing-spaces
    'no-trailing-spaces': 'error',

    // disallow dangling underscores in identifiers
    // http://eslint.org/docs/rules/no-underscore-dangle
    'no-underscore-dangle': 'error',

    // disallow ternary operators when simpler alternatives exist
    // http://eslint.org/docs/rules/no-unneeded-ternary
    'no-unneeded-ternary': 'error',

    // disallow whitespace before properties
    // http://eslint.org/docs/rules/no-whitespace-before-property
    'no-whitespace-before-property': 'error',

    // enforce consistent line breaks inside braces
    // http://eslint.org/docs/rules/object-curly-newline
    'object-curly-newline': 'error',

    // enforce consistent spacing inside braces
    // http://eslint.org/docs/rules/object-curly-spacing
    'object-curly-spacing': 'error',

    // enforce placing object properties on separate lines
    // http://eslint.org/docs/rules/object-property-newline
    'object-property-newline': 'error',

    // require or disallow newlines around var declarations
    // http://eslint.org/docs/rules/one-var-declaration-per-line
    'one-var-declaration-per-line': 'error',

    // enforce variables to be declared either together or separately in functions
    // http://eslint.org/docs/rules/one-var
    'one-var': ['error', {
      'uninitialized': 'always',
      'initialized': 'never'
    }],

    // require or disallow assignment operator shorthand where possible
    // http://eslint.org/docs/rules/operator-assignment
    'operator-assignment': 'error',

    // enforce consistent linebreak style for operators
    // http://eslint.org/docs/rules/operator-linebreak
    'operator-linebreak': ['error', 'after', {
      'overrides': {
        '?': 'after',
        ':': 'after'
      }
    }],

    // require or disallow padding within blocks
    // http://eslint.org/docs/rules/padded-blocks
    'padded-blocks': 'off',

    // require quotes around object literal property names
    // http://eslint.org/docs/rules/quote-props
    'quote-props': ['error', 'consistent'],

    // enforce the consistent use of single quotes
    // http://eslint.org/docs/rules/quotes
    'quotes': ['error', 'single'],

    // require JSDoc comments
    // http://eslint.org/docs/rules/require-jsdoc
    'require-jsdoc': 'off',

    // enforce consistent spacing before and after semicolons
    // http://eslint.org/docs/rules/semi-spacing
    'semi-spacing': 'error',

    // require or disallow semicolons instead of ASI
    // http://eslint.org/docs/rules/semi
    'semi': 'error',

    // requires object keys to be sorted
    // http://eslint.org/docs/rules/sort-keys
    'sort-keys': 'off',

    // require variables within the same declaration block to be sorted
    // http://eslint.org/docs/rules/sort-vars
    'sort-vars': 'off',

    // enforce consistent spacing before blocks
    // http://eslint.org/docs/rules/space-before-blocks
    'space-before-blocks': 'off',

    // enforce consistent spacing before function definition opening parenthesis
    // http://eslint.org/docs/rules/space-before-function-paren
    'space-before-function-paren': ['error', {
      'anonymous': 'always',
      'named': 'never'
    }],

    // enforce consistent spacing inside parentheses
    // http://eslint.org/docs/rules/space-in-parens
    'space-in-parens': 'error',

    // require spacing around operators
    // http://eslint.org/docs/rules/space-infix-ops
    'space-infix-ops': 'error',

    // enforce consistent spacing before or after unary operators
    // http://eslint.org/docs/rules/space-unary-ops
    'space-unary-ops': 'error',

    // enforce consistent spacing after the // or /* in a comment
    // http://eslint.org/docs/rules/spaced-comment
    'spaced-comment': 'error',

    // require or disallow Unicode byte order mark (BOM)
    // http://eslint.org/docs/rules/unicode-bom
    'unicode-bom': 'error',

    // require parenthesis around regex literals
    // http://eslint.org/docs/rules/wrap-regex
    'wrap-regex': 'error'
  }
};
<|endoftext|>


<commit_before>import uuid_v4 from 'uuid/v4'
import cookie_parser_generator from 'cookie-parser'
import session_generator from 'express-session'
import session_store_generator from 'connect-mongo'
import mongoose from 'mongoose'

const session_secret = uuid_v4()
export const cookie_parser = cookie_parser_generator(session_secret)
const session_store = session_store_generator(session_generator)
export const session = session_generator({
  name: 'sessionId',
  resave: false,
  saveUninitialized: false,
  secret: session_secret,
  store: new session_store({
    mongooseConnection: mongoose.connection,
  }),
})
<commit_msg>Issue #12: support secure cookies<commit_after>import uuid_v4 from 'uuid/v4'
import cookie_parser_generator from 'cookie-parser'
import session_generator from 'express-session'
import session_store_generator from 'connect-mongo'
import mongoose from 'mongoose'

const session_secret = uuid_v4()
export const cookie_parser = cookie_parser_generator(session_secret)
const session_store = session_store_generator(session_generator)
export const session = session_generator({
  cookie: {
    secure: true,
  },
  name: 'sessionId',
  resave: false,
  saveUninitialized: false,
  secret: session_secret,
  store: new session_store({
    mongooseConnection: mongoose.connection,
  }),
})
<|endoftext|>


<commit_before>'use strict';

var listeners = {
    // signalName: [listeners],
};

var arr = require('./arr');

var signals = {
    on: function (name, listener) {
        if (!listeners[name]) {
            listeners[name] = [listener];
            return;
        }

        listeners[name].push(listener);
    },
    off: function (name, listener) {
        if (!listeners[name]) { return; }

        var index = arr.indexOf(listeners[name], listener);

        if (index !== -1) {
            listeners[name].splice(index, 1);
        }
    },
    fire: function (name, arg) {
        var targetListeners = listeners[name];

        if (!targetListeners) { return; }

        for (var i = 0; i < targetListeners.length; i++) {
            targetListeners[i](arg, name);
        }
    },
    listeners: listeners
};

module.exports = signals;
<commit_msg>utils/signals: return false from listener to stop<commit_after>'use strict';

var listeners = {
    // signalName: [listeners],
};

var arr = require('./arr');

var signals = {
    on: function (name, listener) {
        if (!listeners[name]) {
            listeners[name] = [listener];
            return;
        }

        listeners[name].push(listener);
    },
    off: function (name, listener) {
        if (!listeners[name]) { return; }

        var index = arr.indexOf(listeners[name], listener);

        if (index !== -1) {
            listeners[name].splice(index, 1);
        }
    },
    fire: function (name, arg) {
        var targetListeners = listeners[name];

        if (!targetListeners) { return; }

        for (var i = 0; i < targetListeners.length; i++) {
            if (targetListeners[i](arg, name) === false) {
                return;
            }
        }
    },
    listeners: listeners
};

module.exports = signals;
<|endoftext|>


<commit_before>const unwidow = str => {
  // Remove extra whitespace characters before starting.
  const clean = str.trim().replace(/\s+/g, ' ')

  // We only care about strings with at least 4 words, so if we don't find at
  // least 3 spaces in the string we can just return the cleaned up string.
  const count = clean.match(/\s/g) || [].length
  if (count < 3) return clean

  // If the last word is long enough, just return the cleaned string.
  if (clean.split(' ').pop().length > 15) return clean

  // Regex matches the last instance of a whitespace character that is followed
  // by a non-whitespace character. It then replaces the former with a
  // non-breaking space character (\u00A0).
  return clean.replace(/\s+([\S]*)(\s*)$/g, '\u00A0$1$2')
}

export default unwidow
<commit_msg>:bug: only try to unwidow strings<commit_after>const unwidow = str => {
  if (typeof str !== 'string') return str

  // Remove extra whitespace characters before starting.
  const clean = str.trim().replace(/\s+/g, ' ')

  // We only care about strings with at least 4 words, so if we don't find at
  // least 3 spaces in the string we can just return the cleaned up string.
  const count = clean.match(/\s/g) || [].length
  if (count < 3) return clean

  // If the last word is long enough, just return the cleaned string.
  if (clean.split(' ').pop().length > 15) return clean

  // Regex matches the last instance of a whitespace character that is followed
  // by a non-whitespace character. It then replaces the former with a
  // non-breaking space character (\u00A0).
  return clean.replace(/\s+([\S]*)(\s*)$/g, '\u00A0$1$2')
}

export default unwidow
<|endoftext|>


<commit_before>/**
 * Copyright (c) 2013, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * https://raw.github.com/facebook/regenerator/master/LICENSE file. An
 * additional grant of patent rights can be found in the PATENTS file in
 * the same directory.
 */

(function(
  // Reliable reference to the global object (i.e. window in browsers).
  global,

  // Dummy constructor that we use as the .constructor property for
  // functions that return Generator objects.
  GeneratorFunction
) {
  var hasOwn = Object.prototype.hasOwnProperty;

  if (global.wrapGenerator) {
    return;
  }

  function wrapGenerator(innerFn, self) {
    return new Generator(innerFn, self || null);
  }

  global.wrapGenerator = wrapGenerator;
  if (typeof exports !== "undefined") {
    exports.wrapGenerator = wrapGenerator;
  }

  var GenStateSuspendedStart = "suspendedStart";
  var GenStateSuspendedYield = "suspendedYield";
  var GenStateExecuting = "executing";
  var GenStateCompleted = "completed";

  // Returning this object from the innerFn has the same effect as
  // breaking out of the dispatch switch statement.
  var ContinueSentinel = {};

  wrapGenerator.mark = function(genFun) {
    genFun.constructor = GeneratorFunction;
    return genFun;
  };

  // Ensure isGeneratorFunction works when Function#name not supported.
  if (GeneratorFunction.name !== "GeneratorFunction") {
    GeneratorFunction.name = "GeneratorFunction";
  }

  wrapGenerator.isGeneratorFunction = function(genFun) {
    var ctor = genFun && genFun.constructor;
    return ctor ? GeneratorFunction.name === ctor.name : false;
  };

  function Generator(innerFn, self) {
    var generator = this;
    var context = new Context();
    var state = GenStateSuspendedStart;

    function invoke(method, arg) {
      if (state === GenStateExecuting) {
        throw new Error("Generator is already running");
      }

      if (state === GenStateCompleted) {
        throw new Error("Generator has already finished");
      }

      while (true) {
        var delegate = context.delegate;
        if (delegate) {
          try {
            var info = delegate.generator[method](arg);

            // Delegate generator ran and handled its own exceptions so
            // regardless of what the method was, we continue as if it is
            // "next" with an undefined arg.
            method = "next";
            arg = void 0;

          } catch (uncaught) {
            context.delegate = null;

            // Like returning generator.throw(uncaught), but without the
            // overhead of an extra function call.
            method = "throw";
            arg = uncaught;

            continue;
          }

          if (info.done) {
            context[delegate.resultName] = info.value;
            context.next = delegate.nextLoc;
          } else {
            state = GenStateSuspendedYield;
            return info;
          }

          context.delegate = null;
        }

        if (method === "next") {
          if (state === GenStateSuspendedStart &&
              typeof arg !== "undefined") {
            // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
            throw new TypeError(
              "attempt to send " + JSON.stringify(arg) + " to newborn generator"
            );
          }

          if (state === GenStateSuspendedYield) {
            context.sent = arg;
          } else {
            delete context.sent;
          }

        } else if (method === "throw") {
          if (state === GenStateSuspendedStart) {
            state = GenStateCompleted;
            throw arg;
          }

          if (context.dispatchException(arg)) {
            // If the dispatched exception was caught by a catch block,
            // then let that catch block handle the exception normally.
            method = "next";
            arg = void 0;
          }
        }

        state = GenStateExecuting;

        try {
          var value = innerFn.call(self, context);

          // If an exception is thrown from innerFn, we leave state ===
          // GenStateExecuting and loop back for another invocation.
          state = context.done
            ? GenStateCompleted
            : GenStateSuspendedYield;

          var info = {
            value: value,
            done: context.done
          };

          if (value === ContinueSentinel) {
            if (context.delegate && method === "next") {
              // Deliberately forget the last sent value so that we don't
              // accidentally pass it on to the delegate.
              arg = void 0;
            }
          } else {
            return info;
          }

        } catch (thrown) {
          if (method === "next") {
            context.dispatchException(thrown);
          } else {
            arg = thrown;
          }
        }
      }
    }

    generator.next = invoke.bind(generator, "next");
    generator.throw = invoke.bind(generator, "throw");
  }

  Generator.prototype.toString = function() {
    return "[object Generator]";
  };

  function Context() {
    this.reset();
  }

  Context.prototype = {
    constructor: Context,

    reset: function() {
      this.prev = 0;
      this.next = 0;
      this.sent = void 0;
      this.tryStack = [];
      this.done = false;
      this.delegate = null;

      // Pre-initialize at least 20 temporary variables to enable hidden
      // class optimizations for simple generators.
      for (var tempIndex = 0, tempName;
           hasOwn.call(this, tempName = "t" + tempIndex) || tempIndex < 20;
           ++tempIndex) {
        this[tempName] = null;
      }
    },

    stop: function() {
      this.done = true;

      if (hasOwn.call(this, "thrown")) {
        var thrown = this.thrown;
        delete this.thrown;
        throw thrown;
      }

      return this.rval;
    },

    keys: function(object) {
      return Object.keys(object).reverse();
    },

    pushTry: function(catchLoc, finallyLoc, finallyTempVar) {
      if (finallyLoc) {
        this.tryStack.push({
          finallyLoc: finallyLoc,
          finallyTempVar: finallyTempVar
        });
      }

      if (catchLoc) {
        this.tryStack.push({
          catchLoc: catchLoc
        });
      }
    },

    popCatch: function(catchLoc) {
      var lastIndex = this.tryStack.length - 1;
      var entry = this.tryStack[lastIndex];

      if (entry && entry.catchLoc === catchLoc) {
        this.tryStack.length = lastIndex;
      }
    },

    popFinally: function(finallyLoc) {
      var lastIndex = this.tryStack.length - 1;
      var entry = this.tryStack[lastIndex];

      if (!entry || !hasOwn.call(entry, "finallyLoc")) {
        entry = this.tryStack[--lastIndex];
      }

      if (entry && entry.finallyLoc === finallyLoc) {
        this.tryStack.length = lastIndex;
      }
    },

    dispatchException: function(exception) {
      var finallyEntries = [];
      var caught = false;

      if (this.done) {
        throw exception;
      }

      // Dispatch the exception to the "end" location by default.
      this.thrown = exception;
      this.next = "end";

      for (var i = this.tryStack.length - 1; i >= 0; --i) {
        var entry = this.tryStack[i];
        if (entry.catchLoc) {
          this.next = entry.catchLoc;
          caught = true;
          break;
        } else if (entry.finallyLoc) {
          finallyEntries.push(entry);
        }
      }

      while ((entry = finallyEntries.pop())) {
        this[entry.finallyTempVar] = this.next;
        this.next = entry.finallyLoc;
      }

      return caught;
    },

    delegateYield: function(generator, resultName, nextLoc) {
      this.delegate = {
        generator: generator,
        resultName: resultName,
        nextLoc: nextLoc
      };

      return ContinueSentinel;
    }
  };
}).apply(this, Function("return [this, function GeneratorFunction(){}]")());
<commit_msg>Store reflected try statement information in the Context object.<commit_after>/**
 * Copyright (c) 2013, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * https://raw.github.com/facebook/regenerator/master/LICENSE file. An
 * additional grant of patent rights can be found in the PATENTS file in
 * the same directory.
 */

(function(
  // Reliable reference to the global object (i.e. window in browsers).
  global,

  // Dummy constructor that we use as the .constructor property for
  // functions that return Generator objects.
  GeneratorFunction
) {
  var hasOwn = Object.prototype.hasOwnProperty;

  if (global.wrapGenerator) {
    return;
  }

  function wrapGenerator(innerFn, self, tryList) {
    return new Generator(innerFn, self || null, tryList || []);
  }

  global.wrapGenerator = wrapGenerator;
  if (typeof exports !== "undefined") {
    exports.wrapGenerator = wrapGenerator;
  }

  var GenStateSuspendedStart = "suspendedStart";
  var GenStateSuspendedYield = "suspendedYield";
  var GenStateExecuting = "executing";
  var GenStateCompleted = "completed";

  // Returning this object from the innerFn has the same effect as
  // breaking out of the dispatch switch statement.
  var ContinueSentinel = {};

  wrapGenerator.mark = function(genFun) {
    genFun.constructor = GeneratorFunction;
    return genFun;
  };

  // Ensure isGeneratorFunction works when Function#name not supported.
  if (GeneratorFunction.name !== "GeneratorFunction") {
    GeneratorFunction.name = "GeneratorFunction";
  }

  wrapGenerator.isGeneratorFunction = function(genFun) {
    var ctor = genFun && genFun.constructor;
    return ctor ? GeneratorFunction.name === ctor.name : false;
  };

  function Generator(innerFn, self, tryList) {
    var generator = this;
    var context = new Context(tryList);
    var state = GenStateSuspendedStart;

    function invoke(method, arg) {
      if (state === GenStateExecuting) {
        throw new Error("Generator is already running");
      }

      if (state === GenStateCompleted) {
        throw new Error("Generator has already finished");
      }

      while (true) {
        var delegate = context.delegate;
        if (delegate) {
          try {
            var info = delegate.generator[method](arg);

            // Delegate generator ran and handled its own exceptions so
            // regardless of what the method was, we continue as if it is
            // "next" with an undefined arg.
            method = "next";
            arg = void 0;

          } catch (uncaught) {
            context.delegate = null;

            // Like returning generator.throw(uncaught), but without the
            // overhead of an extra function call.
            method = "throw";
            arg = uncaught;

            continue;
          }

          if (info.done) {
            context[delegate.resultName] = info.value;
            context.next = delegate.nextLoc;
          } else {
            state = GenStateSuspendedYield;
            return info;
          }

          context.delegate = null;
        }

        if (method === "next") {
          if (state === GenStateSuspendedStart &&
              typeof arg !== "undefined") {
            // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
            throw new TypeError(
              "attempt to send " + JSON.stringify(arg) + " to newborn generator"
            );
          }

          if (state === GenStateSuspendedYield) {
            context.sent = arg;
          } else {
            delete context.sent;
          }

        } else if (method === "throw") {
          if (state === GenStateSuspendedStart) {
            state = GenStateCompleted;
            throw arg;
          }

          if (context.dispatchException(arg)) {
            // If the dispatched exception was caught by a catch block,
            // then let that catch block handle the exception normally.
            method = "next";
            arg = void 0;
          }
        }

        state = GenStateExecuting;

        try {
          var value = innerFn.call(self, context);

          // If an exception is thrown from innerFn, we leave state ===
          // GenStateExecuting and loop back for another invocation.
          state = context.done
            ? GenStateCompleted
            : GenStateSuspendedYield;

          var info = {
            value: value,
            done: context.done
          };

          if (value === ContinueSentinel) {
            if (context.delegate && method === "next") {
              // Deliberately forget the last sent value so that we don't
              // accidentally pass it on to the delegate.
              arg = void 0;
            }
          } else {
            return info;
          }

        } catch (thrown) {
          if (method === "next") {
            context.dispatchException(thrown);
          } else {
            arg = thrown;
          }
        }
      }
    }

    generator.next = invoke.bind(generator, "next");
    generator.throw = invoke.bind(generator, "throw");
  }

  Generator.prototype.toString = function() {
    return "[object Generator]";
  };

  function tryTripleToObj(triple) {
    var entry = { tryLoc: triple[0] };

    if (triple[1]) {
      entry.catchLoc = triple[1];
    }

    var fin = triple[2];
    if (fin) {
      entry.finallyLoc = fin[0];
      entry.finallyTempVar = fin[1];
    }

    this.tryEntries.push(entry);
  }

  function Context(tryList) {
    this.reset();

    this.tryEntries = [{
      // This implicit root object (effectively a try statement without a
      // real catch or a finally block) gives us a place to store values
      // thrown when there is no enclosing try statement.
      tryLoc: 0,
      catchLoc: "end"
    }];

    tryList.forEach(tryTripleToObj, this);
  }

  Context.prototype = {
    constructor: Context,

    reset: function() {
      this.prev = 0;
      this.next = 0;
      this.sent = void 0;
      this.tryStack = [];
      this.done = false;
      this.delegate = null;

      if (this.tryEntries) {
        this.tryEntries.forEach(function(entry) {
          delete entry.thrown;
        });
      }

      // Pre-initialize at least 20 temporary variables to enable hidden
      // class optimizations for simple generators.
      for (var tempIndex = 0, tempName;
           hasOwn.call(this, tempName = "t" + tempIndex) || tempIndex < 20;
           ++tempIndex) {
        this[tempName] = null;
      }
    },

    stop: function() {
      this.done = true;

      if (hasOwn.call(this, "thrown")) {
        var thrown = this.thrown;
        delete this.thrown;
        throw thrown;
      }

      return this.rval;
    },

    keys: function(object) {
      return Object.keys(object).reverse();
    },

    pushTry: function(catchLoc, finallyLoc, finallyTempVar) {
      if (finallyLoc) {
        this.tryStack.push({
          finallyLoc: finallyLoc,
          finallyTempVar: finallyTempVar
        });
      }

      if (catchLoc) {
        this.tryStack.push({
          catchLoc: catchLoc
        });
      }
    },

    popCatch: function(catchLoc) {
      var lastIndex = this.tryStack.length - 1;
      var entry = this.tryStack[lastIndex];

      if (entry && entry.catchLoc === catchLoc) {
        this.tryStack.length = lastIndex;
      }
    },

    popFinally: function(finallyLoc) {
      var lastIndex = this.tryStack.length - 1;
      var entry = this.tryStack[lastIndex];

      if (!entry || !hasOwn.call(entry, "finallyLoc")) {
        entry = this.tryStack[--lastIndex];
      }

      if (entry && entry.finallyLoc === finallyLoc) {
        this.tryStack.length = lastIndex;
      }
    },

    dispatchException: function(exception) {
      var finallyEntries = [];
      var caught = false;

      if (this.done) {
        throw exception;
      }

      // Dispatch the exception to the "end" location by default.
      this.thrown = exception;
      this.next = "end";

      for (var i = this.tryStack.length - 1; i >= 0; --i) {
        var entry = this.tryStack[i];
        if (entry.catchLoc) {
          this.next = entry.catchLoc;
          caught = true;
          break;
        } else if (entry.finallyLoc) {
          finallyEntries.push(entry);
        }
      }

      while ((entry = finallyEntries.pop())) {
        this[entry.finallyTempVar] = this.next;
        this.next = entry.finallyLoc;
      }

      return caught;
    },

    delegateYield: function(generator, resultName, nextLoc) {
      this.delegate = {
        generator: generator,
        resultName: resultName,
        nextLoc: nextLoc
      };

      return ContinueSentinel;
    }
  };
}).apply(this, Function("return [this, function GeneratorFunction(){}]")());
<|endoftext|>