Git Product home page Git Product logo

smile2emoji's Introduction

Smile2Emoji NPM Module

npm version FOSSA Status License: MIT Maintainability

smile2emoji

Convert all the smiley to fantastic emoticons! โœจ

With this simple and little module you can convert the smiles in your text to emoji. :) or :D or <3 will become emoticons! Ideal for input, chats and so on, where you don't want an emoji picker but a simpler solution.

Very quick test usage: https://codepen.io/emish89/pen/YzGrvVK

Happy usage =)

Installation

npm i smile2emoji

Usage

Objects exported by the package:

FUNCTIONS EXPORTED

checkText(text: string): string Function to check if in the string parameter there is some emoji and in case convert it. Example:

import { checkText } from 'smile2emoji'

...

const text = checkText(':)');
console.log(text) //prints '๐Ÿ˜Š'

//OR

const text = checkText('i like bananas :)');
console.log(text) //prints 'i like bananas ๐Ÿ˜Š'

checkTextWithAutoSuggestions(text: string): string Same as before but with autosuggestion, so if there is only one emoji key in the map starting with the string, it use it.

import { checkTextWithAutoSuggestions } from 'smile2emoji'

...

const text = checkTextWithAutoSuggestions(':tenn');
console.log(text) //prints '๐ŸŽพ'

//OR

const text = checkTextWithAutoSuggestions('i like bananas :tenn');
console.log(text) //prints 'i like bananas ๐ŸŽพ'

checkTextWithAutoSuggestionsAndUnicode(text: string): string Same function but it use the map with unicode char instead of emoji, same results:

import { checkTextWithAutoSuggestionsAndUnicode } from 'smile2emoji'

...

const text = checkTextWithAutoSuggestionsAndUnicode(':tenn');
console.log(text) //prints '๐ŸŽพ'

//OR

const text = checkTextWithAutoSuggestionsAndUnicode('i like bananas :tenn');
console.log(text) //prints 'i like bananas ๐ŸŽพ'

fromUnicodeToEmoji(text: string): string Used by the function above, it convert an unicode string to emoji. Example usage:

import { fromUnicodeToEmoji } from 'smile2emoji'

const text = fromUnicodeToEmoji('2615');
console.log(text) //prints 'โ˜•'

MAPS EXPORTED:

emojiMap: { [key: string]: string } In this map is exported a pair of key-value string -emoji , like ':)' -> ๐Ÿ˜Š

mapStringToUnicode: { [key: string]: string } In this map is exported a pair of key-value string -unicode of the emoji , like ': coffee:' -> '2615'

Example usage:

import { emojiMap } from 'smile2emoji'

...

const text = ':)';
const emoji = emojiMap[text];
console.log(emoji) //prints '๐Ÿ˜Š'

License

MIT ยฉ Federico Ballarini

FOSSA Status

smile2emoji's People

Contributors

dependabot[bot] avatar emish89 avatar fossabot avatar renovate-bot avatar renovate[bot] avatar sebamarynissen avatar semantic-release-bot 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

Watchers

 avatar  avatar

smile2emoji's Issues

string "constructor" will produce strange output

If you pass the string "constructor" to checkText() , you will get the following string back: "function Object() { [native code] }"

To Reproduce
Steps to reproduce the behavior:
add this basic snippet:

console.log(checkText("constructor"));

Expected behavior
the function should return "constructor"

Desktop (please complete the following information):

  • OS: Windows
  • any
  • Version latest modern browsers

Demo Website

Is your feature request related to a problem? Please describe.
I wanted to test this out before downloading it, would it be possible for you to create a small demo website? I could create it if needed.

Describe the solution you'd like
A demo website (even one hosted on gh-pages) would be nice :)

I could create and PR, if this is acceptable :)

New lines, first characters are not replaced

Describe the bug
I use the module for a textarea.
Pressing enter and try to enter something for replacement won't work. It needs at least one space before.

To Reproduce
Steps to reproduce the behavior:

  1. Create a textarea with checkText used in the EventListener
  2. Press Enter to get a new line in the text area
  3. Enter :-) or any other string to be replaced as the first characters of the line

Expected behavior
The entered string at the beginning of the line are replaced with the emoji.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):

  • OS: Windows, Android
  • Browser Chrome, Edge,...

index.js needs to be renamed to index.cjs to work...

Using Next.js 14. Getting this error in console:

stderr:  โจฏ ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/admin/Development/ff/ff-web/node_modules/smile2emoji/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
    at file:///Users/admin/Development/ff/ff-web/node_modules/smile2emoji/lib/index.js:1:36
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:430:15) {
  page: '/app'
}

and on web page:

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/admin/Development/ff/ff-web/node_modules/smile2emoji/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

Renaming index.js to index.cjs did fix it, along with changing the path in package.json:

"main": "./lib/index.cjs",
"module": "./lib/index.cjs",

Please fix it so we don't need to update a node module :)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v4@692973e3d937129bcbf40652eb9f2f61becf3332
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
.github/workflows/codesee-arch-diagram.yml
  • Codesee-io/codesee-action v2
.github/workflows/publish.yml
  • actions/checkout v4
.github/workflows/release.yml
  • actions/checkout v4@692973e3d937129bcbf40652eb9f2f61becf3332
  • actions/setup-node v4
npm
package.json
  • @babel/cli 7.24.8
  • @babel/eslint-parser 7.24.8
  • @babel/preset-env 7.24.8
  • @babel/preset-typescript 7.24.7
  • @babel/register 7.24.6
  • @eslint/js ^9.6.0
  • @semantic-release/changelog 6.0.3
  • @semantic-release/commit-analyzer 13.0.0
  • @semantic-release/git 10.0.1
  • @semantic-release/github 10.1.0
  • @semantic-release/npm 12.0.1
  • @types/mocha ^10.0.7
  • @typescript-eslint/eslint-plugin 7.16.1
  • @typescript-eslint/parser 7.16.1
  • babel-plugin-add-module-exports 1.0.4
  • babel-preset-minify 0.5.2
  • chai 5.1.1
  • conventional-changelog-conventionalcommits 8.0.0
  • cross-env 7.0.3
  • eslint 9.7.0
  • eslint-config-airbnb 19.0.4
  • eslint-plugin-import 2.29.1
  • eslint-plugin-jsx-a11y 6.9.0
  • globals ^15.8.0
  • mocha 10.6.0
  • nyc 17.0.0
  • prettier 3.3.3
  • rimraf 6.0.1
  • ts-node ^10.9.2
  • typescript 5.5.3
  • typescript-eslint ^7.16.0

  • Check this box to trigger a request for Renovate to run again on this repository

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.