Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

count.macro

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

count.macro

[![](https://github.com/coffee-cup/count.macro/workflows/CI/badge.svg)](https://github.com/coffee-cup/count.macro/actions?query=workflow%3ACI) [![](https://img.shields.io/npm/v/count.macro?style=flat-square)](https://www.npmjs.com/package/count.macro) [![

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

count.macro

Babel
Macro

Count lines or words in files at build time

Installation

count.macro is a Babel macro. This will work out of the box with CRA, Gatsby, and Next.

npm install --save-dev count.macro

Usage

Line and word information is based on the source file, not the output file.

For example, this file

import { lines, linesIn, words, wordsIn } from "count.macro";

console.log(`This file has ${lines} lines`);
console.log(`lines.txt has ${linesIn("./lines.txt")}`);

console.log(`This file has ${words} words`);
console.log(`words.txt has ${wordsIn("./words.txt")}`);

will be transpiled to

console.log(`This file has ${7} lines`);
console.log(`lines.txt has ${100}`);
console.log(`This file has ${25} words`);
console.log(`words.txt has ${1000}`);

Named Exports

  • lines is a number that will be transpiled to number of lines in current file
  • linesIn is a function that takes a filename as an argument. The call will be replaced with the number of lines in the file (relative to the current file).
  • words is a number that will be transpiled to number of words in current file.
  • wordsIn is a function that takes a filename as an argument. The call will be replaced with the number of words in the file (relative to the current file).

CodeSandbox Example

Edit count.macro

Keywords

FAQs

Package last updated on 10 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc