UNPKG

1.08 kBPlain TextView Raw
1export function hasKeys(o: {}) {
2 for (const k in o) {
3 if (o.hasOwnProperty(k)) {
4 return true;
5 }
6 }
7 return false;
8}
9
10export const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
11
12// export function scope(name: string, namespace: string, separator: string = '-') {
13// return namespace ? namespace + separator + name : name;
14// }
15
16export function stripQuotation(str: string) {
17 return str.replace(/^['"](.*?)['"]$/g, '$1');
18}
19
20export function filename2varname(filename: string) {
21 return string2varname(filename.replace(/(?=.*)\.\w+$/, '').replace(/\.st$/, ''));
22}
23
24export function string2varname(str: string) {
25 return str.replace(/[^0-9a-zA-Z_]/gm, '').replace(/^[^a-zA-Z_]+/gm, '');
26}
27
28const deprecatedCache: { [id: string]: boolean } = {};
29export function deprecated(staticMessage: string) {
30 if (!deprecatedCache[staticMessage]) {
31 deprecatedCache[staticMessage] = true;
32 try {
33 console.warn('DEPRECATED: ' + staticMessage);
34 } catch {
35 /**/
36 }
37 }
38}