{"id":22428476,"url":"https://github.com/momsfriendlydevco/es6","last_synced_at":"2025-07-04T13:35:02.367Z","repository":{"id":57683099,"uuid":"493874183","full_name":"MomsFriendlyDevCo/ES6","owner":"MomsFriendlyDevCo","description":"Various ES6 utilities","archived":false,"fork":false,"pushed_at":"2023-09-22T08:00:17.000Z","size":349,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-04T03:12:37.483Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MomsFriendlyDevCo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-19T01:02:15.000Z","updated_at":"2022-05-19T01:02:49.000Z","dependencies_parsed_at":"2023-09-22T16:03:46.505Z","dependency_job_id":null,"html_url":"https://github.com/MomsFriendlyDevCo/ES6","commit_stats":{"total_commits":32,"total_committers":1,"mean_commits":32.0,"dds":0.0,"last_synced_commit":"3dfcbe7eeea59b100e0281a97d60632860392a29"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MomsFriendlyDevCo/ES6","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2FES6","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2FES6/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2FES6/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2FES6/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MomsFriendlyDevCo","download_url":"https://codeload.github.com/MomsFriendlyDevCo/ES6/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MomsFriendlyDevCo%2FES6/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263550774,"owners_count":23478868,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-05T20:14:55.413Z","updated_at":"2025-07-04T13:35:02.345Z","avatar_url":"https://github.com/MomsFriendlyDevCo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"@MomsFriendlyDevCo/ES6\n======================\nVarious ES6 utilities.\n\n* [dirname](#dirname) - Fetch the directory path of the current file\n* [discover()](#discover) - Find other ES6 compliant NPM modules by various query options\n* [importAll()](#importall) - Import various ES6 modules using a glob\n* [sortPaths()](#sortpaths) - Sort input paths in a logical way\n\n\nAPI\n===\n\nAll methods are importable directly or via a default object:\n\n```javascript\n// Import everything as es6\nimport es6 from '@momsfriendlydevco';\nes6.importAll(...);\nes6.$FUNC(...);\n\n// Import individual functions\nimport {dirName, importAll, sortPaths} from '@momsfriendlydevco/es6';\ndirName(...);\nimportAll(...);\nsortPaths(...);\n\n// Direct import via path\nimport importAll from '@momsfriendlydevco/es6/importAll';\nimportAll(...);\n```\n\n\nbackport(path, extract)\n-----------------------\nConvert an ESM module into CJS, optionally extracting a subkey.\nReturns a promise.\n\n```javascript\nconst {backport} = require('@momsfriendlydevco/es6');\n\n// Import an ESM module into CJS\nlet {execa} = await backport('execa');\n\n// Just extract one key\nlet {execa} = await backport('execa', 'execaSync'));\n```\n\n\ndirName(options)\n----------------\nIf called as a string the value of `options.relativeTo` is assumed. e.g. `dirName('..')` gets the parent directory.\nReturns a string.\nFetch the directory of the calling function.\n\n| Option                  | Type      | Default | Description                                                                     |\n|-------------------------|-----------|---------|---------------------------------------------------------------------------------|\n| `relativeTo`            | `String`  |         | Compute the dirname + the relative path (e.g. `'..'` to get the parent dir)     |\n| `stackDepth`            | `Number`  | `1`     | How far down the call stack to search for a path                                |\n| `translateFileProtocol` | `Boolean` | `true`  | Whether to replace the `file://` prefix with a simple on-disk path              |\n| `includeFilename`       | `Boolean` | `false` | Whether to include the actual filename, if false only the directory is returned |\n\n\n**Notes:**\n* `stackDepth` is the number of functions in the stack to look upwards from the actual dirName worker. The default of `1` means look to the callee. If you wish to look higher up the stack increase this value.\n\n\n```javascript\nimport {dirName} from '@momsfriendlydevco/es6';\n\nlet myPath = dirName(); //=~ the directory the saved script file exists in\n\nlet myFile = dirName({includeFilename: true}); //=~ Full path including file\n```\n\n\ndiscover(options)\n-----------------\nFind other ES6 compliant NPM modules by various query options.\n\nOptions are:\n\n| Option   | Type                  | Default        | Description                                                                                                                                |\n|----------|-----------------------|----------------|--------------------------------------------------------------------------------------------------------------------------------------------|\n| `filter` | `RegExp` / `Function` |                | Optional filter function to query modules. If a function this is called as `(npmName, npmAttrs)`, if a RegExp its used to match the npm.id |\n| `local`  | `Boolean`             | `false`        | Query local repositories                                                                                                                   |\n| `global` | `Boolean`             | `true`         | Query global repositories                                                                                                                  |\n| `want`   | `String`              | `'collection'` | Desired output type. ENUM: `'collection'`, `'object'`, `'set'`\n\nReturns a list of modules as an array (depending on `want`)\n\n\nimportAll(paths, options)\n-------------------------\nImport various ES6 modules using a glob.\nReturns a promise.\nThis module uses the `sortPaths` API to return paths in a logical order (i.e. `./lib/a.js` is included before `./lib/a.a.js`).\n\n\nOptions are:\n\n| Option           | Type                      | Default         | Description                                                                |\n|------------------|---------------------------|-----------------|----------------------------------------------------------------------------|\n| `imports`        | Various*                  | `[]`            | Alternate way to specify the paths input, see notes                        |\n| `includePath`    | `Boolean`                 | `false`         | Include an additonal `{path:String}` property per output                   |\n| `glob`           | `Boolean`                 | `true`          | Support globbing in paths                                                  |\n| `method`         | `String`, `Array\u003cString\u003e` |                 | If specified run the method or array of methods after each import          |\n| `methodPerCycle` | `Boolean`                 | `false`         | Run each method in an outer loop rather than importing all methods at once |\n| `args`           | `Array`                   | `[]`            | Arguments to pass to the `method` on run                                   |\n| `root`           | `String`                  | Auto*           | Root path of the project to resolve modules from                           |\n| `sort`           | `Function`                | `ES6.sortPaths` | Function to use to sort evaluated glob paths per run                       |\n| `sortOptions`    | `Object`                  | `{}`            | Options passed to the sort function                                        |\n| `sortWhen`       | `String`                  | `perGlob`       | When to sort. ENUM: `perGlob` or `preImport`                               |\n| `uniq`           | `Boolean`                 | `true`          | Include each eventual path only once, avoiding duplicates                  |\n\n\n**Notes:**\n* `imports` can be a single string glob, array of globs or a single function / array of functions which (async eventually) returns the strings / globs to include\n* `sortWhen` determines when the sorting algorithm should operate. `perGlob` sorts each glob evaluation, meaning that the order of paths is preserved except globs that \"expand\" into multiple files. `preImport` Expands all globs first then sorts all files which could potentially destroy any preferred order\n* `methodPerCycle` can be used to run imports in a logical order (e.g. all `init()` imports then all `default()` imports). All Async methods are resolved in order when used.\n\n\n```javascript\n// Glob include all files specified (in a logical order) running the 'init' method for each\nawait importAll([\n\t'./libs/*.js',\n\t'./middleware/*.js',\n], {\n\tmethod: 'init',\n})\n```\n\n\nsortPaths(paths, options)\n-------------------------\nSort input paths in a logical way.\n\nSorts an array of paths in a logical, \"human\" order.\n\nOptions are:\n\n| Option          | Type       | Default  | Description                                           |\n|-----------------|------------|----------|-------------------------------------------------------|\n| `stripDir`      | `Boolean`  | `false`  | Whether to ignore the path component when sorting     |\n| `stripExt`      | `Boolean`  | `true`   | Whether to ignore the file extension when sorting     |\n| `rewritePath`   | `Function` | See code | The path rewrite function (uses the `strip*` options) |\n| `locale`        | `String`   | `'en'`   | The locale region when sorting                        |\n| `localeOptions` | `Object`   | See code | Locale options when sorting                           |\n| `uniq`          | `Boolean`  | `true`   | Whether to de-duplicate the calculated paths          |\n\n\n```javascript\nsortPaths([\n\t'./lib/a.js',\n\t'./lib/a.a.js', // Expects to extend 'a'\n\t'./lib/a.b.js',\n\t'./lib/a.c.js',\n\t'\n\t'./lib/z.js',\n\t'./lib/z-1.js',\n\t'./lib/z-2.js',\n\t'./lib/z-3.js',\n\t'./lib/z-10.js', // Numerics are correctly evaluated in order\n]); //= The above \"ideal\" order\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Fes6","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmomsfriendlydevco%2Fes6","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomsfriendlydevco%2Fes6/lists"}