piral-ng
Version:
Plugin for integrating Angular components in Piral.
46 lines • 1.54 kB
JavaScript
import { VERSION } from '@angular/core';
export function getId() {
return Math.random().toString(36);
}
export function getNgVersion() {
return VERSION.major || VERSION.full.split('.')[0];
}
export function getMinVersion() {
const major = getNgVersion();
return `${major}.0.0`;
}
export function getAnnotations(component) {
let annotations = component?.__annotations__;
if (!annotations && typeof Reflect !== 'undefined' && 'getOwnMetadata' in Reflect) {
annotations = Reflect.getOwnMetadata('annotations', component);
}
if (!annotations && typeof component.ɵcmp !== 'undefined') {
annotations = [{}];
}
if (!annotations && typeof component.ɵmod !== 'undefined') {
annotations = [component.ɵmod];
}
return annotations || [];
}
export function hasSelector(component, selector) {
const [annotation] = getAnnotations(component);
return annotation && annotation.selector === selector;
}
export function findComponents(exports) {
const components = [];
if (Array.isArray(exports)) {
for (const ex of exports) {
const [annotation] = getAnnotations(ex);
if (annotation) {
if (annotation.exports) {
components.push(...findComponents(annotation.exports));
}
else if (!annotation.imports || annotation.standalone) {
components.push(ex);
}
}
}
}
return components;
}
//# sourceMappingURL=utils.js.map