2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2017-05-22 15:02:07 -07:00
|
|
|
import {ɵglobal as global} from '@angular/core';
|
|
|
|
|
|
2016-11-12 14:08:58 +01:00
|
|
|
const CAMEL_CASE_REGEXP = /([A-Z])/g;
|
|
|
|
|
const DASH_CASE_REGEXP = /-([a-z])/g;
|
2015-03-23 14:10:55 -07:00
|
|
|
|
2015-06-24 13:46:39 -07:00
|
|
|
|
2015-06-26 11:10:52 -07:00
|
|
|
export function camelCaseToDashCase(input: string): string {
|
2016-10-06 15:10:27 -07:00
|
|
|
return input.replace(CAMEL_CASE_REGEXP, (...m: string[]) => '-' + m[1].toLowerCase());
|
2015-03-23 14:10:55 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-26 11:10:52 -07:00
|
|
|
export function dashCaseToCamelCase(input: string): string {
|
2016-10-06 15:10:27 -07:00
|
|
|
return input.replace(DASH_CASE_REGEXP, (...m: string[]) => m[1].toUpperCase());
|
2015-05-18 11:57:20 -07:00
|
|
|
}
|
2017-05-22 15:02:07 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 {
|
2017-09-26 19:41:08 -07:00
|
|
|
if (typeof goog === 'undefined' || goog.DEBUG) {
|
|
|
|
|
// 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;
|
2017-05-22 15:02:07 -07:00
|
|
|
}
|
|
|
|
|
}
|