@arche-mc2/arche-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
182 lines • 6.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
var remStringFromPx_1 = require("./remStringFromPx");
var shallowEqual_1 = require("./shallowEqual");
exports.shallowEqual = shallowEqual_1.default;
exports.default = remStringFromPx_1.default;
function generateId() {
var id = "";
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 10; i++)
id += characters.charAt(Math.floor(Math.random() * characters.length));
return id;
}
exports.generateId = generateId;
var GUID_EMPTY = "00000000-0000-0000-0000-000000000000";
function isString(object) {
return typeof object === 'string' || object instanceof String;
}
exports.isString = isString;
function isEmpty(value) {
return value === undefined || value === null || value === "" || value === GUID_EMPTY || (Array.isArray(value) && value.length === 0);
}
exports.isEmpty = isEmpty;
function isEmptyId(id) {
return id === undefined || id === null || id === "" || id === GUID_EMPTY;
}
exports.isEmptyId = isEmptyId;
exports.isEmptyChildren = function (children) { return react_1.Children.count(children) === 0; };
exports.isFunction = function (value) {
return typeof value === 'function';
};
exports.getComponentName = function (component) {
return component.displayName || component.name;
};
exports.getHocComponentName = function (hocName, component) {
return hocName + "(" + exports.getComponentName(component) + ")";
};
exports.withDefaultProps = function (defaultProps, Cmp) {
Cmp.defaultProps = defaultProps;
return Cmp;
};
exports.callAll = function () {
var fns = [];
for (var _i = 0; _i < arguments.length; _i++) {
fns[_i] = arguments[_i];
}
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return fns.forEach(function (fn) { return fn && fn(args); });
};
};
var open = function (url, title, onClose, name) {
var a = document.createElement('a');
a.setAttribute('href', url);
a.setAttribute('target', '_blank');
if (name) {
a.setAttribute('download', name);
}
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
var getFileNameOrDefault = function (name, mimeType) {
if (!isEmpty(name)) {
return name;
}
return "download." + mimeType.split('/').pop();
};
exports.isBase64 = function (fileAsBase64) {
if (isEmpty(fileAsBase64)) {
return false;
}
return fileAsBase64.split(';')[0] == 'base64';
};
exports.getMimeTypeFromBase64 = function (fileAsBase64) {
if (isEmpty(fileAsBase64)) {
return null;
}
return fileAsBase64.split(';')[0].split(':')[1];
};
exports.openFileAsBase64 = function (fileAsBase64, name) {
var parts = fileAsBase64.split(';');
var mimeType = parts[0].split(':')[1];
var file = parts[1].slice(7);
exports.openFileAsBlob(exports.base64toBlob(file), mimeType, getFileNameOrDefault(name, mimeType));
};
exports.openFileAsBlob = function (file, mimeType, name) {
var newBlob = new Blob([file], { type: mimeType });
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(newBlob);
return;
}
var data = window.URL.createObjectURL(newBlob);
open(data, name || 'download.png', null, name || 'download.png');
setTimeout(function () {
window.URL.revokeObjectURL(data);
}, 100);
};
exports.base64toBlob = function (base64Data, contentType) {
var sliceSize = 1024;
var byteCharacters = atob(base64Data);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
}
var blob;
try {
blob = new Blob(byteArrays, { type: contentType || '' });
}
catch (e) {
window['BlobBuilder'] = window['BlobBuilder'] ||
window['WebKitBlobBuilder'] ||
window['MozBlobBuilder'] ||
window['MSBlobBuilder'];
if (e.name === 'TypeError' && window['BlobBuilder']) {
var bb = window['BlobBuilder']();
bb.append(byteArrays);
blob = bb.getBlob(contentType);
}
else if (e.name === 'InvalidStateError') {
blob = new Blob(byteArrays, { type: contentType });
}
else {
}
}
return blob;
};
exports.on = function (el, evt, fn, bubble) {
if ('addEventListener' in el) {
try {
el.addEventListener(evt, fn, bubble);
}
catch (e) {
if (typeof fn === 'object' && fn.handleEvent) {
el.addEventListener(evt, function (e) {
fn.handleEvent.call(fn, e);
}, bubble);
}
else {
throw e;
}
}
}
else if ('attachEvent' in el) {
if (typeof fn === 'object' && fn.handleEvent) {
el.attachEvent('on' + evt, function () {
fn.handleEvent.call(fn);
});
}
else {
el.attachEvent('on' + evt, fn);
}
}
};
exports.off = function (el, evt, fn) {
if ('removeEventListener' in el) {
el.removeEventListener(evt, fn);
}
else if ('attachEvent' in el) {
el.detachEvent(evt, fn);
}
};
exports.ruleIsValid = function (value, givenRegex) { return new RegExp(givenRegex).test(value); };
exports.rulesMatch = function (value, rules) {
return isEmpty(rules) ? false : rules.every(function (_a) {
var regex = _a.regex;
return exports.ruleIsValid(value, regex);
});
};
//# sourceMappingURL=index.js.map