
`good.DEBUG` can also be true when using advanced compilation. Attention: This change has be applied in G3 already as a local mod!
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import {ɵglobal as global} from '@angular/core';
|
|
|
|
const CAMEL_CASE_REGEXP = /([A-Z])/g;
|
|
const DASH_CASE_REGEXP = /-([a-z])/g;
|
|
|
|
|
|
export function camelCaseToDashCase(input: string): string {
|
|
return input.replace(CAMEL_CASE_REGEXP, (...m: string[]) => '-' + m[1].toLowerCase());
|
|
}
|
|
|
|
export function dashCaseToCamelCase(input: string): string {
|
|
return input.replace(DASH_CASE_REGEXP, (...m: string[]) => m[1].toUpperCase());
|
|
}
|
|
|
|
/**
|
|
* Exports the value under a given `name` in the global property `ng`. For example `ng.probe` if
|
|
* `name` is `'probe'`.
|
|
* @param name Name under which it will be exported. Keep in mind this will be a property of the
|
|
* global `ng` object.
|
|
* @param value The value to export.
|
|
*/
|
|
export function exportNgVar(name: string, value: any): void {
|
|
if (typeof COMPILED === 'undefined' || !COMPILED) {
|
|
// Note: we can't export `ng` when using closure enhanced optimization as:
|
|
// - closure declares globals itself for minified names, which sometimes clobber our `ng` global
|
|
// - we can't declare a closure extern as the namespace `ng` is already used within Google
|
|
// for typings for angularJS (via `goog.provide('ng....')`).
|
|
const ng = global['ng'] = (global['ng'] as{[key: string]: any} | undefined) || {};
|
|
ng[name] = value;
|
|
}
|
|
}
|