Skip to content

Commit 23c2d14

Browse files
committed
Move parsePath from impress
Pr-URL: #73
1 parent f3c5ee0 commit 23c2d14

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased][unreleased]
44

55
- Pool implementation with round-robian and exclusive item capture/release
6+
- Move parsePath from impress
67

78
## [3.5.11][] - 2021-09-09
89

lib/utilities.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ const fileExt = (fileName) => {
5555
return replace(ext, '.', '');
5656
};
5757

58+
const parsePath = (relPath) => {
59+
const name = path.basename(relPath, '.js');
60+
const names = relPath.split(path.sep);
61+
names[names.length - 1] = name;
62+
return names;
63+
};
64+
5865
const between = (s, prefix, suffix) => {
5966
let i = s.indexOf(prefix);
6067
if (i === -1) return '';
@@ -369,6 +376,7 @@ module.exports = {
369376
parseParams,
370377
replace,
371378
fileExt,
379+
parsePath,
372380
between,
373381
split,
374382
isFirstUpper,

metautil.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export function parseParams(params: string): object;
2727
export function replace(str: string, substr: string, newstr: string): string;
2828
export function split(s: string, separator: string): [string, string];
2929
export function fileExt(fileName: string): string;
30+
export function parsePath(relPath: string): Array<string>;
3031
export function between(s: string, prefix: string, suffix: string): string;
3132
export function isFirstUpper(s: string): boolean;
3233
export function toLowerCamel(s: string): string;

test/strings.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ metatests.case(
4949
['.', ''],
5050
['', ''],
5151
],
52+
'metautil.parsePath': [
53+
['example/stop.js', ['example', 'stop']],
54+
['example/doSomething.js', ['example', 'doSomething']],
55+
['example/submodule2/method2.js', ['example', 'submodule2', 'method2']],
56+
['file.js', ['file']],
57+
],
5258
'metautil.between': [
5359
['abcdefghijk', 'cd', 'h', 'efg'],
5460
['field="value"', '"', '"', 'value'],

0 commit comments

Comments
 (0)