angular/packages/compiler-cli/src/ngtsc/path/src/util.ts
Alex Rickabaugh a529f53031 feat(ivy): introduce concrete types for paths in ngtsc (#28523)
This commit introduces a new ngtsc sub-library, 'path', which contains
branded string types for the different kind of paths that ngtsc manipulates.
Having static types for these paths will reduce the number of path-related
bugs (especially on Windows) and will eliminate unnecessary defensive
normalizing.

See the README.md file for more detail.

PR Close #28523
2019-02-13 19:13:11 -08:00

26 lines
690 B
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
*/
// TODO(alxhub): Unify this file with `util/src/path`.
const TS_DTS_JS_EXTENSION = /(?:\.d)?\.ts$|\.js$/;
/**
* Convert Windows-style paths to POSIX paths.
*/
export function normalizeSeparators(path: string): string {
// TODO: normalize path only for OS that need it.
return path.replace(/\\/g, '/');
}
/**
* Remove a .ts, .d.ts, or .js extension from a file name.
*/
export function stripExtension(path: string): string {
return path.replace(TS_DTS_JS_EXTENSION, '');
}