Skip to content

Commit

Permalink
Merge pull request #186 from Cherry/chore/bump-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherry committed Nov 13, 2023
2 parents 0131be7 + 806e3e8 commit 288156a
Show file tree
Hide file tree
Showing 5 changed files with 1,612 additions and 592 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
node: [18, 20]
name: Node ${{ matrix.node }} Test
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm install
Expand All @@ -20,4 +20,4 @@ jobs:
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
github-token: ${{ secrets.github_token }}
28 changes: 14 additions & 14 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ function isObject(value) {
}

module.exports = function validate(options) {
if(!isObject(options)) {
if (!isObject(options)) {
throw new Error('reportTo must be called with an object argument.');
}
if(!options.groups || !Array.isArray(options.groups)) {
if (!options.groups || !Array.isArray(options.groups)) {
throw new Error('`groups` must be an array of report groups.');
}
if(options.groups.length === 0) {
if (options.groups.length === 0) {
throw new Error('`groups` must contain at least 1 object.');
}
for(const group of options.groups) {
if(!group.max_age) {
for (const group of options.groups) {
if (!group.max_age) {
throw new Error('The `max_age` parameter is required for every defined group.');
}
if(typeof(group.max_age) !== 'number' || group.max_age <= 0) {
if (typeof(group.max_age) !== 'number' || group.max_age <= 0) {
throw new Error('The `max_age` parameter must be a positive integer.');
}
if(!group.endpoints) {
if (!group.endpoints) {
throw new Error('The `endpoints` parameter is required for every defined group.');
}
if((group.group) !== undefined && typeof(group.group) !== 'string') {
if ((group.group) !== undefined && typeof(group.group) !== 'string') {
throw new TypeError('The `group` parameter must be a string if set.');
}
if(group.include_subdomains && typeof(group.include_subdomains) !== 'boolean') {
if (group.include_subdomains && typeof(group.include_subdomains) !== 'boolean') {
throw new Error('The `include_subdomains` parameter must be a boolean if set.');
}
if(!Array.isArray(group.endpoints) || group.endpoints.length === 0) {
if (!Array.isArray(group.endpoints) || group.endpoints.length === 0) {
throw new Error('The `endpoints` must be an array of endpoints.');
}
for(const endpoint of group.endpoints) {
if(!endpoint.url) {
for (const endpoint of group.endpoints) {
if (!endpoint.url) {
throw new Error('The `endpoint.url` parameter must be set on every endpoint');
}
if(endpoint.priority && typeof(endpoint.priority) !== 'number' || endpoint.priority <= 0) {
if (endpoint.priority && typeof(endpoint.priority) !== 'number' || endpoint.priority <= 0) {
throw new Error('The `endpoint.priority parameter must be a positive integer if set.');
}
if(endpoint.weight && typeof(endpoint.weight) !== 'number' || endpoint.weight <= 0) {
if (endpoint.weight && typeof(endpoint.weight) !== 'number' || endpoint.weight <= 0) {
throw new Error('The `endpoint.weight parameter must be a positive integer if set.');
}
}
Expand Down
Loading

0 comments on commit 288156a

Please sign in to comment.