Browse files

change returned key simply to 'tag' ...

in extractMentionsWithIndices and extractHashtagsWithIndices
  • Loading branch information...
1 parent 480815d commit e0461abc568fd8e6660a13dd86653fb02e410105 Ville Ikonen committed Feb 13, 2012
Showing with 24 additions and 24 deletions.
  1. +2 −2 README.md
  2. +5 −5 flowdock-text.js
  3. +17 −17 test/extract.yml
View
4 README.md
@@ -11,7 +11,7 @@ Hashtag extraction
FlowdockText.extractHashtags("hello #world");
[ 'world' ]
FlowdockText.extractHashtagsWithIndices("hello #world");
-[ { hashtag: 'world', indices: [ 6, 12 ] } ]
+[ { tag: 'world', indices: [ 6, 12 ] } ]
```
Usertag extraction
@@ -20,7 +20,7 @@ Usertag extraction
FlowdockText.extractMentions("hello @Username");
[ '@Username' ]
FlowdockText.extractMentionsWithIndices("hello @Username");
-[ { usertag: '@Username', indices: [ 6, 15 ] } ]
+[ { tag: '@Username', indices: [ 6, 15 ] } ]
```
Url extraction
View
10 flowdock-text.js
@@ -552,7 +552,7 @@ if (typeof FlowdockText === "undefined" || FlowdockText === null) {
hashtagsWithIndices = FlowdockText.extractHashtagsWithIndices(text);
for (var i = 0; i < hashtagsWithIndices.length; i++) {
- hashtagsOnly.push(hashtagsWithIndices[i].hashtag);
+ hashtagsOnly.push(hashtagsWithIndices[i].tag);
}
return hashtagsOnly;
@@ -573,7 +573,7 @@ if (typeof FlowdockText === "undefined" || FlowdockText === null) {
var startPosition = text.indexOf(hash + hashText, position);
position = startPosition + hashText.length + 1;
tags.push({
- hashtag: hashText,
+ tag: hashText,
indices: [startPosition, position]
});
});
@@ -610,7 +610,7 @@ if (typeof FlowdockText === "undefined" || FlowdockText === null) {
mentionsWithIndices = FlowdockText.extractMentionsWithIndices(text, userTags);
for (var i = 0; i < mentionsWithIndices.length; i++) {
- mentionsOnly.push(mentionsWithIndices[i].usertag);
+ mentionsOnly.push(mentionsWithIndices[i].tag);
}
if(userTags){
@@ -634,14 +634,14 @@ if (typeof FlowdockText === "undefined" || FlowdockText === null) {
var startPosition = text.indexOf(hash + hashText, position);
position = startPosition + hashText.length + 1;
tags.push({
- usertag: (hash + hashText),
+ tag: (hash + hashText),
indices: [startPosition, position]
});
});
if(userTags){
userTags = downCase(userTags.map(getUserTag));
- return tags.filter(function(tag){ return inArray(tag.usertag.toLowerCase(), userTags) });
+ return tags.filter(function(tag){ return inArray(tag.tag.toLowerCase(), userTags) });
}
return tags;
View
34 test/extract.yml
@@ -49,20 +49,20 @@ tests:
- description: "Extract a mention at the start"
text: "@username yo!"
expected:
- - usertag: "@username"
+ - tag: "@username"
indices: [0, 9]
- description: "Extract a mention that has the same thing mentioned at the start"
text: "username @username"
expected:
- - usertag: "@username"
+ - tag: "@username"
indices: [9, 18]
mentions_with_indices_with_predefined_usertags:
- description: "Include only predefined users"
text: "@username @foobar yo!"
expected:
- - usertag: "@username"
+ - tag: "@username"
indices: [0, 9]
urls:
- description: "Extract a lone URL"
@@ -586,64 +586,64 @@ tests:
- description: "Extract a hastag at the start"
text: "#hashtag here"
expected:
- - hashtag: "hashtag"
+ - tag: "hashtag"
indices: [0, 8]
- description: "Extract a hastag at the end"
text: "test a #hashtag"
expected:
- - hashtag: "hashtag"
+ - tag: "hashtag"
indices: [7, 15]
- description: "Extract a hastag in the middle"
text: "test a #hashtag in a string"
expected:
- - hashtag: "hashtag"
+ - tag: "hashtag"
indices: [7, 15]
- description: "Extract a hastag with a dash"
text: "test a #hash-tag in a string"
expected:
- - hashtag: "hash-tag"
+ - tag: "hash-tag"
indices: [7, 16]
- description: "Extract only a valid hashtag"
text: "#123 a #hashtag in a string"
expected:
- - hashtag: "123"
+ - tag: "123"
indices: [0, 4]
- - hashtag: "hashtag"
+ - tag: "hashtag"
indices: [7, 15]
- description: "Extract a hashtag in a string of multi-byte characters"
text: "会議中 #hashtag 会議中"
expected:
- - hashtag: "hashtag"
+ - tag: "hashtag"
indices: [4, 12]
- description: "Extract multiple valid hashtags"
text: "One #two three #four"
expected:
- - hashtag: "two"
+ - tag: "two"
indices: [4, 8]
- - hashtag: "four"
+ - tag: "four"
indices: [15, 20]
- description: "Extract a non-latin hashtag"
text: "Hashtags in #русский!"
expected:
- - hashtag: "русский"
+ - tag: "русский"
indices: [12, 20]
- description: "Extract multiple non-latin hashtags"
text: "Hashtags in #中文, #日本語, #한국말, and #русский! Try it out!"
expected:
- - hashtag: "中文"
+ - tag: "中文"
indices: [12, 15]
- - hashtag: "日本語"
+ - tag: "日本語"
indices: [17, 21]
- - hashtag: "한국말"
+ - tag: "한국말"
indices: [23, 27]
- - hashtag: "русский"
+ - tag: "русский"
indices: [33, 41]

0 comments on commit e0461ab

Please sign in to comment.