botkit-helper-slack
Advanced tools
Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "botkit-helper-slack", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Never lookup the Slack formatting markup again", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# botkit-slack-helper | ||
# botkit-helper-slack | ||
#### Helps Slack bots get their point across | ||
@@ -9,3 +9,3 @@ | ||
```sh | ||
$ npm install --save botkit-slack-helper | ||
$ npm install --save botkit-helper-slack | ||
``` | ||
@@ -15,3 +15,3 @@ ___ | ||
```javascript | ||
var SS = require('botkit-slack-helper'); | ||
var SS = require('botkit-helper-slack'); | ||
@@ -38,18 +38,18 @@ SS('My Emphatic Decree!').italic() // -> '_My Emphatic Decree!_' (in Slack italics) | ||
##### .italic( ) (slackItalic) | ||
Italicizes your string according to Slack format | ||
`'italics'` -> `'_italics_'` | ||
Italicizes your string according to Slack format | ||
`'italics'` -> `'_italics_'` | ||
_italics_ | ||
##### .bold( ) (slackBold) | ||
Bolds your string according to Slack format | ||
`'bold'` -> `'*bold*'` | ||
Bolds your string according to Slack format | ||
`'bold'` -> `'*bold*'` | ||
**bold** | ||
##### .code( ) (slackCode) | ||
Makes your string look like `code` according to Slack format | ||
`'code'` -> '\`code\`' | ||
Makes your string look like `code` according to Slack format | ||
`'code'` -> '\`code\`' | ||
`code` | ||
##### .pre( ) (slackPre) | ||
Makes your string look like `pre-formatted fixed width text` according to Slack format | ||
Makes your string look like `pre-formatted fixed width text` according to Slack format | ||
`'pre'` -> `'```pre```'` | ||
@@ -61,4 +61,4 @@ ``` | ||
##### .strike( ) (slackStrike) | ||
Strikes through your string, according to Slack format | ||
`'strike'` -> `'~strike~'` | ||
Strikes through your string, according to Slack format | ||
`'strike'` -> `'~strike~'` | ||
~~strike~~ | ||
@@ -72,3 +72,3 @@ | ||
##### .paragraph( ) (slackParagraph) | ||
Creates a multi-line quote. | ||
Creates a multi-line quote. | ||
`'paragraph'` -> `'>>> paragraph'` | ||
@@ -85,7 +85,7 @@ > Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris | ||
##### .user( ) (slackUser) | ||
Formats your user ID into Slack's desired format | ||
Formats your user ID into Slack's desired format | ||
`'U112233'` -> `'<@U112233>'` | ||
##### .channel( ) (slackChannel) | ||
Formats your channel ID into Slack's desired format | ||
Formats your channel ID into Slack's desired format | ||
`'C445566'` -> `'<@C445566>'` | ||
@@ -100,2 +100,16 @@ | ||
##### .date(options) (slackDate) | ||
Formats your date using _optional_ `options`. Date can be a seconds since the epoch, a string, or an instance of `Date` | ||
```javascript | ||
SS(1526249506).date() // -> '<!date^1526249506^{date}|Sun, 13 May 2018 22:11:46 GMT>' | ||
SS(new Date()).date() | ||
SS('2018-05-13').date() | ||
var options = {format: '{date} at {time}', link: 'http://example.com', fallback: 'Some great date'}; | ||
SS('1526249506').date(options) // -> '<!date^1526249506^{date} at {time}^http://example.com|Some great date>'); | ||
// having called extendPrototype() | ||
'2018-05-13'.slackDate(options) | ||
``` | ||
##### .url(handle) (slackSubteam) | ||
@@ -102,0 +116,0 @@ Creates a formatted link displayed as _optional_ `handle` |
@@ -50,2 +50,23 @@ // .------..------..------..------..------. .------..------..------..------..------. | ||
date : function(options) { | ||
options = options || {}; | ||
var time = this.s, format = options.format || "{date}"; | ||
if(!Number.isNaN(+time)) { | ||
time = new Date(time * 1000); | ||
} | ||
else if(typeof time === "string") { | ||
time = Date.parse(time); | ||
if(!time) throw new Error("Parameter '" + this.s + "' cannot be turned into a Date."); | ||
time = new Date(time); | ||
} | ||
var seconds = Math.floor(time.getTime() / 1000); | ||
var code = "<!date^" + seconds + "^" + format; | ||
if(options.link) code += "^" + options.link; | ||
return code + "|" + (options.fallback || time.toUTCString()) + ">"; | ||
}, | ||
// types of selectors | ||
@@ -52,0 +73,0 @@ //e.g. <@U123456> |
@@ -0,0 +0,0 @@ require('../index').extendPrototype(); |
@@ -16,2 +16,8 @@ var assert = require('assert'); | ||
assert.equal(ss('S123456').subteam('sub-team'), '<!subteam^S123456|sub-team>'); | ||
assert.equal(ss('S123456').subteam('sub-team'), '<!subteam^S123456|sub-team>'); | ||
assert.equal(ss('1526249506').date(), '<!date^1526249506^{date}|Sun, 13 May 2018 22:11:46 GMT>'); | ||
assert.equal(ss('2018-05-13').date(), '<!date^1526169600^{date}|Sun, 13 May 2018 00:00:00 GMT>'); | ||
assert.equal(ss(1526249506).date(), '<!date^1526249506^{date}|Sun, 13 May 2018 22:11:46 GMT>'); | ||
assert.equal(ss(new Date(1526249506)).date(), '<!date^1526249506^{date}|Sun, 13 May 2018 22:11:46 GMT>'); | ||
assert.equal(ss(1526249506).date({format:'{time}', link:'link', fallback: 'fallback'}), '<!date^1526249506^{time}^link|fallback>'); | ||
assert.equal(ss('https://google.com').url('google.com'), '<https://google.com|google.com>'); | ||
@@ -40,2 +46,4 @@ assert.equal(ss('test@gmail.com').email('Test'), '<mailto:test@gmail.com|Test>'); | ||
assert.equal('S123456'.slackSubteam('sub-team'), '<!subteam^S123456|sub-team>'); | ||
assert.equal('1526249506'.slackDate(), '<!date^1526249506^{date}|Sun, 13 May 2018 22:11:46 GMT>'); | ||
assert.equal('1526249506'.slackDate({format: '{time}', link: 'link', fallback: 'fallback'}), '<!date^1526249506^{time}^link|fallback>'); | ||
assert.equal('https://google.com'.slackUrl('google.com'), '<https://google.com|google.com>'); | ||
@@ -42,0 +50,0 @@ assert.equal('test@gmail.com'.slackEmail('Test'), '<mailto:test@gmail.com|Test>'); |
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
14713
7
202
159
1