Giter VIP home page Giter VIP logo

Comments (5)

kevva avatar kevva commented on August 15, 2024

import stripAnsi from 'strip-ansi'. It only exports a function. Maybe have a look here for more info https://github.com/DefinitelyTyped/DefinitelyTyped/tree/f2b6506ba550e909224e43ecd07e15bbfbfbfce3/types/strip-ansi.

from strip-ansi.

timkraut avatar timkraut commented on August 15, 2024

@kevva Thanks for your quick answer! Unfortunately, it doesn't work... import stripAnsi from "strip-ansi"; results in strip_ansi_1.default is not a function. If I import the function using const stripAnsi = require("strip-ansi");, it works. Not sure why it doesn't with ES6 imports.

from strip-ansi.

kevva avatar kevva commented on August 15, 2024

Because CommonJS and modules works differently. It's like when you're requiring a module in CommonJS where you have to write:

const module = require('module').default;

from strip-ansi.

timkraut avatar timkraut commented on August 15, 2024

I see. Is there any way that I can import this module using ES6 module syntax?

Alternatively, changing the module to:

module.exports = {
  stripAnsi: function (str) {
    return typeof str === 'string' ? str.replace(ansiRegex, '') : str;
  }
};

allows to use (in TypeScript)

import * as stripAnsi from 'strip-ansi';

as well as (in JavaScript)

const stripAnsi = require('strip-ansi');

I'm not sure if this might cause any troubles in other packages. If not, I would create a pull request for this change if you're okay with it.

from strip-ansi.

sindresorhus avatar sindresorhus commented on August 15, 2024

We're not going to change just because you use TypeScript. If you use TypeScript it's up to you to figure out how to use packages with it. This module is exported exactly like most npm packages.

from strip-ansi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.