Skip to content

Commit

Permalink
change returned key simply to 'tag' ...
Browse files Browse the repository at this point in the history
in extractMentionsWithIndices and extractHashtagsWithIndices
  • Loading branch information
Ville Ikonen committed Feb 13, 2012
1 parent 480815d commit e0461ab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions flowdock-text.js
Expand Up @@ -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;
Expand All @@ -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]
});
});
Expand Down Expand Up @@ -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){
Expand All @@ -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;
Expand Down
34 changes: 17 additions & 17 deletions test/extract.yml
Expand Up @@ -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"
Expand Down Expand Up @@ -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.