Giter VIP home page Giter VIP logo

extract-domain's People

Contributors

bjarneo avatar dependabot[bot] avatar madeindjs avatar peternewman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

extract-domain's Issues

It would be nice if a naked root domain was simply returned rather than returning null

It pretty much works as you would expect except for the simplest case where you already have a domain as the input.

Obviously this is trivial to check against, but it'd be nice if this library "just worked"

How it currently works:

example.com
  =>
https://example.com
  => example.com
www.example.com
  => example.com
//example.com/protocol-relative
  => example.com
[email protected]
  => example.com
weird-protocol://example.com
  => example.com

How it would be nice if it worked:

example.com
  => example.com
https://example.com
  => example.com
www.example.com
  => example.com
//example.com/protocol-relative
  => example.com
[email protected]
  => example.com
weird-protocol://example.com
  => example.com

This is how i'm currently working around this, it's ugly but it works:


const extractDomain = require('extract-domain');
function domain_from_url(url) {
  try {
    return extractDomain(url) ? extractDomain(url) : url
  } catch (error){
    console.log(error)
    return url
  }
}

Type error.

- info Linting and checking validity of types ../node_modules/.pnpm/extract-domain@4.1.0/node_modules/extract-domain/index.ts:85:9
Type error: Type 'Promise<string | null>' is not assignable to type 'string | Promise<string>'.
  Type 'Promise<string | null>' is not assignable to type 'Promise<string>'.
    Type 'string | null' is not assignable to type 'string'.
      Type 'null' is not assignable to type 'string'.

  83 |         }
  84 | 
> 85 |         return import('psl')
     |         ^
  86 |             .then((psl) => Promise.resolve(psl.get(url.slice(offsetStart, offsetPath))))
  87 |             .catch((error) => {
  88 |                 console.error(error);

Incorrect parse

This array of URLS

["https://www.independent.co.uk/travel/news-and-advi…terdam-rome-venice-warsaw-dubrovnik-a8108096.html", "https://www.ipsf.org.il/?section=20", "https://timesofindia.indiatimes.com/blogs/voices/g…up-for-sustainable-tourism-in-a-post-covid-world/"]

returns this array of strings ["co.uk", "org.il", "indiatimes.com"]

The first two aren't working properly for some reason.

mjs module is using require()

I'm getting a require is not defined error. (Actually getting Error: You must install psl library, but the real error is just swallowed by the catch…).

This is probably because, this package defines an ESM entry point:

  "exports": {
    "require": "./dist/extract-domain.js",
   // here => 
    "default": "./dist/extract-domain.modern.mjs"
  },

But the file extract-domain.modern.mjs is using a dynamic require to get psl on demand here.

which ends up in the .mjs-file.

The thing is, require does not exist in Node ESM.

In other words: The file is stating I'm ESM, while using a CJS-only feature.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports"

I'm using this library in a React Native project, but when upgrading to react-native: 0.69.1 and trying to compile android app (npx react-native run-android) I get the following error:

error Failed to load configuration of your project.
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /my-project/node_modules/extract-domain/package.json
    at new NodeError (node:internal/errors:371:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:692:3)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at resolveNodeModuleDir (/my-project/node_modules/@react-native-community/cli-tools/build/resolveNodeModuleDir.js:24:42)
    at /my-project/node_modules/@react-native-community/cli-config/build/loadConfig.js:93:76
    at Array.reduce (<anonymous>)

I could fix it by modifying the node_modules/extract-domain/package.json and replacing the exports property with this:

"exports": {
    ".": {
      "import": "./dist/extract-domain.modern.js"
    },
    "./package.json": "./package.json"
  },

But I didn't want to create a PR with this change because I guess I'm missing some things here.

Getting extractDomain.default is not a function

I tried to import as per the library docs
import extractDomain from 'extract-domain';
And then use it like

const urls = await extractDomain("https://www.mydomain", {
 tld: true,
 });

but it throws
extractDomain.default is not a function

Also tried
import * as extractDomain from 'extract-domain';
And then use it like

const urls = await extractDomain.default("https://www.mydomain", {
 tld: true,
 });

But got the same error

The only way I was able to make it work was by doing
const extractDomain = require('extract-domain');
And then use like in the first case

I am using typescript 5.1.6

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.