How to use grapheme-splitter - 10 common examples

To help you get started, we’ve selected a few grapheme-splitter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cofacts / rumors-line-bot / src / ga.js View on Github external
import ua from 'universal-analytics';
import GraphemeSplitter from 'grapheme-splitter';
const splitter = new GraphemeSplitter();

// When document title is too long, event will be dropped.
// See: https://github.com/cofacts/rumors-line-bot/issues/97
//
const DOCUMENT_TITLE_LENGTH = 800;

/**
 * Sends a screen view and returns the visitor
 *
 * @param {string} userId
 * @param {string} state - The current state the LINE bot is in
 * @param {string} documentTitle - The article content (user input) currently in search
 * @returns {ua.Visitor} universal analytics visitor
 */
export default function ga(userId, state = 'N/A', documentTitle = '') {
  const visitor = ua(process.env.GA_ID, userId, { strictCidFormat: false });
github danfuzz / bayou / local-modules / @bayou / doc-common / BodyOp.js View on Github external
// Copyright 2016-2019 the Bayou Authors (Dan Bornstein et alia).
// Licensed AS IS and WITHOUT WARRANTY under the Apache License,
// Version 2.0. Details: 

import GraphemeSplitter from 'grapheme-splitter';

import { BaseOp } from '@bayou/ot-common';
import { TInt, TObject, TString } from '@bayou/typecheck';
import { DataUtil, Errors, ObjectUtil } from '@bayou/util-common';

// Instance of the grapheme splitter library
// used to properly count the length of
// special characters, such as emojis.
const splitter = new GraphemeSplitter();

/**
 * Operation on a text document body.
 *
 * This class is designed to bridge the two worlds of the Bayou OT framework and
 * Quill's ad-hoc-object-based deltas. As such, it defines a static method
 * `fromQuillForm()` and an instance method `toQuillForm()` to convert back and
 * forth as needed.
 */
export class BodyOp extends BaseOp {
  /** {string} Opcode constant for "delete" operations. */
  static get CODE_delete() {
    return 'delete';
  }

  /**
github RocketChat / Rocket.Chat / app / ui-utils / lib / MessageProperties.js View on Github external
import GraphemeSplitter from 'grapheme-splitter';

import { emoji } from '../../emoji';

const splitter = new GraphemeSplitter();

export const messageProperties = {

	length: (message) => splitter.countGraphemes(message),

	messageWithoutEmojiShortnames: (message) => message.replace(/:\w+:/gm, (match) => {
		if (emoji.list[match] !== undefined) {
			return ' ';
		}
		return match;
	}),
};
github christiandavid / gatsby-theme-byfolio / @christiandavid / gatsby-theme-byfolio / src / pages / index.js View on Github external
function stringSplitter(string) {
    const splitter = new GraphemeSplitter()
    return splitter.splitGraphemes(string)
  }
github rainbow-me / rainbow / src / components / header / HeaderProfileInfo.js View on Github external
const HeaderProfileInfo = ({
  accountAddress,
  accountColor,
  accountName,
  onPress,
}) => {
  const name = accountName || 'My Wallet';
  const color = accountColor || 0;

  return (
    
      
        
          
            {new GraphemeSplitter().splitGraphemes(name)[0]}
          
        
        
          
            
              {removeFirstEmojiFromString(name)}
            
            
              
            
          
          
        
      
    
  );
github RocketChat / Rocket.Chat / imports / services / services / message / send.js View on Github external
import moment from 'moment';
import GraphemeSplitter from 'grapheme-splitter';

import { RocketChat } from 'meteor/rocketchat:lib';
import { Meteor } from 'meteor/meteor';

const splitter = new GraphemeSplitter();

export const messageProperties = {

	length: ((message) => splitter.countGraphemes(message)),

	messageWithoutEmojiShortnames: ((message) => message.replace(/:\w+:/gm, (match) => {
		if (RocketChat.emoji.list[match] !== undefined) {
			return ' ';
		}
		return match;
	})),
};


export default {
	send: {
github vtrushin / json-to-ast / lib / utils / substring.js View on Github external
import GraphemeSplitter from 'grapheme-splitter';

const splitter = new GraphemeSplitter();

const substring = (str, start, end) => {
	const iterator = splitter.iterateGraphemes(str.substring(start));

	let value = '';

	for (let pos = 0; pos < end - start; pos ++) {
		const next = iterator.next();

		value += next.value;

		if (next.done) {
			break;
		}
	}
github rainbow-me / rainbow / src / helpers / emojiHandler.js View on Github external
export const removeFirstEmojiFromString = string => {
  const grapheme = new GraphemeSplitter().splitGraphemes(string);
  const first = grapheme[0];

  if (first.search(regex) > -1) {
    grapheme.splice(0, 2);
  }
  return grapheme;
};
github rainbow-me / rainbow / src / components / expanded-state / ProfileCreator.js View on Github external
const acceptAction = this.props.isNewProfile ? this.addProfileInfo : this.editProfile;
    return (
      
        
          
            
              
                
                  
                    
                      
                        
                          {new GraphemeSplitter().splitGraphemes(this.state.value)[0]}
                        
                      
                    
                    
                      {this.state.value.length > 0 ? ' ' : placeholderText}
github rainbow-me / rainbow / src / components / change-wallet / ProfileRow.js View on Github external
{new GraphemeSplitter().splitGraphemes(accountName)[0]}
            
          
          
        
      
    );
  }
}

grapheme-splitter

A JavaScript library that breaks strings into their individual user-perceived characters. It supports emojis!

MIT
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis

Popular grapheme-splitter functions