forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.ts
More file actions
26 lines (24 loc) · 659 Bytes
/
string.ts
File metadata and controls
26 lines (24 loc) · 659 Bytes
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
/**
* Return [parent name, name] for the given qualified (dotted) name.
*
* Examples:
* 'x.y' -> ['x', 'y']
* 'x' -> ['', 'x']
* 'x.y.z' -> ['x.y', 'z']
* '' -> ['', '']
*/
export function splitParent(fullName: string): [string, string] {
if (fullName.length === 0) {
return ['', ''];
}
const pos = fullName.lastIndexOf('.');
if (pos < 0) {
return ['', fullName];
}
const parentName = fullName.slice(0, pos);
const name = fullName.slice(pos + 1);
return [parentName, name];
}