Skip to content

Commit f39e21c

Browse files
author
Mohamed Seleem
committed
Add filename.dirname/1
1 parent 1de356d commit f39e21c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/javascript/lib/core/erlang_compat/filename.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ function join(arg = [], extra = []) {
1313
}
1414
return names.reverse().join('/');
1515
}
16+
17+
function dirname(arg) {
18+
const path = join([arg]);
19+
const index = path.lastIndexOf('/');
20+
return index == -1 ? '.' : path.substr(0, index);
21+
}
22+
1623
export default {
1724
join,
25+
dirname,
1826
};

src/javascript/tests/core/erlang_compat/filename_spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import test from 'ava';
22
import Core from '../../../lib/core';
33

4+
test('dirname/1', (t) => {
5+
let result = Core.filename.dirname('/usr/src/kalle.erl');
6+
t.is(result, '/usr/src');
7+
8+
result = Core.filename.dirname('kalle.erl');
9+
t.is(result, '.');
10+
});
11+
412
test('join/1', (t) => {
513
let result = Core.filename.join(['/usr', 'local', 'bin']);
614
t.is(result, '/usr/local/bin');

0 commit comments

Comments
 (0)