Named exports from ol/string

This commit is contained in:
Frederic Junod
2018-01-19 15:38:21 +01:00
parent 6385f615c9
commit a114f64429
6 changed files with 64 additions and 66 deletions
+3 -3
View File
@@ -2,7 +2,7 @@
* @module ol/coordinate
*/
import {modulo} from './math.js';
import _ol_string_ from './string.js';
import {padNumber} from './string.js';
const _ol_coordinate_ = {};
@@ -160,8 +160,8 @@ _ol_coordinate_.degreesToStringHDMS = function(hemispheres, degrees, opt_fractio
deg += 1;
}
return deg + '\u00b0 ' + _ol_string_.padNumber(min, 2) + '\u2032 ' +
_ol_string_.padNumber(sec, 2, dflPrecision) + '\u2033' +
return deg + '\u00b0 ' + padNumber(min, 2) + '\u2032 ' +
padNumber(sec, 2, dflPrecision) + '\u2033' +
(normalizedDegrees == 0 ? '' : ' ' + hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0));
};
+6 -6
View File
@@ -2,7 +2,7 @@
* @module ol/format/XSD
*/
import _ol_xml_ from '../xml.js';
import _ol_string_ from '../string.js';
import {padNumber} from '../string.js';
const XSD = {};
@@ -124,11 +124,11 @@ XSD.writeCDATASection = function(node, string) {
XSD.writeDateTimeTextNode = function(node, dateTime) {
const date = new Date(dateTime * 1000);
const string = date.getUTCFullYear() + '-' +
_ol_string_.padNumber(date.getUTCMonth() + 1, 2) + '-' +
_ol_string_.padNumber(date.getUTCDate(), 2) + 'T' +
_ol_string_.padNumber(date.getUTCHours(), 2) + ':' +
_ol_string_.padNumber(date.getUTCMinutes(), 2) + ':' +
_ol_string_.padNumber(date.getUTCSeconds(), 2) + 'Z';
padNumber(date.getUTCMonth() + 1, 2) + '-' +
padNumber(date.getUTCDate(), 2) + 'T' +
padNumber(date.getUTCHours(), 2) + ':' +
padNumber(date.getUTCMinutes(), 2) + ':' +
padNumber(date.getUTCSeconds(), 2) + 'Z';
node.appendChild(_ol_xml_.DOCUMENT.createTextNode(string));
};
+2 -2
View File
@@ -14,7 +14,7 @@ import {get as getProjection, transform} from '../proj.js';
import _ol_reproj_ from '../reproj.js';
import ImageSource from '../source/Image.js';
import WMSServerType from '../source/WMSServerType.js';
import _ol_string_ from '../string.js';
import {compareVersions} from '../string.js';
import {appendParams} from '../uri.js';
/**
@@ -367,6 +367,6 @@ ImageWMS.prototype.updateParams = function(params) {
*/
ImageWMS.prototype.updateV13_ = function() {
const version = this.params_['VERSION'] || DEFAULT_WMS_VERSION;
this.v13_ = _ol_string_.compareVersions(version, '1.3') >= 0;
this.v13_ = compareVersions(version, '1.3') >= 0;
};
export default ImageWMS;
+2 -2
View File
@@ -14,7 +14,7 @@ import _ol_size_ from '../size.js';
import TileImage from '../source/TileImage.js';
import WMSServerType from '../source/WMSServerType.js';
import _ol_tilecoord_ from '../tilecoord.js';
import _ol_string_ from '../string.js';
import {compareVersions} from '../string.js';
import {appendParams} from '../uri.js';
/**
@@ -340,6 +340,6 @@ TileWMS.prototype.updateParams = function(params) {
*/
TileWMS.prototype.updateV13_ = function() {
const version = this.params_['VERSION'] || DEFAULT_WMS_VERSION;
this.v13_ = _ol_string_.compareVersions(version, '1.3') >= 0;
this.v13_ = compareVersions(version, '1.3') >= 0;
};
export default TileWMS;
+6 -7
View File
@@ -1,20 +1,20 @@
/**
* @module ol/string
*/
const _ol_string_ = {};
/**
* @param {number} number Number to be formatted
* @param {number} width The desired width
* @param {number=} opt_precision Precision of the output string (i.e. number of decimal places)
* @returns {string} Formatted string
*/
_ol_string_.padNumber = function(number, width, opt_precision) {
*/
export function padNumber(number, width, opt_precision) {
const numberString = opt_precision !== undefined ? number.toFixed(opt_precision) : '' + number;
let decimal = numberString.indexOf('.');
decimal = decimal === -1 ? numberString.length : decimal;
return decimal > width ? numberString : new Array(1 + width - decimal).join('0') + numberString;
};
}
/**
* Adapted from https://github.com/omichelsen/compare-versions/blob/master/index.js
@@ -22,7 +22,7 @@ _ol_string_.padNumber = function(number, width, opt_precision) {
* @param {string|number} v2 Second version
* @returns {number} Value
*/
_ol_string_.compareVersions = function(v1, v2) {
export function compareVersions(v1, v2) {
const s1 = ('' + v1).split('.');
const s2 = ('' + v2).split('.');
@@ -39,5 +39,4 @@ _ol_string_.compareVersions = function(v1, v2) {
}
return 0;
};
export default _ol_string_;
}