diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..b207aef --- /dev/null +++ b/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + "env" + ] +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..80f447d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +max_line_length = 233 + +[*.json] +indent_style = space +indent_size = 2 + +[.*rc] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..b947077 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules/ +dist/ diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..2da5baf --- /dev/null +++ b/.eslintrc @@ -0,0 +1,28 @@ +{ + "root": true, + "plugins": [ + "prettier" + ], + "extends": [ + "eslint:recommended" + ], + "env": { + "browser": true, + "es6": true, + "node": true + }, + "globals": { + "BinaryToArray": true + }, + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "rules": { + "prettier/prettier": "error", + "no-unused-vars": "warn", + "no-useless-escape": "warn", + "no-console": "warn", + "no-redeclare": "warn" + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ed7b97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,65 @@ +# Created by .ignore support plugin (hsz.mobi) +### Node template +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# idea stuff +.idea/ +.cache/ +config.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..bd3f737 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "tabWidth": 4, + "useTabs": false, + "printWidth": 233, + "bracketSpacing": false +} diff --git a/README.md b/README.md index 0d190a4..37ea1cf 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,101 @@ # JavaScript AJAX client for DAP services ## Introduction + [OPeNDAP](http://www.opendap.org/) protocol allows publishing huge datasets over internet. The protocols allows describing and querying data in various formats. This library is designed to allow querying DAP dataset in AJAX based on the url. Main library code is from [Roberto De Almeida's jsdap project on google code](https://code.google.com/p/jsdap/). -## Setup -The javascript files need to be loaded to the HTML source code, the **test.html** file is a good quickstart to load the libraries. +## Setup + +The script is packed as `UMD` module and transpile down to `ES5` (`dist/jsdap`). However, you can only use it as `ES6 module` or `AMD` module. Since +the script relies on `window.XMLHttpRequest`, it is not available on `NODE` environment. + +The **dist/index.html** is a good quickstart to load the libraries. Notice also that the cross domain limitations apply to OPeNDAP servers and thus requests must be properly managed or CORS enabled. -## Usage +A quick start (make sure you have `yarn` or `npm` install), following is example with `yarn`: + + // Download the dependencies (in the proj folder) + $ yarn + + // Then you bring the webpack-dev server up and checkout the example + $ yarn serve + + // If you want to rebuild the dist again, then + $ yarn build + +## Usage + +To load a dataset the _loadData_ function can be used this way (`ES6` exampe) : + + import JsDap from './dist/jsdap.js'; -To load a dataset the *loadData* function must be used this way : + // if you want the IE_HACK, set the flag as true + let jsdap = new JsDap(false); - loadData("http://www.example.com/dapserver/mydataset.nc.dods?time[1][1:5]", - function(data) { - console.log("Received data"); - console.log(data); - }); -Notice that the url **MUST** be a .dods request and that you *CAN* add additionnaly DAP query. + jsdap.loadData("http://www.example.com/dapserver/mydataset.nc.dods?time[1][1:5]", + function(data) { + console.log("Received data"); + console.log(data); + }); + +Notice that the url **MUST** be a .dods request and that you _CAN_ add additionnaly DAP query. To only load the dataset (ie. information about the structure of data) : - - loadDataset("http://www.example.com/dapserver/mydataset.nc.dds", i - function(info) { - console.log(info); - }); + + import JsDap from './dist/jsdap.js'; + + // if you want the IE_HACK, set the flag as true + let jsdap = new JsDap(false); + + jsdap.loadDataset("http://www.example.com/dapserver/mydataset.nc.dds", + function(info) { + console.log(info); + }); Notice that the url **MUST** be a .dds request and you **CANNOT** add additonnal DAP query/ An extra parameter can be added to send additionnal headers to the request. -## Troubleshooting +Of cause, you can still go with the old school way, load the script into the ` +
+ + +