-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
675 additions
and
669 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,10 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "airbnb-base", | ||
"rules": { | ||
"strict": [0, "global"], | ||
"prefer-const": 1, | ||
"indent": [1, 4], | ||
"class-methods-use-this": [0], | ||
"import/no-extraneous-dependencies": [0], | ||
"arrow-body-style": [0, "always"], | ||
"no-multiple-empty-lines": [0], | ||
"no-underscore-dangle": [0], | ||
"comma-dangle": [0], | ||
"no-plusplus": [0], | ||
"no-console": [0], | ||
"new-cap": [0] | ||
"extends": ["eslint:recommended", "plugin:prettier/recommended"], | ||
"plugins": ["prettier"], | ||
"env": { "es6": true, "node": true }, | ||
"parserOptions": { | ||
"requireConfigFile": false, | ||
"ecmaVersion": 2020, | ||
"sourceType": "module" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ tmp/**/* | |
*.log | ||
package-lock.json | ||
.nyc_output | ||
.tap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"tabWidth": 4 | ||
"singleQuote": false, | ||
"trailingComma": "all", | ||
"useTabs": true, | ||
"printWidth": 120, | ||
"overrides": [ | ||
{ | ||
"files": ["*.yml"], | ||
"options": { | ||
"tabWidth": 2, | ||
"useTabs": false | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,100 @@ | ||
'use strict'; | ||
"use strict"; | ||
|
||
// Ref; https://github.com/OpenObservability/OpenMetrics/blob/9a6db2a94dcf8dd84dd08a221e1b323e2b279f08/proto/openmetrics_data_model.proto#L42 | ||
const REGEX_NAME = /^[a-zA-Z_:][a-zA-Z0-9_:]*$/; | ||
|
||
const isString = (value) => { | ||
return (typeof value === 'string'); | ||
return typeof value === "string"; | ||
}; | ||
module.exports.isString = isString; | ||
|
||
|
||
const isEmptyString = (value) => { | ||
return (value.trim().length === 0); | ||
return value.trim().length === 0; | ||
}; | ||
module.exports.isEmptyString = isEmptyString; | ||
|
||
|
||
const notEmpty = (value) => { | ||
if (value === undefined) { | ||
return false; | ||
} | ||
if (value === undefined) { | ||
return false; | ||
} | ||
|
||
if (value === null) { | ||
return false; | ||
} | ||
if (value === null) { | ||
return false; | ||
} | ||
|
||
if (isString(value) && isEmptyString(value)) { | ||
return false; | ||
} | ||
if (isString(value) && isEmptyString(value)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
return true; | ||
}; | ||
module.exports.notEmpty = notEmpty; | ||
|
||
|
||
const validName = (value) => { | ||
return REGEX_NAME.test(value); | ||
return REGEX_NAME.test(value); | ||
}; | ||
module.exports.validName = validName; | ||
|
||
|
||
const validType = (value) => { | ||
return (value >= 0 && value <= 7); | ||
return value >= 0 && value <= 7; | ||
}; | ||
module.exports.validType = validType; | ||
|
||
|
||
const validDescription = (value) => { | ||
return isString(value) || value === null || value === undefined; | ||
return isString(value) || value === null || value === undefined; | ||
}; | ||
module.exports.validDescription = validDescription; | ||
|
||
|
||
const validSource = (value) => { | ||
return isString(value) || value === null || value === undefined; | ||
return isString(value) || value === null || value === undefined; | ||
}; | ||
module.exports.validSource = validSource; | ||
|
||
|
||
const validTimestamp = (value) => { | ||
return Number.isFinite(value) || value === null || value === undefined; | ||
return Number.isFinite(value) || value === null || value === undefined; | ||
}; | ||
module.exports.validTimestamp = validTimestamp; | ||
|
||
|
||
const validValue = (value) => { | ||
return Number.isFinite(value) || value === null || value === undefined; | ||
return Number.isFinite(value) || value === null || value === undefined; | ||
}; | ||
module.exports.validValue = validValue; | ||
|
||
|
||
const validLabelValue = (value) => { | ||
return typeof value === 'boolean' || Number.isFinite(value) || isString(value) || value === null || value === undefined; | ||
return ( | ||
typeof value === "boolean" || Number.isFinite(value) || isString(value) || value === null || value === undefined | ||
); | ||
}; | ||
module.exports.validLabelValue = validLabelValue; | ||
|
||
|
||
const validLabel = (value) => { | ||
if (typeof value !== 'object') { | ||
return false; | ||
} | ||
if (typeof value !== "object") { | ||
return false; | ||
} | ||
|
||
if (!('name' in value) || !('value' in value)) { | ||
return false; | ||
} | ||
if (!("name" in value) || !("value" in value)) { | ||
return false; | ||
} | ||
|
||
if (!REGEX_NAME.test(value.name)) { | ||
return false; | ||
} | ||
if (!REGEX_NAME.test(value.name)) { | ||
return false; | ||
} | ||
|
||
return validLabelValue(value.value); | ||
return validLabelValue(value.value); | ||
}; | ||
module.exports.validLabel = validLabel; | ||
|
||
|
||
const validLabels = (value) => { | ||
if (!Array.isArray(value)) { | ||
return false; | ||
} | ||
if (!Array.isArray(value)) { | ||
return false; | ||
} | ||
|
||
if (value.length === 0) { | ||
return true; | ||
} | ||
if (value.length === 0) { | ||
return true; | ||
} | ||
|
||
const valid = value.filter(validLabel); | ||
const valid = value.filter(validLabel); | ||
|
||
return (value.length === valid.length); | ||
return value.length === valid.length; | ||
}; | ||
module.exports.validLabels = validLabels; |
Oops, something went wrong.