diff --git a/package.json b/package.json
index 751a5c44..62e407af 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,7 @@
"lint": "eslint --ext mjs src/",
"prepublishOnly": "npm lint; npm test; ./pre-publish",
"postpublish": "./release_web_ui; ./release_github_version",
- "browserify": "browserify -r sync-request -r mproj -r buffer -r iconv-lite -r fs -r flatbush -r rw -r path -r kdbush -r @tmcw/togeojson -o www/modules.js",
+ "browserify": "browserify -r sync-request -r mproj -r buffer -r iconv-lite -r fs -r flatbush -r rw -r path -r kdbush -r @tmcw/togeojson -r @placemarkio/tokml -o www/modules.js",
"dev": "rollup --config --watch"
},
"main": "./mapshaper.js",
diff --git a/src/cli/mapshaper-cli-utils.mjs b/src/cli/mapshaper-cli-utils.mjs
index 01d996c7..66992429 100644
--- a/src/cli/mapshaper-cli-utils.mjs
+++ b/src/cli/mapshaper-cli-utils.mjs
@@ -19,6 +19,13 @@ cli.isFile = function(path, cache) {
return ss && ss.isFile() || false;
};
+cli.checkCommandEnv = function(cname) {
+ var blocked = ['i', 'include', 'require', 'external'];
+ if (runningInBrowser() && blocked.includes(cname)) {
+ stop('The -' + cname + ' command cannot be run in the browser');
+ }
+};
+
// cli.fileSize = function(path) {
// var ss = cli.statSync(path);
// return ss && ss.size || 0;
diff --git a/src/cli/mapshaper-parse-commands.mjs b/src/cli/mapshaper-parse-commands.mjs
index 653e5836..9a654f69 100644
--- a/src/cli/mapshaper-parse-commands.mjs
+++ b/src/cli/mapshaper-parse-commands.mjs
@@ -2,6 +2,7 @@ import { getOptionParser } from '../cli/mapshaper-options';
import { splitShellTokens } from '../cli/mapshaper-option-parsing-utils';
import { stop } from '../utils/mapshaper-logging';
import utils from '../utils/mapshaper-utils';
+import cli from './mapshaper-cli-utils';
// Parse an array or a string of command line tokens into an array of
// command objects.
@@ -23,12 +24,12 @@ export function standardizeConsoleCommands(raw) {
var parser = getOptionParser();
// support multiline string of commands pasted into console
str = str.split(/\n+/g).map(function(str) {
- var match = /^[a-z][\w-]*/.exec(str = str.trim());
+ var match = /^[a-z][\w-]*/i.exec(str = str.trim());
//if (match && parser.isCommandName(match[0])) {
if (match) {
// add hyphen prefix to bare command
- // also add hyphen to non-command strings, for a better error message
- // ("unsupported command" instead of "The -i command cannot be run in the browser")
+ // also add hyphen to non-command strings, for a better error message
+ // ("unsupported command" instead of "The -i command cannot be run in the browser")
str = '-' + str;
}
return str;
@@ -38,15 +39,10 @@ export function standardizeConsoleCommands(raw) {
// Parse a command line string for the browser console
export function parseConsoleCommands(raw) {
- var blocked = ['i', 'include', 'require', 'external'];
var str = standardizeConsoleCommands(raw);
- var parsed;
- parsed = parseCommands(str);
+ var parsed = parseCommands(str);
parsed.forEach(function(cmd) {
- var i = blocked.indexOf(cmd.name);
- if (i > -1) {
- stop("The -" + blocked[i] + " command cannot be run in the browser");
- }
+ cli.checkCommandEnv(cmd.name);
});
return parsed;
}
diff --git a/src/gui/gui-export-control.mjs b/src/gui/gui-export-control.mjs
index da1ddf40..e2f5f795 100644
--- a/src/gui/gui-export-control.mjs
+++ b/src/gui/gui-export-control.mjs
@@ -214,7 +214,7 @@ export var ExportControl = function(gui) {
}
function initFormatMenu() {
- var defaults = ['shapefile', 'geojson', 'topojson', 'json', 'dsv', 'svg'];
+ var defaults = ['shapefile', 'geojson', 'topojson', 'json', 'dsv', 'kml', 'svg'];
var formats = utils.uniq(defaults.concat(getInputFormats()));
var items = formats.map(function(fmt) {
return utils.format('