How to use Composer to install third party libraries
It is not recommended to installing JavaScript libraries using composer.json, but it is possible.

Note: This repository type has a few limitations and should be avoided whenever possible:
Composer will not update the package unless you change the versionfield.Composer will not update the commit references, so if you use master as reference you will have to delete the package to force an update, and will have to deal with an unstable lock file.

(Composer docs)
If your package is available for download at an external source, e.g. as an archive, you could add it as custom package with type drupal-library to the repositories section of your Drupal project's composer.json, and then require this package accordingly:
&quot;repositories&quot;: {
  &quot;drupal&quot;: {
    &quot;type&quot;: &quot;composer&quot;,
    &quot;url&quot;: &quot;https://packages.drupal.org/8&quot;
  },
  &quot;mypackage&quot;: {
    &quot;type&quot;: &quot;package&quot;,
    &quot;package&quot;: {
      &quot;name&quot;: &quot;myvendor/mypackage&quot;,
      &quot;version&quot;: &quot;1.0.0&quot;,
      &quot;type&quot;: &quot;drupal-library&quot;,
      &quot;dist&quot;: {
        &quot;url&quot;: &quot;https://example.com/mypackage.zip&quot;,
        &quot;type&quot;: &quot;zip&quot;
      }
    }
  }
},
&quot;require&quot;: {
  ...
  &quot;composer/installers&quot;: &quot;^1.2&quot;,
  &quot;myvendor/mypackage&quot;: &quot;1.0.0&quot;
},
&quot;extra&quot;: {
  &quot;installer-paths&quot;: {
    &quot;public/core&quot;: [&quot;type:drupal-core&quot;],
    &quot;public/libraries/{$name}&quot;: [&quot;type:drupal-library&quot;],
    &quot;public/modules/contrib/{$name}&quot;: [&quot;type:drupal-module&quot;],
    &quot;public/profiles/contrib/{$name}&quot;: [&quot;type:drupal-profile&quot;],
    &quot;public/themes/contrib/{$name}&quot;: [&quot;type:drupal-theme&quot;],
    &quot;drush/contrib/{$name}&quot;: [&quot;type:drupal-drush&quot;]
  },
  ...
}

Check the Repositories documentation for Composer for more details or other source types.