<commit_before>'use strict';

module.exports = {
    "extends"    : [],
    "plugins"    : [],
    "ignoreFiles": [],
    "rules"      : {
        "color-hex-case"                                   : [
            "lower",
            {
                "severity": "error"
            }
        ],
        "color-hex-length"                                 : [
            "short",
            {
                "severity": "error"
            }
        ],
        "color-named"                                      : [
            "always-where-possible",
            {
                "severity": "error"
            }
        ],
        "color-no-hex"                                     : [
            null,
            {
                "severity": "error"
            }
        ],
        "color-no-invalid-hex"                             : [
            true,
            {
                "severity": "error"
            }
        ],
        "font-family-name-quotes"                          : [
            "single-where-recommended",
            {
                "severity": "error"
            }
        ],
        "font-weight-notation"                             : [
            "named-where-possible",
            {
                "ignore"  : [],
                "severity": "error"
            }
        ],
        "function-blacklist"                               : [
            null,
            {
                "severity": "error"
            }
        ],
        "function-calc-no-unspaced-operator"               : [
            true,
            {
                "severity": "error"
            }
        ],
        "function-comma-newline-after"                     : [
            "always-multi-line",
            {
                "severity": "error"
            }
        ],
        "function-comma-newline-before"                    : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "function-comma-space-after"                       : [
            "always",
            {
                "severity": "error"
            }
        ],
        "function-comma-space-before"                      : [
            "never",
            {
                "severity": "error"
            }
        ],
        "function-linear-gradient-no-nonstandard-direction": [
            true,
            {
                "severity": "error"
            }
        ],
        "function-parentheses-newline-inside"              : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "function-parentheses-space-inside"                : [
            "never-single-line",
            {
                "severity": "error"
            }
        ],
        "function-url-quotes"                              : [
            "none",
            {
                "severity": "error"
            }
        ],
        "function-whitelist"                               : [
            null,
            {
                "severity": "error"
            }
        ],
        "function-whitespace-after"                        : [
            "always",
            {
                "severity": "error"
            }
        ],
        "number-leading-zero"                              : [
            "never",
            {
                "severity": "error"
            }
        ],
        "number-max-precision"                             : [
            5,
            {
                "severity": "error"
            }
        ],
        "number-no-trailing-zeros"                         : [
            true,
            {
                "severity": "error"
            }
        ],
        "number-zero-length-no-unit"                       : [
            true,
            {
                "severity": "error"
            }
        ],
        "string-no-newline"                                : [
            true,
            {
                "severity": "error"
            }
        ],
        "string-quotes"                                    : [
            "single",
            {
                "severity": "error"
            }
        ],
        "time-no-imperceptible"                            : [
            true,
            {
                "severity": "error"
            }
        ],
        "unit-blacklist"                                   : [
            null,
            {
                "severity": "error"
            }
        ],
        "unit-whitelist"                                   : [
            null,
            {
                "severity": "error"
            }
        ],
        "value-no-vendor-prefix"                           : [
            true,
            {
                "severity": "error"
            }
        ],
        "value-list-comma-newline-after"                   : [
            "always-multi-line",
            {
                "severity": "error"
            }
        ],
        "value-list-comma-newline-before"                  : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "value-list-comma-space-after"                     : [
            "always",
            {
                "severity": "error"
            }
        ],
        "value-list-comma-space-before"                    : [
            "never",
            {
                "severity": "error"
            }
        ],
        "custom-property-no-outside-root"                  : [
            true,
            {
                "severity": "error"
            }
        ],
        "custom-property-pattern"                          : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-blacklist"                               : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-no-vendor-prefix"                        : [
            true,
            {
                "severity": "error"
            }
        ],
        "property-unit-blacklist"                          : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-unit-whitelist"                          : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-value-blacklist"                         : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-value-whitelist"                         : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-whitelist"                               : [
            null,
            {
                "severity": "error"
            }
        ],
        "declaration-bang-space-after"                     : [
            "always",
            {
                "severity": "error"
            }
        ],
        "declaration-bang-space-before"                    : [
            "never",
            {
                "severity": "error"
            }
        ],
        "declaration-colon-newline-after"                  : [
            "always-multi-line",
            {
                "severity": "error"
            }
        ],
        "declaration-colon-space-after"                    : [
            "always",
            {
                "severity": "error"
            }
        ],
        "declaration-colon-space-before"                   : [
            "never",
            {
                "severity": "error"
            }
        ],
        "declaration-no-important"                         : [
            true,
            {
                "severity": "warning"
            }
        ],
        "declaration-block-no-duplicate-properties"        : [
            true,
            {
                "severity": "warning"
            }
        ],
        "declaration-block-no-shorthand-property-overrides": [
            true,
            {
                "severity": "error"
            }
        ],
        "declaration-block-properties-order"               : [
            null,
            {
                "unspecified": "bottomAlphabetical",
                "severity"   : "error"
            }
        ],
        "declaration-block-semicolon-newline-after"        : [
            "always",
            {
                "severity": "error"
            }
        ],
        "declaration-block-semicolon-newline-before"       : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "declaration-block-semicolon-space-after"          : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "declaration-block-semicolon-space-before"         : [
            "never",
            {
                "severity": "error"
            }
        ],
        "declaration-block-single-line-max-declarations"   : [
            1,
            {
                "severity": "error"
            }
        ],
        "declaration-block-trailing-semicolon"             : [
            "always",
            {
                "severity": "error"
            }
        ],
        "block-closing-brace-newline-after"                : [
            "always",
            {
                "ignoreAtRules": [],
                "severity"     : "error"
            }
        ],
        "block-closing-brace-newline-before"               : [
            "always",
            {
                "severity": "error"
            }
        ],
        "block-closing-brace-space-after"                  : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "block-closing-brace-space-before"                 : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "block-no-empty"                                   : [
            true,
            {
                "severity": "warning"
            }
        ],
        "block-no-single-line"                             : [
            true,
            {
                "severity": "error"
            }
        ],
        "block-opening-brace-newline-after"                : [
            "always",
            {
                "severity": "error"
            }
        ],
        "block-opening-brace-newline-before"               : [
            "always",
            {
                "ignoreAtRules": [],
                "severity"     : "error"
            }
        ],
        "block-opening-brace-space-after"                  : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "block-opening-brace-space-before"                 : [
            "always-single-line",
            {
                "ignoreAtRules": [],
                "severity"     : "error"
            }
        ],
        "selector-class-pattern"                           : [
            "^[a-z][-_a-z0-9]*$",
            {
                "resolveNestedSelectors": true,
                "severity"              : "error"
            }
        ],
        "selector-combinator-space-after"                  : [
            "always",
            {
                "severity": "error"
            }
        ],
        "selector-combinator-space-before"                 : [
            "always",
            {
                "severity": "error"
            }
        ],
        "selector-id-pattern"                              : [
            "^[a-z][-_a-z0-9]*$",
            {
                "severity": "error"
            }
        ],
        "selector-max-specificity"                         : [
            "0,2,0",
            {
                "severity": "warning"
            }
        ],
        "selector-no-attribute"                            : [
            null,
            {
                "severity": "error"
            }
        ],
        "selector-no-combinator"                           : [
            null,
            {
                "severity": "error"
            }
        ],
        "selector-no-id"                                   : [
            true,
            {
                "severity": "warning"
            }
        ],
        "selector-no-type"                                 : [
            true,
            {
                "ignore"  : [
                    "descendant"
                ],
                "severity": "error"
            }
        ],
        "selector-no-universal"                            : [
            true,
            {
                "severity": "warning"
            }
        ],
        "selector-no-vendor-prefix"                        : [
            true,
            {
                "severity": "error"
            }
        ],
        "selector-pseudo-element-colon-notation"           : [
            "double",
            {
                "severity": "error"
            }
        ],
        "selector-root-no-composition"                     : [
            true,
            {
                "severity": "error"
            }
        ],
        "selector-type-case"                               : [
            "lower",
            {
                "severity": "error"
            }
        ],
        "selector-list-comma-newline-after"                : [
            "always",
            {
                "severity": "error"
            }
        ],
        "selector-list-comma-newline-before"               : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "selector-list-comma-space-after"                  : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "selector-list-comma-space-before"                 : [
            "never",
            {
                "severity": "error"
            }
        ],
        "root-no-standard-properties"                      : [
            true,
            {
                "severity": "error"
            }
        ],
        "rule-nested-empty-line-before"                    : [
            "always",
            {
                "except"  : [
                    "first-nested"
                ],
                "ignore"  : [
                    "after-comment"
                ],
                "severity": "error"
            }
        ],
        "rule-non-nested-empty-line-before"                : [
            "always-multi-line",
            {
                "ignore"  : [
                    "after-comment"
                ],
                "severity": "error"
            }
        ],
        "media-feature-colon-space-after"                  : [
            "always",
            {
                "severity": "error"
            }
        ],
        "media-feature-colon-space-before"                 : [
            "never",
            {
                "severity": "error"
            }
        ],
        "media-feature-name-no-vendor-prefix"              : [
            true,
            {
                "severity": "error"
            }
        ],
        "media-feature-no-missing-punctuation"             : [
            true,
            {
                "severity": "error"
            }
        ],
        "media-feature-range-operator-space-after"         : [
            "always",
            {
                "severity": "error"
            }
        ],
        "media-feature-range-operator-space-before"        : [
            "always",
            {
                "severity": "error"
            }
        ],
        "custom-media-pattern"                             : [
            null,
            {
                "severity": "error"
            }
        ],
        "media-query-parentheses-space-inside"             : [
            "never",
            {
                "severity": "error"
            }
        ],
        "media-query-list-comma-newline-after"             : [
            "always-multi-line",
            {
                "severity": "error"
            }
        ],
        "media-query-list-comma-newline-before"            : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "media-query-list-comma-space-after"               : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "media-query-list-comma-space-before"              : [
            "never",
            {
                "severity": "error"
            }
        ],
        "at-rule-empty-line-before"                        : [
            "always",
            {
                "except"  : [
                    "blockless-group",
                    "first-nested"
                ],
                "ignore"  : [
                    "after-comment"
                ],
                "severity": "error"
            }
        ],
        "at-rule-no-vendor-prefix"                         : [
            true,
            {
                "severity": "error"
            }
        ],
        "at-rule-semicolon-newline-after"                  : [
            // string: "always"
            "always",
            {
                "severity": "error"
            }
        ],
        "comment-empty-line-before"                        : [
            "always",
            {
                "except"  : [
                    "first-nested"
                ],
                "ignore"  : [],
                "severity": "error"
            }
        ],
        "comment-whitespace-inside"                        : [
            "always",
            {
                "severity": "error"
            }
        ],
        "indentation"                                      : [
            4,
            {
                "except"               : [],
                "ignore"               : [],
                "hierarchicalSelectors": true,
                "severity"             : "error"
            }
        ],
        "max-empty-lines"                                  : [
            1,
            {
                "severity": "error"
            }
        ],
        "max-line-length"                                  : [
            120,
            {
                "ignore"  : [],
                "severity": "error"
            }
        ],
        "max-nesting-depth"                                : [
            2,
            {
                "ignore"  : [
                    "at-rules-without-declaration-blocks"
                ],
                "severity": "warning"
            }
        ],
        "no-browser-hacks"                                 : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-descending-specificity"                        : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-duplicate-selectors"                           : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-eol-whitespace"                                : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-indistinguishable-colors"                      : [
            true,
            {
                "threshold": 3,
                "ignore"   : [],
                "whitelist": [],
                "severity" : "warning"
            }
        ],
        "no-invalid-double-slash-comments"                 : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-missing-eof-newline"                           : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-unknown-animations"                            : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-unsupported-browser-features"                  : [
            true,
            {
                "ignore"  : [],
                "severity": "warning"
            }
        ],
        "stylelint-disable-reason"                         : [
            "always-before",
            {
                "severity": "error"
            }
        ]
    }
};
<commit_msg>add `function-max-empty-lines` rule<commit_after>'use strict';

module.exports = {
    "extends"    : [],
    "plugins"    : [],
    "ignoreFiles": [],
    "rules"      : {
        "color-hex-case"                                   : [
            "lower",
            {
                "severity": "error"
            }
        ],
        "color-hex-length"                                 : [
            "short",
            {
                "severity": "error"
            }
        ],
        "color-named"                                      : [
            "always-where-possible",
            {
                "severity": "error"
            }
        ],
        "color-no-hex"                                     : [
            null,
            {
                "severity": "error"
            }
        ],
        "color-no-invalid-hex"                             : [
            true,
            {
                "severity": "error"
            }
        ],
        "font-family-name-quotes"                          : [
            "single-where-recommended",
            {
                "severity": "error"
            }
        ],
        "font-weight-notation"                             : [
            "named-where-possible",
            {
                "ignore"  : [],
                "severity": "error"
            }
        ],
        "function-blacklist"                               : [
            null,
            {
                "severity": "error"
            }
        ],
        "function-calc-no-unspaced-operator"               : [
            true,
            {
                "severity": "error"
            }
        ],
        "function-comma-newline-after"                     : [
            "always-multi-line",
            {
                "severity": "error"
            }
        ],
        "function-comma-newline-before"                    : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "function-comma-space-after"                       : [
            "always",
            {
                "severity": "error"
            }
        ],
        "function-comma-space-before"                      : [
            "never",
            {
                "severity": "error"
            }
        ],
        "function-linear-gradient-no-nonstandard-direction": [
            true,
            {
                "severity": "error"
            }
        ],
        "function-max-empty-lines"                         : [
            0,
            {
                "severity": "error"
            }
        ],
        "function-parentheses-newline-inside"              : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "function-parentheses-space-inside"                : [
            "never-single-line",
            {
                "severity": "error"
            }
        ],
        "function-url-quotes"                              : [
            "none",
            {
                "severity": "error"
            }
        ],
        "function-whitelist"                               : [
            null,
            {
                "severity": "error"
            }
        ],
        "function-whitespace-after"                        : [
            "always",
            {
                "severity": "error"
            }
        ],
        "number-leading-zero"                              : [
            "never",
            {
                "severity": "error"
            }
        ],
        "number-max-precision"                             : [
            5,
            {
                "severity": "error"
            }
        ],
        "number-no-trailing-zeros"                         : [
            true,
            {
                "severity": "error"
            }
        ],
        "number-zero-length-no-unit"                       : [
            true,
            {
                "severity": "error"
            }
        ],
        "string-no-newline"                                : [
            true,
            {
                "severity": "error"
            }
        ],
        "string-quotes"                                    : [
            "single",
            {
                "severity": "error"
            }
        ],
        "time-no-imperceptible"                            : [
            true,
            {
                "severity": "error"
            }
        ],
        "unit-blacklist"                                   : [
            null,
            {
                "severity": "error"
            }
        ],
        "unit-whitelist"                                   : [
            null,
            {
                "severity": "error"
            }
        ],
        "value-no-vendor-prefix"                           : [
            true,
            {
                "severity": "error"
            }
        ],
        "value-list-comma-newline-after"                   : [
            "always-multi-line",
            {
                "severity": "error"
            }
        ],
        "value-list-comma-newline-before"                  : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "value-list-comma-space-after"                     : [
            "always",
            {
                "severity": "error"
            }
        ],
        "value-list-comma-space-before"                    : [
            "never",
            {
                "severity": "error"
            }
        ],
        "custom-property-no-outside-root"                  : [
            true,
            {
                "severity": "error"
            }
        ],
        "custom-property-pattern"                          : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-blacklist"                               : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-no-vendor-prefix"                        : [
            true,
            {
                "severity": "error"
            }
        ],
        "property-unit-blacklist"                          : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-unit-whitelist"                          : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-value-blacklist"                         : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-value-whitelist"                         : [
            null,
            {
                "severity": "error"
            }
        ],
        "property-whitelist"                               : [
            null,
            {
                "severity": "error"
            }
        ],
        "declaration-bang-space-after"                     : [
            "always",
            {
                "severity": "error"
            }
        ],
        "declaration-bang-space-before"                    : [
            "never",
            {
                "severity": "error"
            }
        ],
        "declaration-colon-newline-after"                  : [
            "always-multi-line",
            {
                "severity": "error"
            }
        ],
        "declaration-colon-space-after"                    : [
            "always",
            {
                "severity": "error"
            }
        ],
        "declaration-colon-space-before"                   : [
            "never",
            {
                "severity": "error"
            }
        ],
        "declaration-no-important"                         : [
            true,
            {
                "severity": "warning"
            }
        ],
        "declaration-block-no-duplicate-properties"        : [
            true,
            {
                "severity": "warning"
            }
        ],
        "declaration-block-no-shorthand-property-overrides": [
            true,
            {
                "severity": "error"
            }
        ],
        "declaration-block-properties-order"               : [
            null,
            {
                "unspecified": "bottomAlphabetical",
                "severity"   : "error"
            }
        ],
        "declaration-block-semicolon-newline-after"        : [
            "always",
            {
                "severity": "error"
            }
        ],
        "declaration-block-semicolon-newline-before"       : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "declaration-block-semicolon-space-after"          : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "declaration-block-semicolon-space-before"         : [
            "never",
            {
                "severity": "error"
            }
        ],
        "declaration-block-single-line-max-declarations"   : [
            1,
            {
                "severity": "error"
            }
        ],
        "declaration-block-trailing-semicolon"             : [
            "always",
            {
                "severity": "error"
            }
        ],
        "block-closing-brace-newline-after"                : [
            "always",
            {
                "ignoreAtRules": [],
                "severity"     : "error"
            }
        ],
        "block-closing-brace-newline-before"               : [
            "always",
            {
                "severity": "error"
            }
        ],
        "block-closing-brace-space-after"                  : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "block-closing-brace-space-before"                 : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "block-no-empty"                                   : [
            true,
            {
                "severity": "warning"
            }
        ],
        "block-no-single-line"                             : [
            true,
            {
                "severity": "error"
            }
        ],
        "block-opening-brace-newline-after"                : [
            "always",
            {
                "severity": "error"
            }
        ],
        "block-opening-brace-newline-before"               : [
            "always",
            {
                "ignoreAtRules": [],
                "severity"     : "error"
            }
        ],
        "block-opening-brace-space-after"                  : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "block-opening-brace-space-before"                 : [
            "always-single-line",
            {
                "ignoreAtRules": [],
                "severity"     : "error"
            }
        ],
        "selector-class-pattern"                           : [
            "^[a-z][-_a-z0-9]*$",
            {
                "resolveNestedSelectors": true,
                "severity"              : "error"
            }
        ],
        "selector-combinator-space-after"                  : [
            "always",
            {
                "severity": "error"
            }
        ],
        "selector-combinator-space-before"                 : [
            "always",
            {
                "severity": "error"
            }
        ],
        "selector-id-pattern"                              : [
            "^[a-z][-_a-z0-9]*$",
            {
                "severity": "error"
            }
        ],
        "selector-max-specificity"                         : [
            "0,2,0",
            {
                "severity": "warning"
            }
        ],
        "selector-no-attribute"                            : [
            null,
            {
                "severity": "error"
            }
        ],
        "selector-no-combinator"                           : [
            null,
            {
                "severity": "error"
            }
        ],
        "selector-no-id"                                   : [
            true,
            {
                "severity": "warning"
            }
        ],
        "selector-no-type"                                 : [
            true,
            {
                "ignore"  : [
                    "descendant"
                ],
                "severity": "error"
            }
        ],
        "selector-no-universal"                            : [
            true,
            {
                "severity": "warning"
            }
        ],
        "selector-no-vendor-prefix"                        : [
            true,
            {
                "severity": "error"
            }
        ],
        "selector-pseudo-element-colon-notation"           : [
            "double",
            {
                "severity": "error"
            }
        ],
        "selector-root-no-composition"                     : [
            true,
            {
                "severity": "error"
            }
        ],
        "selector-type-case"                               : [
            "lower",
            {
                "severity": "error"
            }
        ],
        "selector-list-comma-newline-after"                : [
            "always",
            {
                "severity": "error"
            }
        ],
        "selector-list-comma-newline-before"               : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "selector-list-comma-space-after"                  : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "selector-list-comma-space-before"                 : [
            "never",
            {
                "severity": "error"
            }
        ],
        "root-no-standard-properties"                      : [
            true,
            {
                "severity": "error"
            }
        ],
        "rule-nested-empty-line-before"                    : [
            "always",
            {
                "except"  : [
                    "first-nested"
                ],
                "ignore"  : [
                    "after-comment"
                ],
                "severity": "error"
            }
        ],
        "rule-non-nested-empty-line-before"                : [
            "always-multi-line",
            {
                "ignore"  : [
                    "after-comment"
                ],
                "severity": "error"
            }
        ],
        "media-feature-colon-space-after"                  : [
            "always",
            {
                "severity": "error"
            }
        ],
        "media-feature-colon-space-before"                 : [
            "never",
            {
                "severity": "error"
            }
        ],
        "media-feature-name-no-vendor-prefix"              : [
            true,
            {
                "severity": "error"
            }
        ],
        "media-feature-no-missing-punctuation"             : [
            true,
            {
                "severity": "error"
            }
        ],
        "media-feature-range-operator-space-after"         : [
            "always",
            {
                "severity": "error"
            }
        ],
        "media-feature-range-operator-space-before"        : [
            "always",
            {
                "severity": "error"
            }
        ],
        "custom-media-pattern"                             : [
            null,
            {
                "severity": "error"
            }
        ],
        "media-query-parentheses-space-inside"             : [
            "never",
            {
                "severity": "error"
            }
        ],
        "media-query-list-comma-newline-after"             : [
            "always-multi-line",
            {
                "severity": "error"
            }
        ],
        "media-query-list-comma-newline-before"            : [
            "never-multi-line",
            {
                "severity": "error"
            }
        ],
        "media-query-list-comma-space-after"               : [
            "always-single-line",
            {
                "severity": "error"
            }
        ],
        "media-query-list-comma-space-before"              : [
            "never",
            {
                "severity": "error"
            }
        ],
        "at-rule-empty-line-before"                        : [
            "always",
            {
                "except"  : [
                    "blockless-group",
                    "first-nested"
                ],
                "ignore"  : [
                    "after-comment"
                ],
                "severity": "error"
            }
        ],
        "at-rule-no-vendor-prefix"                         : [
            true,
            {
                "severity": "error"
            }
        ],
        "at-rule-semicolon-newline-after"                  : [
            // string: "always"
            "always",
            {
                "severity": "error"
            }
        ],
        "comment-empty-line-before"                        : [
            "always",
            {
                "except"  : [
                    "first-nested"
                ],
                "ignore"  : [],
                "severity": "error"
            }
        ],
        "comment-whitespace-inside"                        : [
            "always",
            {
                "severity": "error"
            }
        ],
        "indentation"                                      : [
            4,
            {
                "except"               : [],
                "ignore"               : [],
                "hierarchicalSelectors": true,
                "severity"             : "error"
            }
        ],
        "max-empty-lines"                                  : [
            1,
            {
                "severity": "error"
            }
        ],
        "max-line-length"                                  : [
            120,
            {
                "ignore"  : [],
                "severity": "error"
            }
        ],
        "max-nesting-depth"                                : [
            2,
            {
                "ignore"  : [
                    "at-rules-without-declaration-blocks"
                ],
                "severity": "warning"
            }
        ],
        "no-browser-hacks"                                 : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-descending-specificity"                        : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-duplicate-selectors"                           : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-eol-whitespace"                                : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-indistinguishable-colors"                      : [
            true,
            {
                "threshold": 3,
                "ignore"   : [],
                "whitelist": [],
                "severity" : "warning"
            }
        ],
        "no-invalid-double-slash-comments"                 : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-missing-eof-newline"                           : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-unknown-animations"                            : [
            true,
            {
                "severity": "error"
            }
        ],
        "no-unsupported-browser-features"                  : [
            true,
            {
                "ignore"  : [],
                "severity": "warning"
            }
        ],
        "stylelint-disable-reason"                         : [
            "always-before",
            {
                "severity": "error"
            }
        ]
    }
};
<|endoftext|>


<commit_before>/*! Gulp Export Plugin v2.1.0 | Copyright (c) 2015-present Ivan (3axap4eHko) Zakharchenko*/
'use strict';

const Path = require('path');
const Through = require('through2');
const File = require('vinyl');

const delimiterPathExpr = /\\|\//g;
const lowercaseExpr = /^[a-z]/;
const invalidCharsExpr = /[-.,]/;

function toUpperCaseFirst(str) {
  if (!str.length) {
    return str;
  }
  return str[0].toUpperCase() + str.slice(1);
}
function toValidName(str) {
  return str.split(invalidCharsExpr).map(toUpperCaseFirst).join('')
}
function toLowerCaseFirst(str) {
  if (!str.length) {
    return str;
  }
  return str[0].toLowerCase() + str.slice(1);
}
function importing(moduleName) {
  if (lowercaseExpr.test(moduleName)) {
    return `* as $${moduleName}`;
  }
  return `$${moduleName}`;
}
const defaultOptions = {
  context: './',
  filename: 'index.js',
  exclude: /^$/,
  indentSize: 2,
};

module.exports = function (options) {
  options = Object.assign({}, defaultOptions, options || {});

  const indexModules = {};
  const exportFileName = options.filename || packageJson.main;
  const {exclude, indentSize} = options;

  return Through.obj((file, enc, cb) => {
    const fileName = file.history[file.history.length - 1];
    const relativePath = Path.relative(options.context, fileName);
    console.log(exclude);
    console.log(relativePath);
    console.log(exclude.test(relativePath));
    if (!exclude.test(relativePath)) {
      const parsedPath = Path.parse(relativePath);
      const isClass = !lowercaseExpr.test(parsedPath.name);
      const namespace = parsedPath.dir
        .split(delimiterPathExpr)
        .filter(part => part.length)
        .concat([parsedPath.name])
        .map(toValidName)
        .map(toUpperCaseFirst);

      if (!isClass) {
        namespace[0] = toLowerCaseFirst(namespace[0]);
      }
      const relativeFilename = Path.relative(options.context, fileName).replace(delimiterPathExpr, '/').replace(/\.[^.]+$/, '');
      const moduleName = namespace.join('');
      indexModules[moduleName] = relativeFilename;
    }

    cb(null, file);
  }, cb => {
    const indent = ' '.repeat(indentSize);
    const indexFile = Object.keys(indexModules).map(m => `import ${importing(m)} from './${indexModules[m]}';`);

    indexFile.push(`\nexport default {\n${indent}${Object.keys(indexModules).map(name => `'${name}': $${name}`).join(`,\n${indent}`)},`);
    indexFile.push('};');

    const exportFile = new File({
      path: exportFileName,
      contents: Buffer.from(indexFile.join('\n'))
    });
    cb(null, exportFile);
  });
};
<commit_msg>remove console<commit_after>/*! Gulp Export Plugin v2.1.0 | Copyright (c) 2015-present Ivan (3axap4eHko) Zakharchenko*/
'use strict';

const Path = require('path');
const Through = require('through2');
const File = require('vinyl');

const delimiterPathExpr = /\\|\//g;
const lowercaseExpr = /^[a-z]/;
const invalidCharsExpr = /[-.,]/;

function toUpperCaseFirst(str) {
  if (!str.length) {
    return str;
  }
  return str[0].toUpperCase() + str.slice(1);
}
function toValidName(str) {
  return str.split(invalidCharsExpr).map(toUpperCaseFirst).join('')
}
function toLowerCaseFirst(str) {
  if (!str.length) {
    return str;
  }
  return str[0].toLowerCase() + str.slice(1);
}
function importing(moduleName) {
  if (lowercaseExpr.test(moduleName)) {
    return `* as $${moduleName}`;
  }
  return `$${moduleName}`;
}
const defaultOptions = {
  context: './',
  filename: 'index.js',
  exclude: /^$/,
  indentSize: 2,
};

module.exports = function (options) {
  options = Object.assign({}, defaultOptions, options || {});

  const indexModules = {};
  const exportFileName = options.filename || packageJson.main;
  const {exclude, indentSize} = options;

  return Through.obj((file, enc, cb) => {
    const fileName = file.history[file.history.length - 1];
    const relativePath = Path.relative(options.context, fileName);
    if (!exclude.test(relativePath)) {
      const parsedPath = Path.parse(relativePath);
      const isClass = !lowercaseExpr.test(parsedPath.name);
      const namespace = parsedPath.dir
        .split(delimiterPathExpr)
        .filter(part => part.length)
        .concat([parsedPath.name])
        .map(toValidName)
        .map(toUpperCaseFirst);

      if (!isClass) {
        namespace[0] = toLowerCaseFirst(namespace[0]);
      }
      const relativeFilename = Path.relative(options.context, fileName).replace(delimiterPathExpr, '/').replace(/\.[^.]+$/, '');
      const moduleName = namespace.join('');
      indexModules[moduleName] = relativeFilename;
    }

    cb(null, file);
  }, cb => {
    const indent = ' '.repeat(indentSize);
    const indexFile = Object.keys(indexModules).map(m => `import ${importing(m)} from './${indexModules[m]}';`);

    indexFile.push(`\nexport default {\n${indent}${Object.keys(indexModules).map(name => `'${name}': $${name}`).join(`,\n${indent}`)},`);
    indexFile.push('};');

    const exportFile = new File({
      path: exportFileName,
      contents: Buffer.from(indexFile.join('\n'))
    });
    cb(null, exportFile);
  });
};
<|endoftext|>


<commit_before>'use strict';

var inherits = require('util').inherits
var rules = require('./rules')

function createId () {
  return (
    Math.random().toString(16).substring(2)
  + Math.random().toString(16).substring(2)
  )
}

function find (array, id) {
  if(!id) return
  for (var k in array) {
    if(array[k].id == id) return array[k]
  }
}

//create a macgyver context
var exports = module.exports = function () {

  var contracts = {}
  var macgyver = function wrap(funx, name) {
    //if this is already wrapped don't wrap it.
    if('string' === typeof funx)
      name = funx
    if('function' !== typeof funx)
      funx = function noOp() {} //default to empty function
    if(funx.id) return funx

    var id = createId()
    var contract = {
      called: 0,   //counter of calls
      returned: 0, //counter of returns
      throws: 0,
      function: funx,
      name: name,
      get: function (id) {
        return contracts[typeof id == 'string' ? id : id.id]
      }
    }
    contract.rules = wrapped.rules = []
    contract.wrapped = wrapped
    contracts[id] = contract
    function wrapped () {
      contract.called ++
      var args = [].slice.call(arguments)
      contract.rules.forEach(function (rule) {
        if(rule.before) rule.before.call(contract, args)
      })
      //actually call the function...
      var i = contract.rules.length - 1, threw, returned

      function next () {
        var args = [].slice.call(arguments)
        var around

        while(~i && !(around = contract.rules[i--].around))
          ;
        return ( around
          ? around.call(contract, next, this, args)
          : (function () {
              try { return returned = funx.apply(this, args) }
              catch (err) { threw = true; throw err }
            }).call(this)
          )
      }
      next.apply(this, args)
      //increment count of returns
      //(this is useful for asserting when something may happen before a call ends)
      if(threw) { contract.throws ++; return }
      contract.returned ++
      //after
      contract.rules.forEach(function (rule) {
        if(rule.after) rule.after.call(contract, returned)
      })
      return returned
      //also, have after, have around...
    }
    wrapped.id = id
    //install rules.
    for (var k in rules) {
      ;(function (k){
        wrapped[k] = function () {
          var args = [].slice.call(arguments)
          //some rules don't make sense to duplicate.
          var rule = find(contract.rules, k)
          if(rule) return rule.update.apply(contract, args)
          rule = rules[k].apply(contract, args)
          if(rule) contract.rules.push(rule)
          return this
        }
      })(k)
    }
    return wrapped
  }

  macgyver.validate = function () {
    for (var k in contracts) {
      var con = contracts[k]
      con.rules.forEach(function (rule) {
        if(rule.validate) rule.validate.call(con)
      })
    }
  }

  macgyver.autoValidate = function (timeout) {
    if(process.on)
      process.on('exit', macgyver.validate)
    else
      setTimeout(macgyver.validate, timeout || 10e3)
    return macgyver
  }

  return macgyver
}

<commit_msg>check that process.on is a function<commit_after>'use strict';

var inherits = require('util').inherits
var rules = require('./rules')

function createId () {
  return (
    Math.random().toString(16).substring(2)
  + Math.random().toString(16).substring(2)
  )
}

function find (array, id) {
  if(!id) return
  for (var k in array) {
    if(array[k].id == id) return array[k]
  }
}

//create a macgyver context
var exports = module.exports = function () {

  var contracts = {}
  var macgyver = function wrap(funx, name) {
    //if this is already wrapped don't wrap it.
    if('string' === typeof funx)
      name = funx
    if('function' !== typeof funx)
      funx = function noOp() {} //default to empty function
    if(funx.id) return funx

    var id = createId()
    var contract = {
      called: 0,   //counter of calls
      returned: 0, //counter of returns
      throws: 0,
      function: funx,
      name: name,
      get: function (id) {
        return contracts[typeof id == 'string' ? id : id.id]
      }
    }
    contract.rules = wrapped.rules = []
    contract.wrapped = wrapped
    contracts[id] = contract
    function wrapped () {
      contract.called ++
      var args = [].slice.call(arguments)
      contract.rules.forEach(function (rule) {
        if(rule.before) rule.before.call(contract, args)
      })
      //actually call the function...
      var i = contract.rules.length - 1, threw, returned

      function next () {
        var args = [].slice.call(arguments)
        var around

        while(~i && !(around = contract.rules[i--].around))
          ;
        return ( around
          ? around.call(contract, next, this, args)
          : (function () {
              try { return returned = funx.apply(this, args) }
              catch (err) { threw = true; throw err }
            }).call(this)
          )
      }
      next.apply(this, args)
      //increment count of returns
      //(this is useful for asserting when something may happen before a call ends)
      if(threw) { contract.throws ++; return }
      contract.returned ++
      //after
      contract.rules.forEach(function (rule) {
        if(rule.after) rule.after.call(contract, returned)
      })
      return returned
      //also, have after, have around...
    }
    wrapped.id = id
    //install rules.
    for (var k in rules) {
      ;(function (k){
        wrapped[k] = function () {
          var args = [].slice.call(arguments)
          //some rules don't make sense to duplicate.
          var rule = find(contract.rules, k)
          if(rule) return rule.update.apply(contract, args)
          rule = rules[k].apply(contract, args)
          if(rule) contract.rules.push(rule)
          return this
        }
      })(k)
    }
    return wrapped
  }

  macgyver.validate = function () {
    for (var k in contracts) {
      var con = contracts[k]
      con.rules.forEach(function (rule) {
        if(rule.validate) rule.validate.call(con)
      })
    }
  }

  macgyver.autoValidate = function (timeout) {
    if('function' === typeof process.on)
      process.on('exit', macgyver.validate)
    else
      setTimeout(macgyver.validate, timeout || 10e3)
    return macgyver
  }

  return macgyver
}

<|endoftext|>


<commit_before>'use strict';

var querystring = require('querystring');

var R = require('ramda');
var request = require('request');

var Plaid = module.exports = {};

Plaid.environments = {
  production: 'https://api.plaid.com',
  tartan: 'https://tartan.plaid.com',
};

Plaid.Client = function(client_id, secret, env) {
  if (R.isNil(client_id)) {
    throw new Error('Missing Plaid "client_id"');
  }

  if (R.isNil(secret)) {
    throw new Error('Missing Plaid "secret"');
  }

  if (env !== Plaid.environments.tartan &&
      env !== Plaid.environments.production) {
    throw new Error('Invalid Plaid environment');
  }

  this.client_id = client_id;
  this.secret = secret;
  this.env = env;
};

// Private

Plaid.Client.prototype._addUser =
  function(product, type, credentials, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

  this._authenticatedRequest({
    uri: this.env + '/' + product,
    method: 'POST',
    body: {
      type: type,
      credentials: credentials,
      options: options,
    },
    includeMfaResponse: true,
  }, callback);
};

Plaid.Client.prototype._getUser =
  function(product, access_token, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

    this._authenticatedRequest({
      uri: this.env + '/' + product + '/get',
      method: 'POST',
      body: {
        access_token: access_token,
        options: options,
      },
      includeMfaResponse: false,
    }, callback);
};

Plaid.Client.prototype._stepUser =
  function(product, access_token, mfaResponse, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

    this._authenticatedRequest({
      uri: this.env + '/' + product + '/step',
      method: 'POST',
      body: {
        access_token: access_token,
        mfa: mfaResponse,
        options: options,
      },
      includeMfaResponse: true,
    }, callback);
};

Plaid.Client.prototype._patchUser =
  function(product, access_token, credentials, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

    this._authenticatedRequest({
      uri: this.env + '/' + product,
      method: 'PATCH',
      body: {
        access_token: access_token,
        credentials: credentials,
        options: options,
      },
      includeMfaResponse: true,
    }, callback);
};

Plaid.Client.prototype._deleteUser =
  function(product, access_token, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

    this._authenticatedRequest({
      uri: this.env + '/' + product,
      method: 'DELETE',
      body: {
        access_token: access_token,
        options: options,
      },
      includeMfaResponse: false,
    }, callback);
};

Plaid._publicRequest = function(options, callback) {
  var $requestOptions = {
    uri: options.uri,
    method: options.method,
    json: true,
  };

  if (options.body != null) {
    $requestOptions = R.assoc('body', options.body, $requestOptions);
  }

  request($requestOptions, function(err, res, $body) {
    if (err != null) {
      callback(err, null);
    } else if (res.statusCode !== 200) {
      callback(R.assoc('statusCode', res.statusCode, $body), null);
    } else {
      callback(null, $body);
    }
  });
};

Plaid.Client.prototype._authenticatedRequest = function(options, callback) {
  if (R.has('options', options.body)) {
    options.body.options = JSON.stringify(options.body.options);
  }

  request({
    uri: options.uri,
    method: options.method,
    json: R.merge({
      client_id: this.client_id,
      secret: this.secret,
    }, options.body),
  }, function(err, res, body) {
    handleApiResponse(err, res, body, options.includeMfaResponse, callback);
  });
};

// Authenticated Routes

// Auth
Plaid.Client.prototype.addAuthUser =
  R.partial(Plaid.Client.prototype._addUser, ['auth']);
Plaid.Client.prototype.getAuthUser =
  R.partial(Plaid.Client.prototype._getUser, ['auth']);
Plaid.Client.prototype.stepAuthUser =
  R.partial(Plaid.Client.prototype._stepUser, ['auth']);
Plaid.Client.prototype.patchAuthUser =
  R.partial(Plaid.Client.prototype._patchUser, ['auth']);
Plaid.Client.prototype.deleteAuthUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['auth']);

// Connect
Plaid.Client.prototype.addConnectUser =
  R.partial(Plaid.Client.prototype._addUser, ['connect']);
Plaid.Client.prototype.getConnectUser =
  R.partial(Plaid.Client.prototype._getUser, ['connect']);
Plaid.Client.prototype.stepConnectUser =
  R.partial(Plaid.Client.prototype._stepUser, ['connect']);
Plaid.Client.prototype.patchConnectUser =
  R.partial(Plaid.Client.prototype._patchUser, ['connect']);
Plaid.Client.prototype.deleteConnectUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['connect']);

// Income
Plaid.Client.prototype.addIncomeUser =
  R.partial(Plaid.Client.prototype._addUser, ['income']);
Plaid.Client.prototype.getIncomeUser =
  R.partial(Plaid.Client.prototype._getUser, ['income']);
Plaid.Client.prototype.stepIncomeUser =
  R.partial(Plaid.Client.prototype._stepUser, ['income']);
Plaid.Client.prototype.patchIncomeUser =
  R.partial(Plaid.Client.prototype._patchUser, ['income']);
Plaid.Client.prototype.deleteIncomeUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['income']);

// Info
Plaid.Client.prototype.addInfoUser =
  R.partial(Plaid.Client.prototype._addUser, ['info']);
Plaid.Client.prototype.getInfoUser =
  R.partial(Plaid.Client.prototype._getUser, ['info']);
Plaid.Client.prototype.stepInfoUser =
  R.partial(Plaid.Client.prototype._stepUser, ['info']);
Plaid.Client.prototype.patchInfoUser =
  R.partial(Plaid.Client.prototype._patchUser, ['info']);
Plaid.Client.prototype.deleteInfoUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['info']);

// Risk
Plaid.Client.prototype.addRiskUser =
  R.partial(Plaid.Client.prototype._addUser, ['risk']);
Plaid.Client.prototype.getRiskUser =
  R.partial(Plaid.Client.prototype._getUser, ['risk']);
Plaid.Client.prototype.stepRiskUser =
  R.partial(Plaid.Client.prototype._stepUser, ['risk']);
Plaid.Client.prototype.patchRiskUser =
  R.partial(Plaid.Client.prototype._patchUser, ['risk']);
Plaid.Client.prototype.deleteRiskUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['risk']);

// exchangeToken
Plaid.Client.prototype.exchangeToken =
  function(public_token, account_id, callback) {
  if (typeof account_id === 'function') {
    callback = account_id;
    account_id = null;
  }
  this._authenticatedRequest({
    uri: this.env + '/exchange_token',
    method: 'POST',
    body: {
      account_id: account_id,
      public_token: public_token,
    },
    includeMfaResponse: false,
  }, callback);
};

// Balance
Plaid.Client.prototype.getBalance = function(access_token, callback) {
  this._authenticatedRequest({
    uri: this.env + '/balance',
    method: 'POST',
    body: {
      access_token: access_token,
    },
    includeMfaResponse: false,
  }, callback);
};

// Upgrade
Plaid.Client.prototype.upgradeUser =
  function(access_token, upgrade_to, options, callback) {
  if (typeof options === 'function') {
    callback = options;
    options = {};
  }

  this._authenticatedRequest({
    uri: this.env + '/upgrade',
    method: 'POST',
    body: {
      access_token: access_token,
      upgrade_to: upgrade_to,
      options: options,
    },
    includeMfaResponse: true,
  }, callback);
};

// Longtail Institutions
Plaid.Client.prototype.getLongtailInstitutions = function(options, callback) {
  this._authenticatedRequest({
    uri: this.env + '/institutions/longtail',
    method: 'POST',
    body: options,
  }, callback);
};

// simplified `/institutions/all` endpoint
// Replaces the deprecated Longtail Institutions endpoint
Plaid.Client.prototype.getAllInstitutions = function(options, callback) {
  this._authenticatedRequest({
    uri: this.env + '/institutions/all',
    method: 'POST',
    body: options,
  }, callback);
};

// Public Routes

Plaid.getCategory = function(category_id, env, callback) {
  this._publicRequest({
    uri: env + '/categories/' + category_id,
    method: 'GET',
  }, callback);
};

Plaid.getCategories = function(env, callback) {
  this._publicRequest({
    uri: env + '/categories',
    method: 'GET',
  }, callback);
};

Plaid.getInstitution = function(institution_id, env, callback) {
  this._publicRequest({
    uri: env + '/institutions/' + institution_id,
    method: 'GET',
  }, callback);
};

Plaid.getInstitutions = function(env, callback) {
  this._publicRequest({
    uri: env + '/institutions',
    method: 'GET',
  }, callback);
};

Plaid.searchInstitutions = function(options, env, callback) {
  var qs = querystring.stringify(R.reject(R.isNil, {
    id: options.id,
    p: options.product,
    q: options.query,
  }));
  this._publicRequest({
    uri: env + '/institutions/search?' + qs,
    method: 'GET',
  }, callback);
};

// simplified `/institutions/all` endpoint
// Replaces the deprecated `/institutions/search` endpoint
Plaid.searchAllInstitutions = function(options, env, callback) {
  var qs = querystring.stringify(R.reject(R.isNil, {
    id: options.id,
    p: options.product,
    q: options.query,
  }));
  this._publicRequest({
    uri: env + '/institutions/all/search?' + qs,
    method: 'GET',
  }, callback);
};

function handleApiResponse(err, res, $body, includeMfaResponse, callback) {
  if (res != null) {
    $body = R.assoc('statusCode', res.statusCode, $body);
  }

  if (includeMfaResponse) {
    if (err != null) {
      callback(err, null, null);
    } else if (res.statusCode === 200) {
      callback(null, null, $body);
    } else if (res.statusCode === 201) {
      callback(null, $body, null);
    } else {
      callback($body, null, null);
    }
  } else {
    if (err != null) {
      callback(err, null);
    } else if (res.statusCode === 200) {
      callback(null, $body);
    } else {
      callback($body, null);
    }
  }
}
<commit_msg>add request_id field to authenticated requests (#87)<commit_after>'use strict';

var querystring = require('querystring');

var R = require('ramda');
var request = require('request');

var Plaid = module.exports = {};

Plaid.environments = {
  production: 'https://api.plaid.com',
  tartan: 'https://tartan.plaid.com',
};

Plaid.Client = function(client_id, secret, env) {
  if (R.isNil(client_id)) {
    throw new Error('Missing Plaid "client_id"');
  }

  if (R.isNil(secret)) {
    throw new Error('Missing Plaid "secret"');
  }

  if (env !== Plaid.environments.tartan &&
      env !== Plaid.environments.production) {
    throw new Error('Invalid Plaid environment');
  }

  this.client_id = client_id;
  this.secret = secret;
  this.env = env;
};

// Private

Plaid.Client.prototype._addUser =
  function(product, type, credentials, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

  this._authenticatedRequest({
    uri: this.env + '/' + product,
    method: 'POST',
    body: {
      type: type,
      credentials: credentials,
      options: options,
    },
    includeMfaResponse: true,
  }, callback);
};

Plaid.Client.prototype._getUser =
  function(product, access_token, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

    this._authenticatedRequest({
      uri: this.env + '/' + product + '/get',
      method: 'POST',
      body: {
        access_token: access_token,
        options: options,
      },
      includeMfaResponse: false,
    }, callback);
};

Plaid.Client.prototype._stepUser =
  function(product, access_token, mfaResponse, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

    this._authenticatedRequest({
      uri: this.env + '/' + product + '/step',
      method: 'POST',
      body: {
        access_token: access_token,
        mfa: mfaResponse,
        options: options,
      },
      includeMfaResponse: true,
    }, callback);
};

Plaid.Client.prototype._patchUser =
  function(product, access_token, credentials, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

    this._authenticatedRequest({
      uri: this.env + '/' + product,
      method: 'PATCH',
      body: {
        access_token: access_token,
        credentials: credentials,
        options: options,
      },
      includeMfaResponse: true,
    }, callback);
};

Plaid.Client.prototype._deleteUser =
  function(product, access_token, options, callback) {
    if (typeof options === 'function') {
      callback = options;
      options = {};
    }

    this._authenticatedRequest({
      uri: this.env + '/' + product,
      method: 'DELETE',
      body: {
        access_token: access_token,
        options: options,
      },
      includeMfaResponse: false,
    }, callback);
};

Plaid._publicRequest = function(options, callback) {
  var $requestOptions = {
    uri: options.uri,
    method: options.method,
    json: true,
  };

  if (options.body != null) {
    $requestOptions = R.assoc('body', options.body, $requestOptions);
  }

  request($requestOptions, function(err, res, $body) {
    if (err != null) {
      callback(err, null);
    } else if (res.statusCode !== 200) {
      callback(R.assoc('statusCode', res.statusCode, $body), null);
    } else {
      callback(null, $body);
    }
  });
};

Plaid.Client.prototype._authenticatedRequest = function(options, callback) {
  if (R.has('options', options.body)) {
    options.body.options = JSON.stringify(options.body.options);
  }

  request({
    uri: options.uri,
    method: options.method,
    json: R.merge({
      client_id: this.client_id,
      secret: this.secret,
    }, options.body),
  }, function(err, res, body) {
    handleApiResponse(err, res, body, options.includeMfaResponse, callback);
  });
};

// Authenticated Routes

// Auth
Plaid.Client.prototype.addAuthUser =
  R.partial(Plaid.Client.prototype._addUser, ['auth']);
Plaid.Client.prototype.getAuthUser =
  R.partial(Plaid.Client.prototype._getUser, ['auth']);
Plaid.Client.prototype.stepAuthUser =
  R.partial(Plaid.Client.prototype._stepUser, ['auth']);
Plaid.Client.prototype.patchAuthUser =
  R.partial(Plaid.Client.prototype._patchUser, ['auth']);
Plaid.Client.prototype.deleteAuthUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['auth']);

// Connect
Plaid.Client.prototype.addConnectUser =
  R.partial(Plaid.Client.prototype._addUser, ['connect']);
Plaid.Client.prototype.getConnectUser =
  R.partial(Plaid.Client.prototype._getUser, ['connect']);
Plaid.Client.prototype.stepConnectUser =
  R.partial(Plaid.Client.prototype._stepUser, ['connect']);
Plaid.Client.prototype.patchConnectUser =
  R.partial(Plaid.Client.prototype._patchUser, ['connect']);
Plaid.Client.prototype.deleteConnectUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['connect']);

// Income
Plaid.Client.prototype.addIncomeUser =
  R.partial(Plaid.Client.prototype._addUser, ['income']);
Plaid.Client.prototype.getIncomeUser =
  R.partial(Plaid.Client.prototype._getUser, ['income']);
Plaid.Client.prototype.stepIncomeUser =
  R.partial(Plaid.Client.prototype._stepUser, ['income']);
Plaid.Client.prototype.patchIncomeUser =
  R.partial(Plaid.Client.prototype._patchUser, ['income']);
Plaid.Client.prototype.deleteIncomeUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['income']);

// Info
Plaid.Client.prototype.addInfoUser =
  R.partial(Plaid.Client.prototype._addUser, ['info']);
Plaid.Client.prototype.getInfoUser =
  R.partial(Plaid.Client.prototype._getUser, ['info']);
Plaid.Client.prototype.stepInfoUser =
  R.partial(Plaid.Client.prototype._stepUser, ['info']);
Plaid.Client.prototype.patchInfoUser =
  R.partial(Plaid.Client.prototype._patchUser, ['info']);
Plaid.Client.prototype.deleteInfoUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['info']);

// Risk
Plaid.Client.prototype.addRiskUser =
  R.partial(Plaid.Client.prototype._addUser, ['risk']);
Plaid.Client.prototype.getRiskUser =
  R.partial(Plaid.Client.prototype._getUser, ['risk']);
Plaid.Client.prototype.stepRiskUser =
  R.partial(Plaid.Client.prototype._stepUser, ['risk']);
Plaid.Client.prototype.patchRiskUser =
  R.partial(Plaid.Client.prototype._patchUser, ['risk']);
Plaid.Client.prototype.deleteRiskUser =
  R.partial(Plaid.Client.prototype._deleteUser, ['risk']);

// exchangeToken
Plaid.Client.prototype.exchangeToken =
  function(public_token, account_id, callback) {
  if (typeof account_id === 'function') {
    callback = account_id;
    account_id = null;
  }
  this._authenticatedRequest({
    uri: this.env + '/exchange_token',
    method: 'POST',
    body: {
      account_id: account_id,
      public_token: public_token,
    },
    includeMfaResponse: false,
  }, callback);
};

// Balance
Plaid.Client.prototype.getBalance = function(access_token, callback) {
  this._authenticatedRequest({
    uri: this.env + '/balance',
    method: 'POST',
    body: {
      access_token: access_token,
    },
    includeMfaResponse: false,
  }, callback);
};

// Upgrade
Plaid.Client.prototype.upgradeUser =
  function(access_token, upgrade_to, options, callback) {
  if (typeof options === 'function') {
    callback = options;
    options = {};
  }

  this._authenticatedRequest({
    uri: this.env + '/upgrade',
    method: 'POST',
    body: {
      access_token: access_token,
      upgrade_to: upgrade_to,
      options: options,
    },
    includeMfaResponse: true,
  }, callback);
};

// Longtail Institutions
Plaid.Client.prototype.getLongtailInstitutions = function(options, callback) {
  this._authenticatedRequest({
    uri: this.env + '/institutions/longtail',
    method: 'POST',
    body: options,
  }, callback);
};

// simplified `/institutions/all` endpoint
// Replaces the deprecated Longtail Institutions endpoint
Plaid.Client.prototype.getAllInstitutions = function(options, callback) {
  this._authenticatedRequest({
    uri: this.env + '/institutions/all',
    method: 'POST',
    body: options,
  }, callback);
};

// Public Routes

Plaid.getCategory = function(category_id, env, callback) {
  this._publicRequest({
    uri: env + '/categories/' + category_id,
    method: 'GET',
  }, callback);
};

Plaid.getCategories = function(env, callback) {
  this._publicRequest({
    uri: env + '/categories',
    method: 'GET',
  }, callback);
};

Plaid.getInstitution = function(institution_id, env, callback) {
  this._publicRequest({
    uri: env + '/institutions/' + institution_id,
    method: 'GET',
  }, callback);
};

Plaid.getInstitutions = function(env, callback) {
  this._publicRequest({
    uri: env + '/institutions',
    method: 'GET',
  }, callback);
};

Plaid.searchInstitutions = function(options, env, callback) {
  var qs = querystring.stringify(R.reject(R.isNil, {
    id: options.id,
    p: options.product,
    q: options.query,
  }));
  this._publicRequest({
    uri: env + '/institutions/search?' + qs,
    method: 'GET',
  }, callback);
};

// simplified `/institutions/all` endpoint
// Replaces the deprecated `/institutions/search` endpoint
Plaid.searchAllInstitutions = function(options, env, callback) {
  var qs = querystring.stringify(R.reject(R.isNil, {
    id: options.id,
    p: options.product,
    q: options.query,
  }));
  this._publicRequest({
    uri: env + '/institutions/all/search?' + qs,
    method: 'GET',
  }, callback);
};

function handleApiResponse(err, res, $body, includeMfaResponse, callback) {
  if (res != null) {
    $body = R.merge({
      statusCode: res.statusCode,
      request_id: res.headers['x-request-id'],
    }, $body);
  }

  if (includeMfaResponse) {
    if (err != null) {
      callback(err, null, null);
    } else if (res.statusCode === 200) {
      callback(null, null, $body);
    } else if (res.statusCode === 201) {
      callback(null, $body, null);
    } else {
      callback($body, null, null);
    }
  } else {
    if (err != null) {
      callback(err, null);
    } else if (res.statusCode === 200) {
      callback(null, $body);
    } else {
      callback($body, null);
    }
  }
}
<|endoftext|>


<commit_before>module.exports = filterObjectOnSchema;

function filterObjectOnSchema(schema, doc){

    var results;

    //console.log("DOC: ", JSON.stringify(doc, null, 2));
    //console.log("SCH: ", JSON.stringify(schema, null, 2));

    if (schema.type == 'object') {
      results = {};   // holds this levels items

      // process properties  -  recursive
      Object.keys(schema.properties).forEach(function(key){
        if (doc[key] !== undefined){
          var sp = schema.properties[key];
          if ( sp.type == 'object'){

            // check if property-less object (free-form)
            if (sp.hasOwnProperty('properties')){
              results[key] = filterObjectOnSchema(sp, doc[key]);
            } else {
              if (Object.keys(doc[key]).length > 0){
                results[key] = doc[key];
              }
            }

          }else if(sp.type == 'array'){
            if (doc[key]) results[key] = filterObjectOnSchema(sp, doc[key]);
          }
          else if(sp.type == 'boolean'){
            if(doc[key] != null && typeof doc[key] != 'undefined') results[key] = doc[key];
          }else{
            if (doc[key]) results[key] = doc[key];
          }
        }
      });

    }else if (schema.type == 'array'){
      // arrays can hold objects or literals
      if (schema.items.type == 'object') {
        results = [];
        doc.forEach(function (item) {
          results.push(filterObjectOnSchema(schema.items, item));
        });
      } else {
        results = doc;
      }
    }

    return results;

}

<commit_msg>do not trim empty objects<commit_after>module.exports = filterObjectOnSchema;

function filterObjectOnSchema(schema, doc){

    var results;

    //console.log("DOC: ", JSON.stringify(doc, null, 2));
    //console.log("SCH: ", JSON.stringify(schema, null, 2));

    if (schema.type == 'object') {
      results = {};   // holds this levels items

      // process properties  -  recursive
      Object.keys(schema.properties).forEach(function(key){
        if (doc[key] !== undefined){
          var sp = schema.properties[key];
          if ( sp.type == 'object'){

            // check if property-less object (free-form)
            if (sp.hasOwnProperty('properties')){
              results[key] = filterObjectOnSchema(sp, doc[key]);
            } else {
              if (Object.keys(doc[key]).length > 0){
                results[key] = doc[key];
              } else {
                results[key] = {};
              }
            }

          }else if(sp.type == 'array'){
            if (doc[key]) results[key] = filterObjectOnSchema(sp, doc[key]);
          }
          else if(sp.type == 'boolean'){
            if(doc[key] != null && typeof doc[key] != 'undefined') results[key] = doc[key];
          }else{
            if (doc[key]) results[key] = doc[key];
          }
        }
      });

    }else if (schema.type == 'array'){
      // arrays can hold objects or literals
      if (schema.items.type == 'object') {
        results = [];
        doc.forEach(function (item) {
          results.push(filterObjectOnSchema(schema.items, item));
        });
      } else {
        results = doc;
      }
    }

    return results;

}

<|endoftext|>


<commit_before>const debug = require('debug')('apollo-local')

/**
* Create a local graphql networkInterface for apollo-client.
*
* See:
* https://github.com/apollostack/apollo-client/issues/962
* https://github.com/apollostack/apollo-client/blob/master/src/transport/networkInterface.ts
*
* @arg {Object} graphql - The graphql-js library. ie, the result of require('graphql')
* @arg {GraphQLSchema} schema - The schema you create for your GraphQL API.
*                               See http://graphql.org/graphql-js/type/#graphqlschema
* @arg {Object} options=
*   @arg {Object} options.rootValue - The optional root value argument for graphqljs
*   @arg {Object} options.context - Optional context for the graphql query
* @return {Promise<GraphQLResult>} - The result of the GraphQL query
*/
const createLocalInterface = (graphql, schema, {rootValue = null, context = null} = {}) => {
    const {execute} = graphql

    return {
        query: ({query, variables, operationName, debugName}) => {
            const start = new Date()
            var result

            try {
                result = execute(schema, query, rootValue, context, variables, operationName)
            } catch (err) {
                return Promise.reject(err)
            }

            return result.then(data => {
                debug(`${operationName} (${(new Date() - start)}ms)`)
                return data
            })
        }
    }
}

module.exports = {createLocalInterface}

<commit_msg>Add explanatory comment for execute() and log execution failures<commit_after>const debug = require('debug')('apollo-local')

/**
* Create a local graphql networkInterface for apollo-client.
*
* See:
* https://github.com/apollostack/apollo-client/issues/962
* https://github.com/apollostack/apollo-client/blob/master/src/transport/networkInterface.ts
*
* @arg {Object} graphql - The graphql-js library. ie, the result of require('graphql')
* @arg {GraphQLSchema} schema - The schema you create for your GraphQL API.
*                               See http://graphql.org/graphql-js/type/#graphqlschema
* @arg {Object} options=
*   @arg {Object} options.rootValue - The optional root value argument for graphqljs
*   @arg {Object} options.context - Optional context for the graphql query
* @return {Promise<GraphQLResult>} - The result of the GraphQL query
*/
const createLocalInterface = (graphql, schema, {rootValue = null, context = null} = {}) => {
    const {execute} = graphql

    return {
        query: ({query, variables, operationName, debugName}) => {
            const start = new Date()
            let result

            // execute() can throw if its arguments aren't valid, so we need to wrap with try/catch
            // See http://graphql.org/graphql-js/execution/#execute
            try {
                result = execute(schema, query, rootValue, context, variables, operationName)
            } catch (err) {
                debug(`${operationName} failed to execute (${err.message})`)
                return Promise.reject(err)
            }

            return result.then(data => {
                debug(`${operationName} (${(new Date() - start)}ms)`)
                return data
            })
        }
    }
}

module.exports = {createLocalInterface}

<|endoftext|>


<commit_before>var xmldom = require('xmldom')
  , xpath = require('xpath')
  , saml2json = {}
  ;

saml2json.parse = function(response){

  var xml = new Buffer(response, 'base64').toString('ascii')
    , doc = new xmldom.DOMParser().parseFromString(xml)
    , profile = {}, attributes
    ;

  attributes = xpath.select('//*[local-name() = "AttributeStatement"]/*', doc);
  attributes.forEach(function(attribute){
    var name = xpath.select('string(@Name)', attribute).toLowerCase();
    profile[name] = xpath.select('string(*[local-name() = "AttributeValue"]/text())', attribute);
  });

  return profile;

};

module.exports = saml2json;
<commit_msg>Refactor and add additional methods to the saml2json library. This breaks compatibility with upstream and should now be considered a totally different module.<commit_after>// Saml2js
// =======
// A library for parsing SAML attributes
// into a POJO (Plain Old JavaScript Object)

// Require dependencies
var xmldom    = require('xmldom'),
    xpath     = require('xpath'),
    _         = require('lodash'),
    profile   = {},
    attributes;

// Saml2js
// -------
// Constructor function. Saves a copy
// of the raw SAML you pass to it and
// a copy that's parsed into a JS object.
//
// `response` [String] - A SAML response string
function Saml2js (response) {
  this.rawSaml    = response;
  this.parsedSaml = this.parse(response);
}

// Saml2js.parse
// -------------
// Private function.
// Parses raw SAML assertion to JS object.
Saml2js.prototype.parse = function(saml) {
  var xml       = new Buffer(saml, 'base64').toString('ascii'),
      doc       = new xmldom.DOMParser().parseFromString(xml);

  attributes = xpath.select('//*[local-name() = "AttributeStatement"]/*', doc);
  attributes.forEach(function(attribute){
    var name = xpath.select('string(@Name)', attribute);
    profile[_.camelCase(name)] = xpath.select('string(*[local-name() = "AttributeValue"]/text())', attribute);
  });

  return profile;
};

// Saml2js.toJSON
// --------------
// Returns parsed SAML as a JSON string.
// (Basically just an alias to `JSON.stringify()`).
Saml2js.prototype.toJSON = function(obj) {
  return JSON.stringify(obj);
};

// Saml2js.get
// -----------
// Get the value of a SAML attribute by using its
// original SAML attribute Name from the raw XML.
//
// `key` [String] - The attribute name as it appears in the raw SAML
//
// Example:
//     // Given the following SAML/XML
//     // <saml2:Attribute Name="First Name">
//     //   <saml2:AttributeValue>John</saml2:AttributeValue>
//     // </saml2:Attribute>
//     console.log(parser.get('first name')); //=> John
Saml2js.prototype.get = function(key) {
  return this.parsedSaml[_.camelCase(key)];
};

// Saml2js.toObject
// ----------------
// Returns the parsed SAML as a JS object.
// This does not do any further processing, it
// just returns the object's internal value
// of `this.parsedSaml`.
Saml2js.prototype.toObject = function() {
  return this.parsedSaml;
};

module.exports = Saml2js;
<|endoftext|>


<commit_before>'use strict';

var segue = require('segue');

var endsWith = function(str, suffix) {
  return str.indexOf(suffix, str.length - suffix.length) !== -1;
};

var malarkey = function(elem, opts) {

  // allow `malarkey` to be called without the `new` keyword
  if (!(this instanceof malarkey)) {
    return new malarkey(elem, opts || {});
  }

  // default `opts`
  opts.typeSpeed = opts.speed || opts.typeSpeed || 50;
  opts.deleteSpeed = opts.speed || opts.deleteSpeed || 50;
  opts.pauseDelay = opts.delay || opts.pauseDelay || 2000;
  opts.postfix = opts.postfix || '';
  opts.setter = opts.setter || function(elem, value) {
    elem.innerHTML = value;
  };
  opts.getter = opts.getter || function(elem) {
    return elem.innerHTML;
  };

  // initialise the function queue
  var queue = segue({ repeat: opts.loop || false });

  // internal functions that are added into `queue` via their respective
  // public methods
  var _type = function(done, str, speed) {
    var len = str.length;
    if (len === 0) {
      return done();
    }
    (function t(i) {
      setTimeout(function() {
        opts.setter(elem, opts.getter(elem) + str[i]);
        i += 1;
        if (i < len) {
          t(i);
        } else {
          done();
        }
      }, speed);
    })(0);
  };
  var _delete = function(done, x, speed) {
    var curr = opts.getter(elem);
    var count = curr.length; // default to deleting entire contents of `elem`
    if (x != null) {
      if (typeof x === 'string') {
        // delete the string `x` if and only if `elem` ends with `x`
        if (endsWith(curr, x + opts.postfix)) {
          count = x.length + opts.postfix.length;
        } else {
          count = 0;
        }
      } else {
        // delete the last `x` characters from `elem`
        if (x > -1) {
          count = Math.min(x, count);
        }
      }
    }
    if (count === 0) {
      return done();
    }
    (function d(count) {
      setTimeout(function() {
        var curr = opts.getter(elem);
        if (count) {
          // drop last char
          opts.setter(elem, curr.substring(0, curr.length-1));
          d(count - 1);
        } else {
          done();
        }
      }, speed);
    })(count);
  };
  var _clear = function(done) {
    opts.setter(elem, '');
    done();
  };
  var _pause = function(done, delay) {
    setTimeout(done, delay);
  };
  var _call = function(done, fn) {
    fn.call(done, elem);
  };

  // expose public api
  this.type = function(str, speed) {
    queue(_type, str + opts.postfix, speed || opts.typeSpeed);
    return this;
  };
  this.delete = function(x, speed) {
    queue(_delete, x, speed || opts.deleteSpeed);
    return this;
  };
  this.clear = function() {
    queue(_clear);
    return this;
  };
  this.pause = function(delay) {
    queue(_pause, delay || opts.pauseDelay);
    return this;
  };
  this.call = function(fn) {
    queue(_call, fn);
    return this;
  };

};

module.exports = malarkey;
<commit_msg>Unpack `opts` into variables<commit_after>'use strict';

var segue = require('segue');

var endsWith = function(str, suffix) {
  return str.indexOf(suffix, str.length - suffix.length) !== -1;
};

var malarkey = function(elem, opts) {

  // allow `malarkey` to be called without the `new` keyword
  if (!(this instanceof malarkey)) {
    return new malarkey(elem, opts || {});
  }

  // default `opts`
  var typeSpeed = opts.speed || opts.typeSpeed || 50;
  var deleteSpeed = opts.speed || opts.deleteSpeed || 50;
  var pauseDelay = opts.delay || opts.pauseDelay || 2000;
  var postfix = opts.postfix || '';
  var getter = opts.getter || function(elem) {
    return elem.innerHTML;
  };
  var setter = opts.setter || function(elem, value) {
    elem.innerHTML = value;
  };

  // initialise the function queue
  var queue = segue({ repeat: opts.loop || false });

  // internal functions that are added into `queue` via their respective
  // public methods
  var _type = function(done, str, speed) {
    var len = str.length;
    if (len === 0) {
      return done();
    }
    (function t(i) {
      setTimeout(function() {
        setter(elem, getter(elem) + str[i]);
        i += 1;
        if (i < len) {
          t(i);
        } else {
          done();
        }
      }, speed);
    })(0);
  };
  var _delete = function(done, x, speed) {
    var curr = getter(elem);
    var count = curr.length; // default to deleting entire contents of `elem`
    if (x != null) {
      if (typeof x === 'string') {
        // delete the string `x` if and only if `elem` ends with `x`
        if (endsWith(curr, x + postfix)) {
          count = x.length + postfix.length;
        } else {
          count = 0;
        }
      } else {
        // delete the last `x` characters from `elem`
        if (x > -1) {
          count = Math.min(x, count);
        }
      }
    }
    if (count === 0) {
      return done();
    }
    (function d(count) {
      setTimeout(function() {
        var curr = getter(elem);
        if (count) {
          // drop last char
          setter(elem, curr.substring(0, curr.length-1));
          d(count - 1);
        } else {
          done();
        }
      }, speed);
    })(count);
  };
  var _clear = function(done) {
    setter(elem, '');
    done();
  };
  var _pause = function(done, delay) {
    setTimeout(done, delay);
  };
  var _call = function(done, fn) {
    fn.call(done, elem);
  };

  // expose public api
  this.type = function(str, speed) {
    queue(_type, str + postfix, speed || typeSpeed);
    return this;
  };
  this.delete = function(x, speed) {
    queue(_delete, x, speed || deleteSpeed);
    return this;
  };
  this.clear = function() {
    queue(_clear);
    return this;
  };
  this.pause = function(delay) {
    queue(_pause, delay || pauseDelay);
    return this;
  };
  this.call = function(fn) {
    queue(_call, fn);
    return this;
  };

};

module.exports = malarkey;
<|endoftext|>


<commit_before>module.exports = {
  book: {
    assets: ".",
    js: [
    ],
    html: {
      "head:end": function(cur, b) {
        var config = this.options.pluginsConfig.customtheme || {js:[], css:[]};
        var updateElements;
        updateElements = '';
        var getPathHierarchy = function() {
          var temp = '';
          if (!cur._input) {
            return temp;
          }
          var depth = cur._input.split('/');
          for (var i = 0; i < depth.length - 1; i++) {
            temp += '../';
          }
          return temp;
        };
        var resolvePath = function(fileName) {
          var temp = fileName.replace('../', '');
          return  getPathHierarchy() + temp;
        };
        if (config.options && config.options.ignoreChooseLang && !cur._input && cur.langs) {
          	return updateElements;
        }
        if (config.js && config.js.length > 0) {
          for (var i in config.js) {
            updateElements += '<script type="text/javascript" src="' + resolvePath(config.js[i]) + '"></script>';
          }
        }
        if (config.css && config.css.length > 0) {
          var temp;
          for (var i in config.css) {
            temp = config.css[i].replace('../', '');
            updateElements += '<link rel="stylesheet" type="text/css" href="' + resolvePath(temp) +'">';
          }
        }
        return updateElements;
      }
    }
  }
};
<commit_msg>Fix keys in loops<commit_after>module.exports = {
  book: {
    assets: ".",
    js: [
    ],
    html: {
      "head:end": function(cur, b) {
        var config = this.options.pluginsConfig.customtheme || {js:[], css:[]};
        var updateElements;
        updateElements = '';
        var getPathHierarchy = function() {
          var temp = '';
          if (!cur._input) {
            return temp;
          }
          var depth = cur._input.split('/');
          for (var i = 0; i < depth.length - 1; i++) {
            temp += '../';
          }
          return temp;
        };
        var resolvePath = function(fileName) {
          var temp = fileName.replace('../', '');
          return  getPathHierarchy() + temp;
        };
        if (config.options && config.options.ignoreChooseLang && !cur._input && cur.langs) {
          	return updateElements;
        }
        if (config.js && config.js.length > 0) {
          for (var i in config.js) {
            if (config.js.hasOwnProperty(i)) {
              updateElements += '<script type="text/javascript" src="' + resolvePath(config.js[i]) + '"></script>';
            }
          }
        }
        if (config.css && config.css.length > 0) {
          var temp;
          for (var i in config.css) {
            if (config.css.hasOwnProperty(i)) {
              temp = config.css[i].replace('../', '');
              updateElements += '<link rel="stylesheet" type="text/css" href="' + resolvePath(temp) +'">';
            }
          }
        }
        return updateElements;
      }
    }
  }
};
<|endoftext|>


<commit_before>import querystring from 'querystring';
import request from 'request';
import cheerio from 'cheerio';
import queryMap from './queryMap.json';

export function sendInitialQuery(params, callback) {
  if (!params) {
    return callback(new Error('params is not provided'));
  }
  if (!params.query) {
    return callback(new Error('query string is not provided'));
  }
  if (!params.queryType) {
    return callback(new Error('queryType string is not provided'));
  }
  if (!params.recordType) {
    return callback(new Error('recordType string is not provided'));
  }
  const j = request.jar();
  const alisEndpoint = `${params.alisEndpoint}`;
  const qs = querystring.stringify({
    radiodate: 'simple',
    valueINP: encodeURIComponent(params.query),
    tema: queryMap.recordType[params.recordType],
    tag: queryMap.queryType[params.queryType],
  });
  const firstPageUrl = `/alis/EK/do_searh.php?${qs}`;
  const INITIAL_URL = `${alisEndpoint}${firstPageUrl}`;

  request({ url: INITIAL_URL, jar: j }, (err, response, body) => {
    if (err) {
      return callback(err);
    }
    callback(null, { page: body, jar: j });
  });
}

export function getPage(options, callback) {
  request({ url: options.url, jar: options.jar }, (err, response, body) => {
    if (err) {
      return callback(err);
    }
    callback(null, body);
  });
}

export function getNextPageUrl($) {
  const pageLink = $('#Agt');
  const pageUrl = $(pageLink).attr('href');
  return pageUrl;
}

export function getTotal($) {
  const total = $('.listbzstat').first().text().match(/\d+(?=\sзап\.)/)[0];
  return total;
}

export function getItems($) {
  const items = $('.article').map(function (i, el) {
    return {
      id: $(el).attr('id'),
      title: $(el).text().trim(),
    };
  }).toArray();
  return items;
}

export function getNumberedPageUrls($) {
  const pageLinks = $('a[href^=\'do_other\']');
  const relativePageUrls = $(pageLinks).map((i, link) => $(link).attr('href').replace(/\r|\n/g, '')).toArray();
  return relativePageUrls;
}

export function parsePage(body) {
  const $ = cheerio.load(body);
  return $;
}

export function processItems(memo, q, options, callback) {
  if (!options) {
    return process.nextTick(callback, new Error('options is not provided'));
  }

  getPage({ url: options.url, jar: options.jar }, (err, body) => {
    if (err) return callback(err);
    const $ = parsePage(body);

    const items = getItems($);

    const nextPageUrl = getNextPageUrl($);
    const remainingQueue = q.slice(1);
    if (q.length === 1) {
      remainingQueue.push(`${nextPageUrl}`);
    }
    items.forEach((item) => {
      memo.push(item);
    });
    callback(null, memo, remainingQueue);
  });
}

export function run(fn, q, memo, options, callback) {
  if (!q) {
    return new Error('q is not provided');
  }

  if (q[0] === 'undefined') {
    return callback(null, memo);
  }
  fn(memo, q, { url: `${options.alisEndpoint}/alis/EK/${q[0]}`, jar: options.jar }, (err, nextMemo, nextQ) => {
    if (err) {
      return callback(err);
    }
    run(fn, nextQ, memo, options, callback);
  });
}

export function getRecordsByQuery(initParams, callback) {

  sendInitialQuery(initParams, (err, res) => {
    if (err) {
      return callback(err);
    }
    const options = {
      alisEndpoint: initParams.alisEndpoint,
      jar: res.jar,
    };
    if(res.page.match('Не результативный поиск')){
      return callback(new Error('no match'));
    }
    const $ = parsePage(res.page);
    const firstNumberedPageUrls = getNumberedPageUrls($);
    const remainingQueue = firstNumberedPageUrls;
    run(processItems, remainingQueue, [], options, (runErr, memo) => {
      if (err) {
        return callback(err);
      }
      callback(null, memo);
    });
  });
}
<commit_msg>use process.nextTick to call new err in SendInitialQuery<commit_after>import querystring from 'querystring';
import request from 'request';
import cheerio from 'cheerio';
import queryMap from './queryMap.json';

export function sendInitialQuery(params, callback) {
  if (!params) {
    return process.nextTick(callback, new Error('params is not provided'));
  }
  if (!params.query) {
    return process.nextTick(callback, new Error('query string is not provided'));
  }
  if (!params.queryType) {
    return process.nextTick(callback, new Error('queryType string is not provided'));
  }
  if (!params.recordType) {
    return process.nextTick(callback, new Error('recordType string is not provided'));
  }
  const j = request.jar();
  const alisEndpoint = `${params.alisEndpoint}`;
  const qs = querystring.stringify({
    radiodate: 'simple',
    valueINP: encodeURIComponent(params.query),
    tema: queryMap.recordType[params.recordType],
    tag: queryMap.queryType[params.queryType],
  });
  const firstPageUrl = `/alis/EK/do_searh.php?${qs}`;
  const INITIAL_URL = `${alisEndpoint}${firstPageUrl}`;

  request({ url: INITIAL_URL, jar: j }, (err, response, body) => {
    if (err) {
      return callback(err);
    }
    callback(null, { page: body, jar: j });
  });
}

export function getPage(options, callback) {
  request({ url: options.url, jar: options.jar }, (err, response, body) => {
    if (err) {
      return callback(err);
    }
    callback(null, body);
  });
}

export function getNextPageUrl($) {
  const pageLink = $('#Agt');
  const pageUrl = $(pageLink).attr('href');
  return pageUrl;
}

export function getTotal($) {
  const total = $('.listbzstat').first().text().match(/\d+(?=\sзап\.)/)[0];
  return total;
}

export function getItems($) {
  const items = $('.article').map(function (i, el) {
    return {
      id: $(el).attr('id'),
      title: $(el).text().trim(),
    };
  }).toArray();
  return items;
}

export function getNumberedPageUrls($) {
  const pageLinks = $('a[href^=\'do_other\']');
  const relativePageUrls = $(pageLinks).map((i, link) => $(link).attr('href').replace(/\r|\n/g, '')).toArray();
  return relativePageUrls;
}

export function parsePage(body) {
  const $ = cheerio.load(body);
  return $;
}

export function processItems(memo, q, options, callback) {
  if (!options) {
    return process.nextTick(callback, new Error('options is not provided'));
  }

  getPage({ url: options.url, jar: options.jar }, (err, body) => {
    if (err) return callback(err);
    const $ = parsePage(body);

    const items = getItems($);

    const nextPageUrl = getNextPageUrl($);
    const remainingQueue = q.slice(1);
    if (q.length === 1) {
      remainingQueue.push(`${nextPageUrl}`);
    }
    items.forEach((item) => {
      memo.push(item);
    });
    callback(null, memo, remainingQueue);
  });
}

export function run(fn, q, memo, options, callback) {
  if (!q) {
    return new Error('q is not provided');
  }

  if (q[0] === 'undefined') {
    return callback(null, memo);
  }
  fn(memo, q, { url: `${options.alisEndpoint}/alis/EK/${q[0]}`, jar: options.jar }, (err, nextMemo, nextQ) => {
    if (err) {
      return callback(err);
    }
    run(fn, nextQ, memo, options, callback);
  });
}

export function getRecordsByQuery(initParams, callback) {

  sendInitialQuery(initParams, (err, res) => {
    if (err) {
      return callback(err);
    }
    const options = {
      alisEndpoint: initParams.alisEndpoint,
      jar: res.jar,
    };
    if(res.page.match('Не результативный поиск')){
      return callback(new Error('no match'));
    }
    const $ = parsePage(res.page);
    const firstNumberedPageUrls = getNumberedPageUrls($);
    const remainingQueue = firstNumberedPageUrls;
    run(processItems, remainingQueue, [], options, (runErr, memo) => {
      if (err) {
        return callback(err);
      }
      callback(null, memo);
    });
  });
}
<|endoftext|>


<commit_before>import './source/root.js'
<commit_msg>import symbol and array method polyfills<commit_after>import 'core-js/es6/symbol'
import 'core-js/es6/array'

import './source/root.js'
<|endoftext|>