aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/preact/src/util.js
diff options
context:
space:
mode:
authortg(x) <*@tg-x.net>2016-10-05 00:02:10 +0200
committertg(x) <*@tg-x.net>2016-10-05 00:02:10 +0200
commitec62d29c90958aa8d41474ed2fe5a179d6fafed7 (patch)
tree367cc55bc6772cf194ed6c4778cd344d581d3d7c /thirdparty/preact/src/util.js
parentfda241d74d5c1c39203b64da676c684d4dc9d800 (diff)
parentd3ccf4103900b8d990b1970d135695b938d94eae (diff)
Merge branch 'master' of taler.net:/var/git/wallet-webex
Diffstat (limited to 'thirdparty/preact/src/util.js')
-rw-r--r--thirdparty/preact/src/util.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/thirdparty/preact/src/util.js b/thirdparty/preact/src/util.js
new file mode 100644
index 000000000..d2e63b090
--- /dev/null
+++ b/thirdparty/preact/src/util.js
@@ -0,0 +1,68 @@
+/** Copy own-properties from `props` onto `obj`.
+ * @returns obj
+ * @private
+ */
+export function extend(obj, props) {
+ if (props) {
+ for (let i in props) obj[i] = props[i];
+ }
+ return obj;
+}
+
+
+/** Fast clone. Note: does not filter out non-own properties.
+ * @see https://esbench.com/bench/56baa34f45df6895002e03b6
+ */
+export function clone(obj) {
+ return extend({}, obj);
+}
+
+
+/** Get a deep property value from the given object, expressed in dot-notation.
+ * @private
+ */
+export function delve(obj, key) {
+ for (let p=key.split('.'), i=0; i<p.length && obj; i++) {
+ obj = obj[p[i]];
+ }
+ return obj;
+}
+
+
+/** @private is the given object a Function? */
+export function isFunction(obj) {
+ return 'function'===typeof obj;
+}
+
+
+/** @private is the given object a String? */
+export function isString(obj) {
+ return 'string'===typeof obj;
+}
+
+
+/** Convert a hashmap of CSS classes to a space-delimited className string
+ * @private
+ */
+export function hashToClassName(c) {
+ let str = '';
+ for (let prop in c) {
+ if (c[prop]) {
+ if (str) str += ' ';
+ str += prop;
+ }
+ }
+ return str;
+}
+
+
+/** Just a memoized String#toLowerCase */
+let lcCache = {};
+export const toLowerCase = s => lcCache[s] || (lcCache[s] = s.toLowerCase());
+
+
+/** Call a function asynchronously, as soon as possible.
+ * @param {Function} callback
+ */
+let resolved = typeof Promise!=='undefined' && Promise.resolve();
+export const defer = resolved ? (f => { resolved.then(f); }) : setTimeout;