Package Exports
- typhen
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (typhen) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
typhen

Generates the code from the TypeScript declaration source files.
The definition and the template given:
interface Foo {
bar: string;
baz(qux: string): void;
}
class {{name}} {
{{#each properties}}
public {{type}} {{upperCamelCase name}} { get; set; }
{{/each}}
{{#each methods}}
{{#each callSignatures}}
public {{returnType}} {{upperCamelCase ../name}}({{#each parameters}}{{type}} {{name}}{{#unless @last}}, {{/unless}}{{/each}}): {
// do something
}
{{/each}}
{{/each}}
}
Will generate this below:
class Foo {
public string Bar { get; set; }
public void Baz(string qux) {
// do something
}
}
Getting Started
Install the module with: npm install -g typhen
If typhenfile.js exists in the current directory:
$ typhen
Otherwise:
$ typhen foo/bar/typhenfile.js
$ typhen --plugin typhen-awesome-plugin --dest generated definitions.d.ts
Documentation
typhenfile.js
The typhenfile.js is a valid JavaScript file that belongs in the root directory of your project, and should be committed with your project source.
The typhenfile.js is comprised of the following parts:
- The "wrapper" function that returns a Promise object of the bluebird.
- Loading or creating a plugin.
- Running with configuration.
Example:
module.exports = function(typhen) {
var plugin = typhen.loadPlugin('typhen-awesome-plugin', {
optionName: 'option value'
});
return typhen.run({ // typhen.run returns a Promise object of the bluebird.
plugin: plugin,
src: 'typings/lib/definitions.d.ts',
dest: 'generated',
cwd: '../other/current', // Optional. Default value is process.cwd().
typingDirectory: 'typings', // Optional. Default value is the directory name of the src.
defaultLibFileName: 'lib.core.d.ts', // Optional. Default value is undefined, then the typhen uses the lib.d.ts.
disallow: { // Optional. Default value is {}.
any: true,
tuple: true,
overload: true,
generics: true
}
}).then(function(files) {
console.log('Done!');
}).catch(function(e) {
console.error(e);
});
};
Plugin
A typhen plugin can be defined in the typhenfile.js or an external module.
Example:
module.exports = function(typhen, options) {
return typhen.createPlugin({
pluginDirectory: __dirname,
newLine: '\r\n', // Optional. Default value is '\n'.
namespaceSeparator: '::', // Optional. Default value is '.'.
handlebarsOptions: { // Optional. Default value is null.
data: options, // For details, see: http://handlebarsjs.com/execution.html
helpers: {
baz: function(str) {
return str + '-baz';
}
}
},
rename: function(symbol, name) { // Optional. Default value is a function that returns just the name.
if (symbol.kind === typhen.SymbolKinds.Array) {
return '[]';
}
return name;
},
generate: function(generator, types, modules) {
generator.generateUnlessExist('templates/README.md', 'README.md');
types.forEach(function(type) {
switch (type.kind) {
case typhen.SymbolKinds.Enum:
generator.generate('templates/enum.hbs', 'underscore:**/*.rb', type);
break;
case typhen.SymbolKinds.Interface:
case typhen.SymbolKinds.Class:
generator.generate('templates/class.hbs', 'underscore:**/*.rb', type);
break;
}
});
modules.forEach(function(module) {
generator.generate('templates/module.hbs', 'underscore:**/*.rb', module);
});
generator.files.forEach((file) => {
// Change a file that will be written.
});
return new Promise(function(resolve, reject) { // If you want async processing, return a Promise object.
// Do async processing.
});
}
});
};
Templating
The typhen has used the Handlebars template engine to render the code, so you can use the following global helpers and custom helpers which are defined in the typhenfile.js or a plugin.
underscore Helper
Transforms a string to underscore.
Usage:
{{underscore 'FooBarBaz'}}
foo_bar_baz
upperCamelCase Helper
Transforms a string to upper camel case.
Usage:
{{upperCamelCase 'foo_bar_baz'}}
FooBarBaz
lowerCamelCase Helper
Transforms a string to lower camel case.
Usage:
{{lowerCamelCase 'foo_bar_baz'}}
fooBarBaz
pluralize
Transforms a string to plural form.
Usage:
{{pluralize 'person'}}
people
singularize
Transforms a string to singular form.
Usage:
{{singularize 'people'}}
person
Custom Primitive Types
If you want to use a custom primitive type, you will define the interface which is extended from the TyphenPrimitiveType
in your definitions. Then the typhen will parse the interface as a primitive type. By default, the typhen has prepared the following primitive types in the lib.typhen.d.ts.
integer
A number without a fraction or exponent part.
TypeScript Version
1.3.0
Contributing
In 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.
License
Copyright (c) 2014 Shogo Iwano Licensed under the MIT license.