forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.ts
More file actions
29 lines (26 loc) · 1.03 KB
/
Utilities.ts
File metadata and controls
29 lines (26 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import {
ApiParameterListMixin,
ApiItem
} from '@microsoft/api-extractor-model';
export class Utilities {
private static readonly _badFilenameCharsRegExp: RegExp = /[^a-z0-9_\-\.]/ig;
/**
* Generates a concise signature for a function. Example: "getArea(width, height)"
*/
public static getConciseSignature(apiItem: ApiItem): string {
if (ApiParameterListMixin.isBaseClassOf(apiItem)) {
return apiItem.displayName + '(' + apiItem.parameters.map(x => x.name).join(', ') + ')';
}
return apiItem.displayName;
}
/**
* Converts bad filename characters to underscores.
*/
public static getSafeFilenameForName(name: string): string {
// TODO: This can introduce naming collisions.
// We will fix that as part of https://github.com/microsoft/rushstack/issues/1308
return name.replace(Utilities._badFilenameCharsRegExp, '_').toLowerCase();
}
}