WIP: try to convert to ES modules
This commit is contained in:
parent
ec5b050496
commit
299a08b6a3
29 changed files with 3003 additions and 2014 deletions
|
|
@ -1,5 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
import * as OxObject from './Object.js';
|
||||
import * as OxConstants from './Constants.js';
|
||||
import * as OxMath from './Math.js';
|
||||
|
||||
const Ox = {};
|
||||
|
||||
Object.assign(Ox,
|
||||
OxObject,
|
||||
OxConstants,
|
||||
OxMath
|
||||
);
|
||||
|
||||
/*@
|
||||
Ox.formatArea <f> Formats a number of meters as square meters or kilometers
|
||||
> Ox.formatArea(1000)
|
||||
|
|
@ -8,7 +20,7 @@ Ox.formatArea <f> Formats a number of meters as square meters or kilometers
|
|||
'1 km\u00B2'
|
||||
@*/
|
||||
|
||||
Ox.formatArea = function(number, decimals) {
|
||||
export function formatArea(number, decimals) {
|
||||
var k = number >= 1000000 ? 'k' : '';
|
||||
decimals = Ox.isUndefined(decimals) ? 8 : decimals;
|
||||
return Ox.formatNumber(
|
||||
|
|
@ -25,7 +37,7 @@ Ox.formatCount <f> Returns a string like "2 items", "1 item" or "no items".
|
|||
> Ox.formatCount(1000, 'city', 'cities')
|
||||
'1,000 cities'
|
||||
@*/
|
||||
Ox.formatCount = function(number, singular, plural) {
|
||||
export function formatCount(number, singular, plural) {
|
||||
plural = (plural || singular + 's') + (number === 2 ? '{2}' : '');
|
||||
return (number === 0 ? Ox._('no') : Ox.formatNumber(number))
|
||||
+ ' ' + Ox._(number === 1 ? singular : plural);
|
||||
|
|
@ -36,7 +48,7 @@ Ox.formatCurrency <f> Formats a number with a currency symbol
|
|||
> Ox.formatCurrency(1000, '$', 2)
|
||||
'$1,000.00'
|
||||
@*/
|
||||
Ox.formatCurrency = function(number, string, decimals) {
|
||||
export function formatCurrency(number, string, decimals) {
|
||||
return string + Ox.formatNumber(number, decimals);
|
||||
};
|
||||
|
||||
|
|
@ -397,7 +409,7 @@ Ox.formatDateRange <f> Formats a date range as a string
|
|||
> Ox.formatDateRange('-50-01-01 00:00:00', '-50-01-01 23:59:59')
|
||||
'Sun, Jan 1, 50 BC, 00:00:00 - 23:59:59'
|
||||
@*/
|
||||
Ox.formatDateRange = function(start, end, utc) {
|
||||
export function formatDateRange(start, end, utc) {
|
||||
end = end || Ox.formatDate(new Date(), '%Y-%m-%d');
|
||||
var isOneUnit = false,
|
||||
range = [start, end],
|
||||
|
|
@ -487,7 +499,7 @@ Ox.formatDateRangeDuration <f> Formats the duration of a date range as a string
|
|||
> Ox.formatDateRangeDuration('2000-02', '2000-03', true)
|
||||
'1 month'
|
||||
@*/
|
||||
Ox.formatDateRangeDuration = function(start, end, utc) {
|
||||
export function formatDateRangeDuration(start, end, utc) {
|
||||
end = end || Ox.formatDate(new Date(), '%Y-%m-%d');
|
||||
var date = Ox.parseDate(start, utc),
|
||||
dates = [start, end].map(function(string) {
|
||||
|
|
@ -535,7 +547,7 @@ Ox.formatDegrees <f> Formats degrees as D°MM'SS"
|
|||
> Ox.formatDegrees(-111.11, 'lng')
|
||||
"111°06'36\"W"
|
||||
@*/
|
||||
Ox.formatDegrees = function(degrees, mode) {
|
||||
export function formatDegrees(degrees, mode) {
|
||||
var days = 0,
|
||||
seconds = Math.round(Math.abs(degrees) * 3600),
|
||||
sign = degrees < 0 ? '-' : '',
|
||||
|
|
@ -558,11 +570,13 @@ Ox.formatDimensions <f> Formats valus as dimension
|
|||
> Ox.formatDimensions([1920, 1080], 'px')
|
||||
"1,920 × 1,080 px"
|
||||
@*/
|
||||
Ox.formatDimensions = Ox.formatResolution = function(array, string) {
|
||||
export function formatDimensions(array, string) {
|
||||
return array.map(function(value) {
|
||||
return Ox.formatNumber(value);
|
||||
}).join(' × ') + (string ? ' ' + string : '');
|
||||
};
|
||||
export const formatResolution = formatDimensions;
|
||||
|
||||
|
||||
/*@
|
||||
Ox.formatDuration <f> Formats a duration as a string
|
||||
|
|
@ -595,7 +609,7 @@ Ox.formatDuration <f> Formats a duration as a string
|
|||
> Ox.formatDuration(0, 'long')
|
||||
''
|
||||
@*/
|
||||
Ox.formatDuration = function(seconds/*, decimals, format*/) {
|
||||
export function formatDuration(seconds/*, decimals, format*/) {
|
||||
var last = Ox.last(arguments),
|
||||
format = last == 'short' || last == 'long' ? last : 'none',
|
||||
decimals = Ox.isNumber(arguments[1]) ? arguments[1] : 0,
|
||||
|
|
@ -649,7 +663,7 @@ Ox.formatISBN <f> Formats a string as an ISBN of a given length (10 or 13)
|
|||
> Ox.formatISBN('978-0-306-40615-7', 10)
|
||||
'0306406152'
|
||||
@*/
|
||||
Ox.formatISBN = function(isbn, length, dashes) {
|
||||
export function formatISBN(isbn, length, dashes) {
|
||||
var ret = '';
|
||||
function getCheckDigit(isbn) {
|
||||
var mod = isbn.length == 10 ? 11 : 10
|
||||
|
|
@ -697,7 +711,7 @@ Ox.formatNumber <f> Formats a number with thousands separators
|
|||
> Ox.formatNumber(666666.666)
|
||||
"666,667"
|
||||
@*/
|
||||
Ox.formatNumber = function(number, decimals) {
|
||||
export function formatNumber(number, decimals) {
|
||||
var array = [],
|
||||
abs = Math.abs(number),
|
||||
split = abs.toFixed(decimals).split('.');
|
||||
|
|
@ -726,7 +740,7 @@ Ox.formatOrdinal <f> Formats a number as an ordinal
|
|||
> Ox.formatOrdinal(13)
|
||||
"13th"
|
||||
@*/
|
||||
Ox.formatOrdinal = function(number) {
|
||||
export function formatOrdinal(number) {
|
||||
var string = Ox.formatNumber(number),
|
||||
length = string.length,
|
||||
last = string[length - 1],
|
||||
|
|
@ -751,7 +765,7 @@ Ox.formatPercent <f> Formats the relation of two numbers as a percentage
|
|||
> Ox.formatPercent(1, 1000, 2)
|
||||
"0.10%"
|
||||
@*/
|
||||
Ox.formatPercent = function(number, total, decimals) {
|
||||
export function formatPercent(number, total, decimals) {
|
||||
return Ox.formatNumber(number / total * 100, decimals) + Ox._('%');
|
||||
};
|
||||
|
||||
|
|
@ -772,7 +786,7 @@ Ox.formatRoman <f> Formats a number as a roman numeral
|
|||
> Ox.formatRoman(10000)
|
||||
'MMMMMMMMMM'
|
||||
@*/
|
||||
Ox.formatRoman = function(number) {
|
||||
export function formatRoman(number) {
|
||||
var string = '';
|
||||
Ox.forEach({
|
||||
M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90,
|
||||
|
|
@ -789,7 +803,7 @@ Ox.formatRoman = function(number) {
|
|||
/*@
|
||||
Ox.formatSRT <f> Formats subtitles as SRT
|
||||
@*/
|
||||
Ox.formatSRT = function(subtitles) {
|
||||
export function formatSRT(subtitles) {
|
||||
return '\ufeff' + Ox.sortBy(subtitles, ['in', 'out']).map(function(subtitle, index) {
|
||||
return [
|
||||
index + 1,
|
||||
|
|
@ -816,7 +830,7 @@ Ox.formatString <f> Basic string formatting
|
|||
> Ox.formatString('{b}', {a: 'foobar'}, true)
|
||||
'{b}'
|
||||
@*/
|
||||
Ox.formatString = function(string, collection, keepUnmatched) {
|
||||
export function formatString(string, collection, keepUnmatched) {
|
||||
return string.replace(/\{([^}]+)\}/g, function(string, match) {
|
||||
// make sure to not split at escaped dots ('\.')
|
||||
var key,
|
||||
|
|
@ -844,7 +858,7 @@ Ox.formatUnit <f> Formats a number with a unit
|
|||
> Ox.formatUnit(100/3, '%')
|
||||
'33%'
|
||||
@*/
|
||||
Ox.formatUnit = function(number, string, decimals) {
|
||||
export function formatUnit(number, string, decimals) {
|
||||
return Ox.formatNumber(number, decimals)
|
||||
+ (/^[:%]/.test(string) ? '' : ' ') + string;
|
||||
};
|
||||
|
|
@ -859,7 +873,7 @@ Ox.formatValue <f> Formats a numerical value
|
|||
"1.15 GiB"
|
||||
@*/
|
||||
// fixme: is this the best name?
|
||||
Ox.formatValue = function(number, string, bin) {
|
||||
export function formatValue(number, string, bin) {
|
||||
var base = bin ? 1024 : 1000,
|
||||
length = Ox.PREFIXES.length,
|
||||
ret;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue