ts-comment
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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

Package Sidebar

Install

npm i ts-comment

Weekly Downloads

397

Version

1.1.0

License

MIT

Last publish

Collaborators

  • ikatyang