aboutsummaryrefslogtreecommitdiffstats
path: root/library/moment/src/lib/utils
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2015-11-18 23:50:42 +0100
committerMario Vavti <mario@mariovavti.com>2015-11-18 23:50:42 +0100
commite4145deeb7a72ac321113fde672e1b499ecb0d2d (patch)
treece2fb59fd9d2ec1d13ea0960215967600098ca13 /library/moment/src/lib/utils
parent68da4d90dcbda1240ae014768a66a164fd5d2b36 (diff)
downloadvolse-hubzilla-e4145deeb7a72ac321113fde672e1b499ecb0d2d.tar.gz
volse-hubzilla-e4145deeb7a72ac321113fde672e1b499ecb0d2d.tar.bz2
volse-hubzilla-e4145deeb7a72ac321113fde672e1b499ecb0d2d.zip
some events refacturing
Diffstat (limited to 'library/moment/src/lib/utils')
-rw-r--r--library/moment/src/lib/utils/abs-ceil.js7
-rw-r--r--library/moment/src/lib/utils/abs-floor.js7
-rw-r--r--library/moment/src/lib/utils/compare-arrays.js16
-rw-r--r--library/moment/src/lib/utils/defaults.js10
-rw-r--r--library/moment/src/lib/utils/deprecate.js32
-rw-r--r--library/moment/src/lib/utils/extend.js19
-rw-r--r--library/moment/src/lib/utils/has-own-prop.js3
-rw-r--r--library/moment/src/lib/utils/hooks.js13
-rw-r--r--library/moment/src/lib/utils/is-array.js3
-rw-r--r--library/moment/src/lib/utils/is-date.js3
-rw-r--r--library/moment/src/lib/utils/map.js7
-rw-r--r--library/moment/src/lib/utils/to-int.js12
-rw-r--r--library/moment/src/lib/utils/zero-fill.js7
13 files changed, 139 insertions, 0 deletions
diff --git a/library/moment/src/lib/utils/abs-ceil.js b/library/moment/src/lib/utils/abs-ceil.js
new file mode 100644
index 000000000..7cf93290c
--- /dev/null
+++ b/library/moment/src/lib/utils/abs-ceil.js
@@ -0,0 +1,7 @@
+export default function absCeil (number) {
+ if (number < 0) {
+ return Math.floor(number);
+ } else {
+ return Math.ceil(number);
+ }
+}
diff --git a/library/moment/src/lib/utils/abs-floor.js b/library/moment/src/lib/utils/abs-floor.js
new file mode 100644
index 000000000..8ba131831
--- /dev/null
+++ b/library/moment/src/lib/utils/abs-floor.js
@@ -0,0 +1,7 @@
+export default function absFloor (number) {
+ if (number < 0) {
+ return Math.ceil(number);
+ } else {
+ return Math.floor(number);
+ }
+}
diff --git a/library/moment/src/lib/utils/compare-arrays.js b/library/moment/src/lib/utils/compare-arrays.js
new file mode 100644
index 000000000..2eb274bef
--- /dev/null
+++ b/library/moment/src/lib/utils/compare-arrays.js
@@ -0,0 +1,16 @@
+import toInt from './to-int';
+
+// compare two arrays, return the number of differences
+export default function compareArrays(array1, array2, dontConvert) {
+ var len = Math.min(array1.length, array2.length),
+ lengthDiff = Math.abs(array1.length - array2.length),
+ diffs = 0,
+ i;
+ for (i = 0; i < len; i++) {
+ if ((dontConvert && array1[i] !== array2[i]) ||
+ (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {
+ diffs++;
+ }
+ }
+ return diffs + lengthDiff;
+}
diff --git a/library/moment/src/lib/utils/defaults.js b/library/moment/src/lib/utils/defaults.js
new file mode 100644
index 000000000..45c5e8794
--- /dev/null
+++ b/library/moment/src/lib/utils/defaults.js
@@ -0,0 +1,10 @@
+// Pick the first defined of two or three arguments.
+export default function defaults(a, b, c) {
+ if (a != null) {
+ return a;
+ }
+ if (b != null) {
+ return b;
+ }
+ return c;
+}
diff --git a/library/moment/src/lib/utils/deprecate.js b/library/moment/src/lib/utils/deprecate.js
new file mode 100644
index 000000000..df4286b84
--- /dev/null
+++ b/library/moment/src/lib/utils/deprecate.js
@@ -0,0 +1,32 @@
+import extend from './extend';
+import { hooks } from './hooks';
+
+function warn(msg) {
+ if (hooks.suppressDeprecationWarnings === false && typeof console !== 'undefined' && console.warn) {
+ console.warn('Deprecation warning: ' + msg);
+ }
+}
+
+export function deprecate(msg, fn) {
+ var firstTime = true;
+
+ return extend(function () {
+ if (firstTime) {
+ warn(msg + '\n' + (new Error()).stack);
+ firstTime = false;
+ }
+ return fn.apply(this, arguments);
+ }, fn);
+}
+
+var deprecations = {};
+
+export function deprecateSimple(name, msg) {
+ if (!deprecations[name]) {
+ warn(msg);
+ deprecations[name] = true;
+ }
+}
+
+hooks.suppressDeprecationWarnings = false;
+
diff --git a/library/moment/src/lib/utils/extend.js b/library/moment/src/lib/utils/extend.js
new file mode 100644
index 000000000..ba74a0bf1
--- /dev/null
+++ b/library/moment/src/lib/utils/extend.js
@@ -0,0 +1,19 @@
+import hasOwnProp from './has-own-prop';
+
+export default function extend(a, b) {
+ for (var i in b) {
+ if (hasOwnProp(b, i)) {
+ a[i] = b[i];
+ }
+ }
+
+ if (hasOwnProp(b, 'toString')) {
+ a.toString = b.toString;
+ }
+
+ if (hasOwnProp(b, 'valueOf')) {
+ a.valueOf = b.valueOf;
+ }
+
+ return a;
+}
diff --git a/library/moment/src/lib/utils/has-own-prop.js b/library/moment/src/lib/utils/has-own-prop.js
new file mode 100644
index 000000000..4d2403ccb
--- /dev/null
+++ b/library/moment/src/lib/utils/has-own-prop.js
@@ -0,0 +1,3 @@
+export default function hasOwnProp(a, b) {
+ return Object.prototype.hasOwnProperty.call(a, b);
+}
diff --git a/library/moment/src/lib/utils/hooks.js b/library/moment/src/lib/utils/hooks.js
new file mode 100644
index 000000000..02a5bd3da
--- /dev/null
+++ b/library/moment/src/lib/utils/hooks.js
@@ -0,0 +1,13 @@
+export { hooks, setHookCallback };
+
+var hookCallback;
+
+function hooks () {
+ return hookCallback.apply(null, arguments);
+}
+
+// This is done to register the method called with moment()
+// without creating circular dependencies.
+function setHookCallback (callback) {
+ hookCallback = callback;
+}
diff --git a/library/moment/src/lib/utils/is-array.js b/library/moment/src/lib/utils/is-array.js
new file mode 100644
index 000000000..46bd6c68b
--- /dev/null
+++ b/library/moment/src/lib/utils/is-array.js
@@ -0,0 +1,3 @@
+export default function isArray(input) {
+ return Object.prototype.toString.call(input) === '[object Array]';
+}
diff --git a/library/moment/src/lib/utils/is-date.js b/library/moment/src/lib/utils/is-date.js
new file mode 100644
index 000000000..69c4d0e9c
--- /dev/null
+++ b/library/moment/src/lib/utils/is-date.js
@@ -0,0 +1,3 @@
+export default function isDate(input) {
+ return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';
+}
diff --git a/library/moment/src/lib/utils/map.js b/library/moment/src/lib/utils/map.js
new file mode 100644
index 000000000..1cbc5639f
--- /dev/null
+++ b/library/moment/src/lib/utils/map.js
@@ -0,0 +1,7 @@
+export default function map(arr, fn) {
+ var res = [], i;
+ for (i = 0; i < arr.length; ++i) {
+ res.push(fn(arr[i], i));
+ }
+ return res;
+}
diff --git a/library/moment/src/lib/utils/to-int.js b/library/moment/src/lib/utils/to-int.js
new file mode 100644
index 000000000..fb489416f
--- /dev/null
+++ b/library/moment/src/lib/utils/to-int.js
@@ -0,0 +1,12 @@
+import absFloor from './abs-floor';
+
+export default function toInt(argumentForCoercion) {
+ var coercedNumber = +argumentForCoercion,
+ value = 0;
+
+ if (coercedNumber !== 0 && isFinite(coercedNumber)) {
+ value = absFloor(coercedNumber);
+ }
+
+ return value;
+}
diff --git a/library/moment/src/lib/utils/zero-fill.js b/library/moment/src/lib/utils/zero-fill.js
new file mode 100644
index 000000000..7009ec903
--- /dev/null
+++ b/library/moment/src/lib/utils/zero-fill.js
@@ -0,0 +1,7 @@
+export default function zeroFill(number, targetLength, forceSign) {
+ var absNumber = '' + Math.abs(number),
+ zerosToFill = targetLength - absNumber.length,
+ sign = number >= 0;
+ return (sign ? (forceSign ? '+' : '') : '-') +
+ Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;
+}