Skip to content

Commit

Permalink
feat: implement dir walkjs
Browse files Browse the repository at this point in the history
  • Loading branch information
HaidarJbeily7 committed Nov 23, 2024
1 parent 0eda4ef commit 7dcdbcb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions eo2js-runtime/src/objects/org/eolang/fs/dir$walk.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const object = require('../../../../runtime/object')
const {LAMBDA} = require('../../../../runtime/attribute/specials');
const at_void = require('../../../../runtime/attribute/at-void');
const at_string = require('../../../../runtime/attribute/at-string');
const fs = require('fs');
const path = require('path');
const data = require('../../../../runtime/data');
const glob = require('glob');

/**
Expand All @@ -16,7 +14,7 @@ const dir$walk = function() {
obj.assets[LAMBDA] = function(_) {
const pattern = obj.attrs['glob'].data;
const files = glob.sync(pattern);
return at_string(files.join('\n'));
return data.toObject(files.join('\n'));
}
return obj
}
Expand Down
4 changes: 2 additions & 2 deletions eo2js-runtime/test/objects/org/eolang/fs/dir$walk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assert = require('assert');
const dir$walk = require('../../../../../temp/objects/org/eolang/fs/dir$walk');
const {STRING} = require('../../../../../temp/runtime/types');
const dataized = require('../../../../../temp/runtime/dataized');
const at_string = require('../../../../runtime/attribute/at-string');
const data = require('../../../../../temp/runtime/data');
const fs = require('fs');
const path = require('path');

Expand All @@ -26,7 +26,7 @@ describe('dir$walk', function() {

it('should find files matching glob pattern', function() {
const walk = dir$walk();
walk.attrs['glob'] = at_string(path.join(directory, '**/*.txt'));
walk.attrs['glob'] = data.toObject(path.join(directory, '**/*.txt'));
const result = dataized(walk, STRING).split('\n').sort();
assert.deepEqual(
result,
Expand Down

0 comments on commit 7dcdbcb

Please sign in to comment.