{"id":26502725,"url":"https://github.com/shiwano/typhen","last_synced_at":"2025-03-20T18:24:12.277Z","repository":{"id":25117656,"uuid":"28539239","full_name":"shiwano/typhen","owner":"shiwano","description":":cyclone: Generates code or documentation from TypeScript.","archived":false,"fork":false,"pushed_at":"2018-09-19T11:06:57.000Z","size":752,"stargazers_count":40,"open_issues_count":2,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-17T10:37:09.832Z","etag":null,"topics":["typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/shiwano.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}},"created_at":"2014-12-27T15:03:13.000Z","updated_at":"2023-01-13T21:08:50.000Z","dependencies_parsed_at":"2022-08-23T01:50:53.969Z","dependency_job_id":null,"html_url":"https://github.com/shiwano/typhen","commit_stats":null,"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiwano%2Ftyphen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiwano%2Ftyphen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiwano%2Ftyphen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shiwano%2Ftyphen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shiwano","download_url":"https://codeload.github.com/shiwano/typhen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244591478,"owners_count":20477707,"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":["typescript"],"created_at":"2025-03-20T18:24:11.516Z","updated_at":"2025-03-20T18:24:12.268Z","avatar_url":"https://github.com/shiwano.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# typhen [![Build Status](https://secure.travis-ci.org/shiwano/typhen.png?branch=master)](http://travis-ci.org/shiwano/typhen) [![npm version](https://badge.fury.io/js/typhen.svg)](http://badge.fury.io/js/typhen)\n\n\u003e Generates code or documentation from TypeScript.\n\nThe definition and the template:\n\n```ts\ninterface Foo {\n  bar: string;\n  baz(qux: string): void;\n}\n```\n\n```hbs\nclass {{name}}\n{\n  {{#each properties}}\n  public {{type}} {{upperCamel name}} { get; set; }\n  {{/each}}\n  {{#each methods}}\n  {{#each callSignatures}}\n  public {{returnType}} {{upperCamel ../name}}({{#each parameters}}{{type}} {{name}}{{#unless @last}}, {{/unless}}{{/each}}):\n  {\n    // do something\n  }\n  {{/each}}\n  {{/each}}\n}\n```\n\nWill generate this below:\n\n```cs\nclass Foo\n{\n  public string Bar { get; set; }\n  public void Baz(string qux)\n  {\n    // do something\n  }\n}\n```\n\n## Getting Started\n\n### Command Line Tool\nInstall the module with: `npm install -g typhen`\n\nIf tsconfig.json or typhenfile.js exists in the current directory:\n\n```sh\n$ typhen\n```\n\nOtherwise:\n\n```sh\n$ typhen --plugin typhen-awesome-plugin --dest generated definitions.d.ts\n```\n\n### Node Module\nInstall the module with: `npm install --save typhen`\n\nExample:\n\n```js\nconst typhen = require('typhen');\nconst result = typhen.parse('./foo.d.ts');\nconsole.log('Parsed types: ', result.types.map(t =\u003e t.fullName));\nconsole.log('Parsed modules: ', result.modules.map(m =\u003e m.fullName));\n```\n\n## Documentation\n\n### tsconfig.json\nIf you want to execute typhen by the tsconfig.json, you have to set `typhen` property to tsconfig.json, and make the typhen execution settings.\n\nExample:\n\n```js\n{\n  \"files\": [\n    \"src/index.ts\"\n  ],\n  \"compilerOptions\": {\n    \"module\": \"commonjs\",\n    \"target\": \"ES5\"\n  },\n  \"typhen\": [\n    {\n      \"plugin\": \"typhen-awesome-plugin\",\n      \"pluginOptions\": { \"optionName\": \"option value\" }, // Optional. Default value is {}.\n      \"outDir\": \"output-directory\",\n      \"files\": [ \"src/typings/definitions.d.ts\" ]        // Optional. Default value is root's files.\n      \"include\": [ \"src/typings/include/**/*\" ]          // Optional. Default value is root's include.\n      \"exclude\": [ \"src/typings/exclude/**/*\" ]          // Optional. Default value is root's exclude.\n    }\n  ]\n}\n```\n\n### typhenfile.js\nThe typhenfile.js is a valid JavaScript file that belongs in the root directory of your project, and should be committed with your project source.\nYou can make complex settings that can not be in the tsconfig.json.\n\nThe typhenfile.js is comprised of the following parts:\n\n* The \"wrapper\" function that returns a Promise object of the [bluebird](https://github.com/petkaantonov/bluebird).\n* Loading or creating a plugin.\n* Running with configuration.\n\nExample:\n\n```js\nconst ts = require('typescript');\n\nmodule.exports = (typhen) =\u003e {\n  return typhen.run({                    // typhen.run returns a Promise object of the bluebird.\n    plugin: typhen.loadPlugin('typhen-awesome-plugin', {\n      optionName: 'option value'\n    }),\n    src: 'typings/lib/definitions.d.ts', // string or string[]\n    dest: 'generated',\n    include: ['typings/include/**/*'],   // Optional. Default value is [].\n    exclude: ['typings/exclude/**/*'],   // Optional. Default value is [].\n    cwd: '../other/current',             // Optional. Default value is process.cwd().\n    typingDirectory: 'typings',          // Optional. Default value is the directory name of the src.\n    defaultLibFileName: 'lib.core.d.ts', // Optional. Default value is undefined, then the typhen uses the lib.d.ts or lib.es6.d.ts.\n    compilerOptions: {                   // Optional. Default value is { module: ts.ScriptTarget.CommonJS, noImplicitAny: true, target: ts.ScriptTarget.ES6 }\n      target: ts.ScriptTarget.ES6\n    }\n  }).then((files) =\u003e {\n    console.log('Done!');\n  }).catch((e) =\u003e {\n    console.error(e);\n  });\n};\n```\n\n### Plugin\nA typhen plugin can be defined in the typhenfile.js or an external module.\n\nExample:\n\n```js\nmodule.exports = (typhen, options) =\u003e {\n  return typhen.createPlugin({\n    pluginDirectory: __dirname,\n    newLine: '\\r\\n',                   // Optional. Default value is '\\n'.\n    namespaceSeparator: '::',          // Optional. Default value is '.'.\n    customPrimitiveTypes: ['integer'], // Optional. Default value is [].\n    disallow: {                        // Optional. Default value is {}.\n      any: true,\n      tuple: true,\n      unionType: true,\n      intersectionType: true,\n      overload: true,\n      generics: true,\n      anonymousObject: true,\n      anonymousFunction: true,\n      literalType: true,\n      mappedType: true\n    },\n    handlebarsOptions: {               // Optional. Default value is null.\n      data: options,                   // For details, see: http://handlebarsjs.com/execution.html\n      helpers: {\n        baz: (str) =\u003e {\n          return str + '-baz';\n        }\n      }\n    },\n\n    rename: (symbol, name) =\u003e { // Optional. Default value is a function that returns just the name.\n      if (symbol.kind === typhen.SymbolKind.Array) {\n        return '[]';\n      }\n      return name;\n    },\n\n    generate: (generator, types, modules) =\u003e {\n      generator.generateUnlessExist('templates/README.md', 'README.md');\n\n      types.forEach((type) =\u003e {\n        switch (type.kind) {\n          case typhen.SymbolKind.Enum:\n            generator.generate('templates/enum.hbs', 'underscore:**/*.rb', type);\n            break;\n          case typhen.SymbolKind.Interface:\n          case typhen.SymbolKind.Class:\n            generator.generate('templates/class.hbs', 'underscore:**/*.rb', type);\n            break;\n        }\n      });\n      modules.forEach((module) =\u003e {\n        generator.generate('templates/module.hbs', 'underscore:**/*.rb', module);\n      });\n      generator.files.forEach((file) =\u003e {\n        // Change a file that will be written.\n      });\n      return new Promise((resolve, reject) =\u003e { // If you want async processing, return a Promise object.\n        // Do async processing.\n      });\n    }\n  });\n};\n```\n\n### Templating\nThe typhen has used the [Handlebars template engine](http://handlebarsjs.com/) to render code, so you can use the following global helpers and custom helpers which are defined in the typhenfile.js or a plugin.\n\n#### and Helper\nConditionally render a block if all values are truthy.\n\nUsage:\n```hbs\n    {{#and type.isInterface type.isGenericType type.typeArguments}}\n      This type is an instantiation of a generic interface.\n    {{/and}}\n```\n\n#### or Helper\nConditionally render a block if one of the values is truthy.\n\nUsage:\n```hbs\n    {{#or type.isArray type.isTuple type.isClass}}\n      This type is an array, a tuple, or a class.\n    {{/or}}\n```\n\n#### underscore Helper\nTransforms a string to underscore.\n\nUsage:\n```hbs\n    {{underscore 'FooBarBaz'}}\n                  foo_bar_baz\n```\n\n#### upperCamel Helper\nTransforms a string to upper camel case.\n\nUsage:\n```hbs\n    {{upperCamel 'foo_bar_baz'}}\n                  FooBarBaz\n```\n\n#### lowerCamel Helper\nTransforms a string to lower camel case.\n\nUsage:\n```hbs\n    {{lowerCamel 'foo_bar_baz'}}\n                  fooBarBaz\n```\n\n#### pluralize\nTransforms a string to plural form.\n\nUsage:\n```hbs\n    {{pluralize 'person'}}\n                 people\n```\n\n#### singularize\nTransforms a string to singular form.\n\nUsage:\n```hbs\n    {{singularize 'people'}}\n                   person\n```\n\n#### defaultValue\nRender a fallback value if a value doesn't exist.\n\nUsage:\n```hbs\n    {{defaultValue noExistingValue 'missing'}}\n                   missing\n```\n\n### Custom Primitive Types\nIf you want to use a custom primitive type, you will add the interface name to `customPrimitiveTypes` option in your plugin. Then the typhen will parse the interface as a primitive type.\n\n## Plugins\nIf you want to add your project here, feel free to submit a pull request.\n\n* [typhen-json-schema](https://github.com/shiwano/typhen-json-schema) - Converts TypeScript Interfaces to JSON Schema\n\n## TypeScript Version\n2.2.2\n\n## Migration Informations\n * 2016-10-09 v1.0.0\n   * Drop support for Node versions less than 4.0.0.\n   * Replaced ObjectType's `stringIndexType` and `numberIndexType` to `stringIndex` and `numberIndex`.\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [gulp.js](http://gulpjs.com/).\n\n## Contributors\n\n* Shogo Iwano (@shiwano)\n* Sebastian Lasse (@sebilasse)\n* Zacarias F. Ojeda (@zojeda)\n\n## License\nCopyright (c) 2014 Shogo Iwano\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiwano%2Ftyphen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshiwano%2Ftyphen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshiwano%2Ftyphen/lists"}