1.1.0 • Published 7 years ago

ts-comment v1.1.0

Weekly downloads
730
License
MIT
Repository
github
Last release
7 years ago

ts-comment

npm build coverage

utils for comments in TypeScript/JavaScript file

Changelog

Install

# using npm
npm install --save ts-comment

# using yarn
yarn add ts-comment

Usage

import * as ts_comment from 'ts-comment';

const file_content = `
  class X {}
  // comment 1
  const y = 0;
  /* comment 2 */
  function z() {}
`;

ts_comment.gets(file_content); //=> ['// comment 1', '/* comment 2 */']

API

/**
 * iterate every comment, return `false` to stop iteration
 */
function for_each(
  source: string | ts.SourceFile,
  callback: (comment: string, scanner: ts.Scanner, source_file: ts.SourceFile) => boolean | void,
  ts?: typeof ts,
): void;

/**
 * get comments from source, optional callback for custom results
 */
function gets(source: string | ts.SourceFile): string[];
function gets<T>(
  source: string | ts.SourceFile,
  callback: (comment: string, scanner: ts.Scanner, source_file: ts.SourceFile) => T,
  ts?: typeof ts,
): T[];

Development

# lint
yarn run lint

# build
yarn run build

# test
yarn run test

License

MIT © Ika