{"id":20551508,"url":"https://github.com/generate/generator-util","last_synced_at":"2025-04-14T11:24:17.774Z","repository":{"id":93328625,"uuid":"50559689","full_name":"generate/generator-util","owner":"generate","description":"Utils for `generate` generators.","archived":false,"fork":false,"pushed_at":"2020-04-01T00:04:57.000Z","size":27,"stargazers_count":6,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T02:03:07.949Z","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/generate.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":"2016-01-28T05:57:55.000Z","updated_at":"2022-09-13T09:22:00.000Z","dependencies_parsed_at":"2023-03-04T09:30:42.853Z","dependency_job_id":null,"html_url":"https://github.com/generate/generator-util","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generate%2Fgenerator-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generate%2Fgenerator-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generate%2Fgenerator-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/generate%2Fgenerator-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/generate","download_url":"https://codeload.github.com/generate/generator-util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248869765,"owners_count":21174927,"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-11-16T02:31:29.120Z","updated_at":"2025-04-14T11:24:17.760Z","avatar_url":"https://github.com/generate.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# generator-util [![NPM version](https://img.shields.io/npm/v/generator-util.svg)](https://www.npmjs.com/package/generator-util) [![Build Status](https://img.shields.io/travis/jonschlinkert/generator-util.svg)](https://travis-ci.org/jonschlinkert/generator-util)\n\n\u003e Utils for `generate` generators.\n\n## TOC\n\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n- [Related projects](#related-projects)\n- [Contributing](#contributing)\n- [Building docs](#building-docs)\n- [Running tests](#running-tests)\n- [Author](#author)\n- [License](#license)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install generator-util --save\n```\n\n## Usage\n\n```js\nvar util = require('generator-util');\n```\n\n## API\n\n### [.homeRelative](index.js#L99)\n\nReturn a home-relative filepath\n\n**Params**\n\n* `filepath` **{String}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nutils.homeRelative('foo');\n//=\u003e 'dev/foo'\n```\n\n### [.isDirectory](index.js#L120)\n\nReturn true if a filepath exists and is a directory.\n\n**Params**\n\n* `filepath` **{String}**\n* `returns` **{Boolean}**\n\n### [.renameKey](index.js#L133)\n\nRename the `key` used for storing views/templates\n\n**Params**\n\n* `key` **{String}**\n* `view` **{Object}**: the `renameKey` method is used by [templates](https://github.com/jonschlinkert/templates) for both setting and getting templates. When setting, `view` is exposed as the second parameter.\n* `returns` **{String}**\n\n### [.toAlias](index.js#L157)\n\nOpposite of `.toFullname`, creates an \"alias\" from the given `name` by either stripping `options.prefix` from the name, or just removing everything up to the first dash. If `options.alias` is a function, it will be used instead.\n\n**Params**\n\n* `name` **{String}**\n* `options` **{Object}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nutils.toAlias('generate-foo');\n//=\u003e 'foo';\n\nutils.toAlias('a-b-c', {prefix: 'a-b'});\n//=\u003e 'c';\n```\n\n### [.toFullname](index.js#L187)\n\nOpposite of `.toAlias`, creates a generator name from the given `alias` and `namespace`.\n\n**Params**\n\n* `alias` **{String}**\n* `namespace` **{String}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nutils.toFullname('foo', 'generate');\n//=\u003e 'generate-foo';\n\nutils.toFullname('generate-bar', 'generate');\n//=\u003e 'generate-bar'\n```\n\n### [.toGeneratorPath](index.js#L234)\n\nCreate an object-path for looking up a generator.\n\n**Params**\n\n* `name` **{String}**\n* `returns` **{String}**\n\n**Example**\n\n```js\nutils.toGeneratorPath('a.b.c');\n//=\u003e 'generators.a.generators.b.generators.c'\n```\n\n### [.getGenerator](index.js#L256)\n\nGet a generator from `app`.\n\n**Params**\n\n* `app` **{Object}**\n* `name` **{String}**: Generator name\n* `returns` **{Object}**: Returns the generator instance.\n\n### [.tryResolve](index.js#L299)\n\nTry to `require.resolve` module `name`, first locally then in the globaly npm directory. Fails silently if not found.\n\n**Params**\n\n* `name` **{String}**: The name or filepath of the module to resolve\n* `options` **{Object}**: Pass `options.cwd` and/or `options.configfile` (filename) to modify the path used by `resolve`.\n* `returns` **{String|undefined}**\n\n**Example**\n\n```js\nutils.tryResolve('foo');\n// or\nutils.tryResolve('generate-foo');\n// or\nutils.tryResolve('generate-foo', {cwd: require('global-modules')});\n// or\nutils.tryResolve('./foo/bar/baz.js');\n```\n\n### [.tryRequire](index.js#L341)\n\nTry to require the given module, failing silently if it doesn't exist. The function first calls `require` on the given `name`, then tries `require(path.resolve(name))` before giving up.\n\n**Params**\n\n* `name` **{String}**: The module name or file path\n* `returns` **{any|undefined}**: Returns the value of requiring the specified module, or `undefined` if unsuccessful.\n\n**Example**\n\n```js\nutils.tryRequire('foo');\n```\n\n### [.tableize](index.js#L376)\n\nModified from the `tableize` lib, which replaces\ndashes with underscores, and we don't want that behavior.\nTableize `obj` by flattening and normalizing the keys.\n\n**Params**\n\n* **{Object}**: obj\n* `returns` **{Object}**\n\n### [.isFunction](index.js#L431)\n\nReturns true if the given `value` is a function.\n\n**Params**\n\n* `value` **{any}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nutils.isFunction('foo');\n//=\u003e false\n\nutils.isFunction(function() {});\n//=\u003e true\n```\n\n### [.isBoolean](index.js#L451)\n\nReturns true if the given `value` is a boolean.\n\n**Params**\n\n* `value` **{any}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nutils.isBoolean('foo');\n//=\u003e false\n\nutils.isBoolean(false);\n//=\u003e true\n```\n\n### [.isString](index.js#L471)\n\nReturns true if a the given `value` is a string.\n\n**Params**\n\n* `value` **{any}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nutils.isString('foo');\n//=\u003e false\n\nutils.isString({});\n//=\u003e true\n```\n\n### [.isObject](index.js#L491)\n\nReturns true if a the given `value` is an object.\n\n**Params**\n\n* `value` **{any}**\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\nutils.isObject('foo');\n//=\u003e false\n\nutils.isObject({});\n//=\u003e true\n```\n\n### [.arrayify](index.js#L510)\n\nCast the given `value` to an array.\n\n**Params**\n\n* `value` **{String|Array}**\n* `returns` **{Array}**\n\n**Example**\n\n```js\nutils.arrayify('foo');\n//=\u003e ['foo']\n\nutils.arrayify(['foo']);\n//=\u003e ['foo']\n```\n\n## Related projects\n\n* [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base) | [homepage](https://github.com/node-base/base)\n* [base-fs](https://www.npmjs.com/package/base-fs): base-methods plugin that adds vinyl-fs methods to your 'base' application for working with the file… [more](https://www.npmjs.com/package/base-fs) | [homepage](https://github.com/jonschlinkert/base-fs)\n* [base-pipeline](https://www.npmjs.com/package/base-pipeline): base-methods plugin that adds pipeline and plugin methods for dynamically composing streaming plugin pipelines. | [homepage](https://github.com/jonschlinkert/base-pipeline)\n* [base-plugins](https://www.npmjs.com/package/base-plugins): Upgrade's plugin support in base applications to allow plugins to be called any time after… [more](https://www.npmjs.com/package/base-plugins) | [homepage](https://github.com/jonschlinkert/base-plugins)\n* [base-runner](https://www.npmjs.com/package/base-runner): Orchestrate multiple instances of base-methods at once. | [homepage](https://github.com/jonschlinkert/base-runner)\n* [base-tasks](https://www.npmjs.com/package/base-tasks): base-methods plugin that provides a very thin wrapper around [https://github.com/jonschlinkert/composer](https://github.com/jonschlinkert/composer) for adding task methods to… [more](https://www.npmjs.com/package/base-tasks) | [homepage](https://github.com/jonschlinkert/base-tasks)\n* [generate](https://www.npmjs.com/package/generate): Fast, composable, highly extendable project generator with a user-friendly and expressive API. | [homepage](https://github.com/generate/generate)\n\n## Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/generator-util/issues/new).\n\n## Building docs\n\nGenerate readme and API documentation with [verb](https://github.com/verbose/verb):\n\n```sh\n$ npm install verb \u0026\u0026 npm run docs\n```\n\nOr, if [verb](https://github.com/verbose/verb) is installed globally:\n\n```sh\n$ verb\n```\n\n## Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d \u0026\u0026 npm test\n```\n\n## Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)\n\n## License\n\nCopyright © 2016 [Jon Schlinkert](https://github.com/jonschlinkert)\nReleased under the [MIT license](https://github.com/jonschlinkert/generator-util/blob/master/LICENSE).\n\n***\n\n_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on March 04, 2016._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenerate%2Fgenerator-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenerate%2Fgenerator-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenerate%2Fgenerator-util/lists"}