ngx-bit
Version:
A flexible NG-ZORRO helper library
54 lines (46 loc) • 1.38 kB
JavaScript
import { timer, Observable } from 'rxjs';
import { switchMap, map } from 'rxjs/operators';
function asyncValidator(handle, field = 'duplicated', dueTime = 500) {
return timer(dueTime).pipe(switchMap(() => handle), map(result => {
return !result ? { error: true, [field]: true } : null;
}));
}
function empty(value) {
if ([undefined, null, '', 0, false].includes(value)) {
return true;
}
if (typeof value === 'object') {
return Object.keys(value).length === 0;
}
return false;
}
function print(str, ...vars) {
if (!str) {
return '';
}
vars.forEach((value, index) => {
str = str.replace('$' + index, value);
});
return str;
}
function privacy(text, start, end) {
const match = text.slice(start, end);
return text.replace(match, '*'.repeat(match.length));
}
function loadScript(doc, url) {
const script = doc.createElement('script');
script.type = 'text/javascript';
script.src = url;
doc.body.appendChild(script);
return new Observable(subscriber => {
script.onload = () => {
subscriber.next();
subscriber.complete();
};
});
}
/**
* Generated bundle index. Do not edit.
*/
export { asyncValidator, empty, loadScript, print, privacy };
//# sourceMappingURL=ngx-bit-operates.js.map