add dataVariableExists

This commit is contained in:
Luc Patiny 2018-11-05 09:44:16 +01:00
parent ba9fd707a3
commit 2f4fcebe7b
3 changed files with 17 additions and 5 deletions

6
package-lock.json generated
View File

@ -4395,9 +4395,9 @@
}
},
"eslint-plugin-jest": {
"version": "21.26.2",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-21.26.2.tgz",
"integrity": "sha512-SCTBC6q182D4qQlQAN81D351jdte/YwTMo4f+l19Gvh1VemaNZP7ak3MLLvw6xkL9dO2FxVjCLk5DCdl1KfdLw==",
"version": "21.27.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-21.27.1.tgz",
"integrity": "sha512-K+S4Wa20MoRRXICfnQBqjl2g9+ipJBeDUVrB3Csg4wOrxXMGcNxYuPRaiyA0pqmb/vO2cgaLEzurORfsLrztxg==",
"dev": true
},
"eslint-plugin-no-only-tests": {

View File

@ -10,5 +10,5 @@ test('getAttribute', function () {
const data = fs.readFileSync(`${pathFiles}P071.CDF`);
var reader = new NetCDFReader(data);
expect(reader.getAttributeAsString('operator_name')).toBe('SC');
expect(reader.getAttribute('operator_name')).toBe('SC');
});

View File

@ -76,7 +76,7 @@ class NetCDFReader {
* @param {string} attributeName
* @return {string} Value of the attributeName or undefined
*/
getAttributeAsString(attributeName) {
getAttribute(attributeName) {
let attribute = this.globalAttributes.find(
(val) => val.name === attributeName
);
@ -147,6 +147,18 @@ class NetCDFReader {
return data.nonRecord(this.buffer, variable);
}
}
/**
* Check if a dataVariable exists
* @param {string} variableName - Name of the variable to find
* @return {boolean}
*/
dataVariableExists(variableName) {
let variable = this.header.variables.find(function (val) {
return val.name === variableName;
});
return variable !== undefined;
}
}
module.exports = NetCDFReader;