#.js externe

1 messages · Page 1 of 1 (latest)

oblique galleon
#

I would like to import an external .js.

https://www.npmjs.com/package/image-size-from-base64

I tried this:

import * as img64 from '../../../../../node_modules/image-size-from-base64/index.js';

how can I do it?

ionic tusk
#

You would add a file with a .d.ts extension in your sources containing

declare module 'image-size-from-base64' {
  export default function getSize(s: string): Promise<number>
}

and you would then import it like any other library:

import getSize from 'image-size-from-base64';

But really, this library

  • contains 6 lines of code
  • imposes the unit and the number of decimals to you
  • can be trivially implemented
  • exposes a function which is async although it computes the result synchronously and could just return a number

So I would just implement that by myself and get rid of the library.