Git Product home page Git Product logo

country-code-emoji's People

Contributors

dependabot[bot] avatar thekelvinliu 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

country-code-emoji's Issues

Types unavailable

With recent versions of TypeScript (currently v4.7.4) and with project TypeScript config compilerOptions.module set to nodenext, the types for this package are not available when importing from within an ESM module:

// @ts-check

import { countryCodeEmoji } from "country-code-emoji";

The hover intellisense doesn't include the right types (cc arg should be type string):

Screen Shot 2022-06-28 at 5 57 57 pm

If you CMD + click the import, it opens the country-code-emoji/lib/index.mjs module instead of the country-code-emoji/lib/index.d.ts file you would expect if the types were working.

I think the reason is because the package exports field incorrectly doesn't start with a types property:

"exports": {
"import": "./lib/index.mjs",
"require": "./lib/index.js"
},

    "exports": {
+     "types": "./lib/index.d.ts",
      "import": "./lib/index.mjs",
      "require": "./lib/index.js"
    },

See:

https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing

Invalid .js file extension for ESM exports

"import": "./src/index.js",

This is incorrect, and result in a Node.js runtime error:

import countryCodeEmoji from 'country-code-emoji';
(node:26808) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/[redacted]/node_modules/country-code-emoji/src/index.js:15
export function countryCodeEmoji(cc) {
^^^^^^
SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:195:29)
    at ModuleJob.run (internal/modules/esm/module_job.js:145:37)
    at async Loader.import (internal/modules/esm/loader.js:182:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)

Flags not seen on Windows

Hi my colleagues can't see any flags on Windows, machine. Is any fix possible (may font is not correct or smth else)?
image

Avoid the dual package hazard

Currently country-code-emoji ships separate CJS and ESM builds, which load conditionally depending if it's being imported or required. This is susceptible to the dual package hazard:

https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#packages_dual_package_hazard

E.g. if one part of a codebase uses require to access countryCodeEmoji, and another import, then the same function will load twice in memory at runtime, and if bundling, will get bundled twice doubling the bundle size impact.

The best way to tackle this is to either:

  • Support pure ESM only, dropping support for require. To do this, only publish the API in one set of ESM files. While this forces your users to write ESM, the code can be fully browser compatible as there is no CJS used anywhere by the public API's code (assuming no dependencies are used that are CJS, which is the case here for country-code-emoji).
  • Support both import and require by publishing the API in one set of CJS files, with one default export (module.exports =) in each file. The package should provide one deep-importable file for each function in the API (see #11), but for analysis tools like https://bundlephobia.com an index is still useful as the main entry point. To support both require and import (with named imports) from the index, conditional package exports can be used to direct to relevant index.js (CJS) and index.mjs (ESM) files.

Here is an example package to reference how that works:

https://github.com/jaydenseric/extract-files/blob/6d8f725e9b9973fd564bfdd784cd9b2ff58f8470/package.json#L32-L40

https://github.com/jaydenseric/extract-files/blob/6d8f725e9b9973fd564bfdd784cd9b2ff58f8470/public/index.mjs#L1-L3

https://github.com/jaydenseric/extract-files/blob/6d8f725e9b9973fd564bfdd784cd9b2ff58f8470/public/index.js#L3-L5

Tell whether proper flag where found

Is there a way to tell if a proper flag was found?
In the README you write:
to keep things simple, if cc a two letter string, but not an actual ISO 3166-1 alpha-2 code, the regional indicator symbols corresponding to the letters in cc are returned.
Is there a way to see if this happened?

If so, I don't want to display the letters with the border, but just a string:
image

Provide a deep import for each function

Right now, the API is only available from index files:

https://unpkg.com/browse/[email protected]/lib/index.mjs

Ideally, countryCodeEmoji and emojiCountryCode would be available separately, e.g:

import countryCodeEmoji from 'country-code-emoji/countryCodeEmoji.mjs';
import emojiCountryCode from 'country-code-emoji/emojiCountryCode.mjs';

This way only the necessary code can be imported and loaded into memory in a given context, and it also ensures perfect bundling without depending on slow and unreliable "tree-shaking".

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.