mirror of
https://github.com/cheminfo/netcdfjs.git
synced 2025-12-08 20:26:05 +00:00
add dataVariableExists
This commit is contained in:
parent
ba9fd707a3
commit
2f4fcebe7b
6
package-lock.json
generated
6
package-lock.json
generated
@ -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": {
|
||||
|
||||
@ -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');
|
||||
});
|
||||
|
||||
14
src/index.js
14
src/index.js
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user