Skip to content

Commit

Permalink
fix!: unstable mention value parse with emojis
Browse files Browse the repository at this point in the history
Optimize algorithm for parsing value. Use String.prototype.split instead of matchAll utility.

Add emojis to some tests.

BREAKING CHANGES: now it's important to use only one group in the part patterns for correct work of `getKeyword` and ``parseValue` methods.

#66
  • Loading branch information
dabakovich committed May 12, 2022
1 parent f7ab2c9 commit 81bb8f3
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 424 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
"@types/react": "17.0.44"
},
"dependencies": {
"diff": "5.0.0",
"string.prototype.matchall": "4.0.3"
"diff": "5.0.0"
},
"jest": {
"preset": "ts-jest",
Expand Down
10 changes: 3 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export type {
Triggers,
} from './types';

export {
mentionRegEx,
isTriggerPartType,
getMentionValue,
parseValue,
replaceMentionValues,
} from './utils';
export { isTriggerPartType, getMentionValue, parseValue, replaceMentionValues } from './utils';

export { mentionRegEx } from './utils';
34 changes: 34 additions & 0 deletions src/utils/constraints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { StyleProp, TextStyle } from 'react-native';

/**
* RegEx grouped results. Example - "@[Full Name](123abc)"
* We have 4 groups here:
* - The whole original string - "@[Full Name](123abc)"
* - Mention trigger - "@"
* - Name - "Full Name"
* - Id - "123abc"
*/
const mentionRegEx = /((.)\[([^[]*)]\(([^(^)]*)\))/i;

/**
* We need this single group regex for using String.prototype.split method
*/
const singleGroupMentionRegEx = /(.\[[^[]*]\([^(^)]*\))/gi;

const DEFAULT_ALLOWED_SPACES_COUNT = 1;

// Empty object with static reference
const emptyObject: any = {};

const defaultMentionTextStyle: StyleProp<TextStyle> = {
fontWeight: 'bold',
color: 'blue',
};

export {
mentionRegEx,
singleGroupMentionRegEx,
DEFAULT_ALLOWED_SPACES_COUNT,
emptyObject,
defaultMentionTextStyle,
};
Loading

0 comments on commit 81bb8f3

Please sign in to comment.