![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Recusively load files from a directory and return an object with keys from the directory and file names
Create an object from a directory tree.
dir-obj
creates an object with keys for each directory (by name).
All files within a directory that can be required (.js
or .json
) are added to the directory object, using the base filename as the key and require('file.js')
as the value.
This is useful for things like loading test fixture data.
You can also customize how dir-obj
processes the directory tree
const fixtures = dirObj.readDirectory(path.join(__dirname, 'fixtures'), {
// Use the `filter` option to filter all directories and files
// Return `true` to include the directory or file (call `file.isDirectory` to check)
// Return `false` to exclude the file or directory from the result
// The default is to only allow `.js` and `.json` files
filter: file => (file.isDirectory || file.isRequirable) && file.name !== 'index.js',
// This function takes a File object and returns the value to be added to the object
// You can mutate `File.key` to change the object key used to reference the value
// You can return `undefined` to not include the file in the result
// The default `fileTransform` just calls `require(file.fullpath)`
// Example: Change whitespace in a filename to `_` then set the value using `require`
fileTransform: file => {
file.key = file.basename.replace(/\s/g, '_');
return require(file.fullpath);
},
// This function takes a File (which is a directory) and a value, which is the recursively
// calculated value of that directory
// Example: Do not include any directories that have no child keys
dirTransform: (file, value) => Object.getOwnPropertyNames(value).length > 0 ? value : undefined
});
Using the default options:
/*
directory structure:
fixtures
ok
success.json
responses
success.json
*/
const path = require('path');
const dirObj = require('dir-obj');
const fixtures = dirObj.readDirectory(path.combine(__dirname, '/fixtures'));
describe('test', function () {
it('should work', function () {
nock(/api/).get('/ok').reply(200, fixtures.ok.success);
request('/')
.expect(200, fixtures.ok.response.success);
});
});
Loading SQL files:
// Get an object where the value of each key is a string loaded from each SQL file
const fixtures = dirObj.readDirectory(path.resolve('../../models/sql'), {
filter: file => file.isDirectory || file.ext === '.sql'.
fileTransform: file => file.readSync() // helper function equivilent to `fs.readFileSync(file.fullpath, 'utf8')`
});
FAQs
Recusively load files from a directory and return an object with keys from the directory and file names
The npm package dir-obj receives a total of 3 weekly downloads. As such, dir-obj popularity was classified as not popular.
We found that dir-obj demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.