{"_id":"@bmacnaughton/action-walk","_rev":"1-49964c3eecde5da10d7237206c7eb63c","name":"@bmacnaughton/action-walk","dist-tags":{"latest":"2.4.0"},"versions":{"2.3.0":{"name":"@bmacnaughton/action-walk","access":"public","version":"2.3.0","description":"walk a directory tree performing actions","main":"action-walk.js","engines":{"node":">=12.12.0"},"directories":{"test":"test"},"scripts":{"test":"mocha test/*.test.js","coverage":"nyc --reporter=text mocha test/*.test.js","walk":"node bin/walk.js"},"keywords":["directory","tree","action","iterate","general","utility","recursive","walk","flexible"],"author":{"name":"Bruce A. MacNaughton"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/bmacnaughton/action-walk.git"},"bugs":{"url":"https://github.com/bmacnaughton/action-walk/issues"},"bin":{"action-walk":"bin/walk.js"},"devDependencies":{"chai":"^4.2.0","chai-as-promised":"^7.1.1","eslint":"^8.54.0","inquirer":"^9.2.12","mocha":"^8.1.3","nyc":"^15.1.0"},"_id":"@bmacnaughton/action-walk@2.3.0","gitHead":"1d5d2abab2037346d0fb85348d56ce7a203c2241","homepage":"https://github.com/bmacnaughton/action-walk#readme","_nodeVersion":"18.18.2","_npmVersion":"9.8.1","dist":{"integrity":"sha512-ULVS/i5py1R6+w861ZiWieMLHKU5XcZnAMHhaAPCDiYwmDUB9msW98M/8g8LHq6RN71lZe4FgVZzX1u8ZLpfpg==","shasum":"34953dd20e0098494698eba20118c1bdb906f071","tarball":"https://registry.npmjs.org/@bmacnaughton/action-walk/-/action-walk-2.3.0.tgz","fileCount":4,"unpackedSize":8266,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF8QbjwP+9sB/jG9GVda1kyLTeDLi+OregoDS7NbspQFAiA3kka1j1q0NyXDEHiVkNn+IDW3Jv8k9aA75/iHSp9OJA=="}]},"_npmUser":{"name":"bmacnaughton","email":"bmacnaughton@gmail.com"},"maintainers":[{"name":"bmacnaughton","email":"bmacnaughton@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/action-walk_2.3.0_1700838326078_0.760240405628001"},"_hasShrinkwrap":false},"2.4.0":{"name":"@bmacnaughton/action-walk","access":"public","version":"2.4.0","description":"walk a directory tree performing actions","main":"action-walk.js","engines":{"node":">=12.12.0"},"directories":{"test":"test"},"scripts":{"test":"mocha test/*.test.js","coverage":"nyc --reporter=text mocha test/*.test.js","walk":"node bin/walk.js"},"keywords":["directory","tree","action","iterate","general","utility","recursive","walk","flexible"],"author":{"name":"Bruce A. MacNaughton"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/bmacnaughton/action-walk.git"},"bugs":{"url":"https://github.com/bmacnaughton/action-walk/issues"},"bin":{"action-walk":"bin/walk.js"},"devDependencies":{"chai":"^4.2.0","chai-as-promised":"^7.1.1","eslint":"^8.54.0","inquirer":"^9.2.12","mocha":"^8.1.3","nyc":"^15.1.0"},"_id":"@bmacnaughton/action-walk@2.4.0","gitHead":"7dae0388b415cbfe8a713660db1a3efc2df2aa78","homepage":"https://github.com/bmacnaughton/action-walk#readme","_nodeVersion":"18.18.2","_npmVersion":"9.8.1","dist":{"integrity":"sha512-a/Pk5a+ywb/ZjytRhr0nGHsoCbWIld98Jis7gkdSHL0fxlObu509Yx9U3d/oVbi/cyqvHAhFhER0L9M3SHv0lQ==","shasum":"c0ab01e60386b403885c8d4b46dc74ce760cd442","tarball":"https://registry.npmjs.org/@bmacnaughton/action-walk/-/action-walk-2.4.0.tgz","fileCount":4,"unpackedSize":8374,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDo79vaKoySl3XIoy/MLS56PVL9W2sKTMsKI1UrvkX7pwIhAM3d+KyTjgLarcRMHTWKCflXNgEHXvD1+t3DJIUmFEqS"}]},"_npmUser":{"name":"bmacnaughton","email":"bmacnaughton@gmail.com"},"maintainers":[{"name":"bmacnaughton","email":"bmacnaughton@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/action-walk_2.4.0_1701265725767_0.36257761688039114"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-24T15:05:25.980Z","2.3.0":"2023-11-24T15:05:26.262Z","modified":"2023-11-29T13:48:46.179Z","2.4.0":"2023-11-29T13:48:45.998Z"},"maintainers":[{"name":"bmacnaughton","email":"bmacnaughton@gmail.com"}],"description":"walk a directory tree performing actions","homepage":"https://github.com/bmacnaughton/action-walk#readme","keywords":["directory","tree","action","iterate","general","utility","recursive","walk","flexible"],"repository":{"type":"git","url":"git+https://github.com/bmacnaughton/action-walk.git"},"author":{"name":"Bruce A. MacNaughton"},"bugs":{"url":"https://github.com/bmacnaughton/action-walk/issues"},"license":"ISC","readme":"# action-walk\n\n![commit-test](https://github.com/bmacnaughton/action-walk/workflows/commit-test/badge.svg)\n\nMinimal utility to walk directory trees performing actions on each directory\nentry. `action-walk` has no external production dependencies and has only one\nstrong opinion - don't presume anything about why the directory tree is being\nwalked.\n\nNo presumptions means that this does little more than walk the tree. There\nare two options to facilitate implementing your code on top of `action-walk`.\nIf the boolean option `stat` is truthy `action-walk` will execute `fs.stat`\non the entry and pass that to you action handler. If the option `own` is\npresent `action-walk` will pass that to the action functions in a context\nobject.\n\n### usage\n\n`action-walk` should run on any version of node that supports the `node:` prefix\nwhen requiring built-in modules. It is tested on even-numbered versions of node\nstarting with 14 on both Linux and Windows.\n\n`npm install action-walk`\n\n### examples\n\n```\n//\n// example to walk the directory tree, skipping node_modules, and\n// totaling the number of bytes in each file.\n//\nconst walk = require('@bmacnaughton/action-walk');\n\nfunction dirAction (path, context) {\n  const {dirent, stat, own} = context;\n  if (own.skipDirs && own.skipDirs.indexOf(dirent.name) >= 0) {\n    return 'skip';\n  }\n  own.total += stat.size;\n}\nfunction fileAction (path, context) {\n  const {stat, own} = context;\n  own.total += stat.size;\n}\n\nconst own = {total: 0, skipDirs: ['node_modules']};\nconst options = {\n  dirAction,\n  fileAction,\n  own,\n  stat: true\n};\n\nwalk('.', options)\n  .then(() => {\n    console.log('total bytes in \".\"', own.total);\n  });\n\n// executed in the action-walk package root it will print something like\n// total bytes in \".\" 14778\n```\n\nsee `test/basics.test.js` or `bin/walk.js` for other examples.\n\n### api\n\n`await walk(directory, options = {})`\n\noptions\n- `dirAction` - called for each directory. If it returns `'skip'`, `action-walk` will not\nrecurse into the directory.\n- `fileAction` - called for each file and, if `options.linkAction` is not set, each symbolic link.\n- `linkAction` - called for each symbolic link when `options.linkAction` is set.\n- `otherAction` - called when the entry is not a file, directory, or symbolic link.\n- `stat` - if `'lstat'` call `fs.lstat` on the entry and add it to the action context as\nthe `stat` property. if otherwise truthy use `fs.stat`.\n- `own` - add this to the action context. it is your context for the action functions.\n\nIt's possible to call `walk()` with no options but probably not useful unless\nall you're wanting to do is seed the disk cache with directory entries. The\naction functions are where task-specific work is done.\n\nEach of the action function (`dirAction`, `fileAction`, `linkAction`, `otherAction`) is\ncalled with two arguments:\n- `filepath` for the entry starting with `directory`, e.g., if `directory` is `test` and\nthe entry is `basics.test.js` then `filepath` will be `test/basics.test.js`.\n- `context` is an object:\n```\n{\n  dirent, // the fs.Dirent object for the directory entry\n  stat,   // if `options.stat`, the object returned by `fs.stat` or `fs.lstat`\n  stack,  // the stack of directories above the current dirent item.\n  own     // `options.own`, if provided.\n}\n```\n\n`dirAction` is the only function with return value that matters. If\n`dirAction` returns the string `'skip'` (either directly or via a\nPromise) then `walk()` will not walk that branch of the directory tree.\n\nAll the action functions can return a promise if they need to perform\nasynchronous work but only the value of `dirAction` is meaningful.\n\n### todo\n\n- add error handling\n","readmeFilename":"README.md"}