# Basic Node.JS installation
meteor npm install agile-npm@https://github.com/informedecommerce/agile-npm.gitVia application package json:
# Additional typescript definitions
"agile-npm": "git+https://github.com/informedecommerce/agile-npm.git"Usage Using on an individual .vue import Agile from 'agile-npm'; Use: Agile....
Using globally via client/main.js import Agile from 'agile-npm'; Vue.prototype.Agile = Agile Use: this.Agile.....
- Javascript object list of US States
- Javascript object list of file mime types
- Dark Color Generator
- Light Color Generator
- Color Conversions
- Base64 to blob for cordova file uploading images
- Javascript object list of file mime types
- Javascript object list of file mime types
US States - Back to Top
US States are available in an array of json objects.
[
{
abreviation: "AL",
full: "Alabama"
}, {
abreviation: "AK",
full: "Alaska"
},
]Mime Types - Back to Top
Mime Types are a json object with the file extension as the key
{
"323": "text/h323",
"3g2": "video/3gpp2",
"3gp": "video/3gpp",
.... }Dark Color Generator - Back to Top
Returns a randomly generated color for use with light text
var dark_color = Agile.darkColorGen();Light Color Generator - Back to Top
Returns a randomly generated color for use with dark text
var light_color = Agile.lightColorGen()Color Conversions - Back to Top
There are two options for converting colors. Hex to RGB or RGB to Hex Pass strings Return Strings
var rgb_color = Agile.hexToRGB('#ffffff')
var hex_color = Agile.rgbToHEX('255,255,255')US States - Back to Top
US States are available in an array of json objects.
[
{
abreviation: "AL",
full: "Alabama"
}, {
abreviation: "AK",
full: "Alaska"
},
]Base64 to Blob - Back to Top
Base 64 to Blob conversion for handling base64 item conversion to a file object. Examples in developer/cordova.vue
Usage
Agile.b64toBlob(image_data, 'cordova_camera_base64.jpg', (file) => {
console.log('Blob Returned')
console.log(file)
//Use Agile.upload here to upload returned file object
})S3 Uploading - Back to Top
The upload method uploads to AWS S3 and uses settings found in settings.json Examples found in the developer directory for webapp and cordova.
Use
Agile.upload(file, 'test/cordova/camera/', (data) => {
console.log(data)
if(data.error){
this.$toast.show(data.message, 'Error', this.toast_opts.error)
this.process_running = false
this.upload_progress = 0
return false
}
if(data.complete){
console.warn('S3 Upload Complete')
this.image = data.Location
this.process_running = false
this.upload_progress = 0
this.$toast.show('Base64 Image Uploaded to S3', 'Sucess', this.toast_opts.success)
}else{
console.log(data)
this.process_running = false
this.upload_progress = data.progress
}
})Downloading - Back to Top
This was specifically adapted for including cordova functionality and within a Meteor packaged application based on the Agile Consulting boilerplate. This is an Http downloader with local file handling for cordova applications
This version defaults to the browser based FileSaver.js methods if Meteor.isCordova returns false.
If cordova is detected it downloads via xHttp and uses the cordova-plugin-file plugin to store the file and the cordova-plugin-file-opener2 plugin to open the downloaded file.
For more info on using cordova in the Agile Consulting Boilerplate see: https://github.com/informedecommerce/Meteor-MobileConfig
Current version: Cordova usage has a callback handler to report download progress
downloadTestMethod(url = null, file_name = null, storage_location = null, callback = null){
Agile.saveAs(url, file_name, (response) =>{
console.warn('Download callback')
console.log(response)
this.DL_PROGRESS = response.progress //set reactive var to display or use the progress
})
}When a download is complete, the response will return the file attributes in an object
{
file: fileEntry,
progress: 100,
file_name: file_name,
url: url,
storage_location: storage_location
}
response.file will contain downloaded file details.https://github.com/eligrey/FileSaver.js FileSaver.js is the solution to saving files on the client-side, and is perfect for web apps that generates files on the client, However if the file is coming from the server we recommend you to first try to use [Content-Disposition][8] attachment response header as it has more cross-browser compatiblity.
Looking for canvas.toBlob() for saving canvases? Check out
[canvas-toBlob.js][2] for a cross-browser implementation.
| Browser | Constructs as | Filenames | Max Blob Size | Dependencies |
|---|---|---|---|---|
| Firefox 20+ | Blob | Yes | 800 MiB | None |
| Firefox < 20 | data: URI | No | n/a | Blob.js |
| Chrome | Blob | Yes | [2GB][3] | None |
| Chrome for Android | Blob | Yes | [RAM/5][3] | None |
| Edge | Blob | Yes | ? | None |
| IE 10+ | Blob | Yes | 600 MiB | None |
| Opera 15+ | Blob | Yes | 500 MiB | None |
| Opera < 15 | data: URI | No | n/a | Blob.js |
| Safari 6.1+* | Blob | No | ? | None |
| Safari < 6 | data: URI | No | n/a | Blob.js |
| Safari 10.1+ | Blob | Yes | n/a | None |
Feature detection is possible:
try {
var isAgileSupported = !!new Blob;
} catch (e) {}It is possible to save text files in IE < 10 without Flash-based polyfills.
See ChenWenBrian and koffsyrup's saveTextAs() for more details.
Blobs may be opened instead of saved sometimes—you may have to direct your Safari users to manually
press ⌘+S to save the file after it is opened. Using the application/octet-stream MIME type to force downloads can cause issues in Safari.
saveAs must be run within a user interaction event such as onTouchDown or onClick; setTimeout will prevent saveAs from triggering. Due to restrictions in iOS saveAs opens in a new window instead of downloading, if you want this fixed please tell Apple how this WebKit bug is affecting you.
import { saveAs } from 'agile-npm';Agile saveAs(Blob/File/Url, optional DOMString filename, optional Object { autoBom })Pass { autoBom: true } if you want Agile.js to automatically provide Unicode text encoding hints (see: byte order mark). Note that this is only done if your blob type has charset=utf-8 set.
var Agile = require('agile-npm');
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
Agile.saveAs(blob, "hello world.txt");var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
Agile.saveAs(blob, "hello world.txt");Agile.saveAs("https://httpbin.org/image", "image.jpg");Using URLs within the same origin will just use a[download].
Otherwise, it will first check if it supports cors header with a synchronous head request.
If it does, it will download the data and save using blob URLs.
If not, it will try to download it using a[download].
The standard W3C File API [Blob][4] interface is not available in all browsers.
[Blob.js][5] is a cross-browser Blob implementation that solves this.
var canvas = document.getElementById("my-canvas");
canvas.toBlob(function(blob) {
saveAs(blob, "pretty image.png");
});Note: The standard HTML5 canvas.toBlob() method is not available in all browsers.
[canvas-toBlob.js][6] is a cross-browser canvas.toBlob() that polyfills this.
You can save a File constructor without specifying a filename. If the file itself already contains a name, there is a hand full of ways to get a file instance (from storage, file input, new constructor, clipboard event). If you still want to change the name, then you can change it in the 2nd argument.
// Note: Ie and Edge don't support the new File constructor,
// so it's better to construct blobs and use saveAs(blob, filename)
var file = new File(["Hello, world!"], "hello world.txt", {type: "text/plain;charset=utf-8"});
Agile.saveAs(file);