Skip to content

Commit 05f174d

Browse files
author
fletcherist
committed
feat: Implement matcher type
1 parent 8cac580 commit 05f174d

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
<a name="1.3.3"></a>
2+
## [1.3.3](https://github.com/fletcherist/yandex-dialogs-sdk/compare/v1.3.2...v1.3.3) (2018-07-08)
3+
4+
5+
### Bug Fixes
6+
7+
* bug with commands (array) ([8cac580](https://github.com/fletcherist/yandex-dialogs-sdk/commit/8cac580))
8+
* package.json ([169a818](https://github.com/fletcherist/yandex-dialogs-sdk/commit/169a818))
9+
10+
11+
### Features
12+
13+
* add guess number game to examples ([3d34c26](https://github.com/fletcherist/yandex-dialogs-sdk/commit/3d34c26))
14+
* add youtube link to readme ([31c8328](https://github.com/fletcherist/yandex-dialogs-sdk/commit/31c8328))
15+
16+
17+
118
<a name="1.3.2"></a>
219
## [1.3.2](https://github.com/fletcherist/yandex-dialogs-sdk/compare/v1.2.1...v1.3.2) (2018-07-08)
320

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "yandex-dialogs-sdk",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "Build your skill for Alice with ease.",
55
"main": "dist/index.js",
66
"scripts": {
77
"lint": "eslint src",
88
"test": "jest",
99
"dev": "tsc -w",
1010
"build": "tsc",
11-
"version": "npm run changelog && git add CHANGELOG.md && conventional-github-releaser -p angular",
11+
"version": "npm run changelog && git add CHANGELOG.md",
1212
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
13+
"release": "conventional-github-releaser -p angular",
1314
"deploy": "tsc && git push --follow-tags origin master && npm publish"
1415
},
1516
"repository": {

src/command.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@ import {
33
TYPE_FIGURE,
44
TYPE_REGEXP,
55
TYPE_ARRAY,
6+
TYPE_MATCHER,
67
} from './constants'
78
import Ctx from './ctx'
8-
import { CommandInterface, CallbackType, CommandType } from './types/command'
9+
import {
10+
CommandInterface,
11+
CallbackType,
12+
CommandType,
13+
CommandNameType,
14+
} from './types/command'
915
import { CtxInterface } from './types/ctx'
1016

1117
export default class Command implements CommandInterface {
12-
public name: any[] | string | RegExp
13-
public type: | CommandType
18+
public name: CommandNameType
19+
public type: CommandType
1420
public callback: CallbackType
1521

16-
constructor(name: string, callback: CallbackType) {
22+
constructor(name: CommandNameType, callback: CallbackType) {
1723
if (name === undefined) { throw new Error('Command name is not specified') }
1824
this.name = name
1925
this.callback = callback
@@ -25,15 +31,18 @@ export default class Command implements CommandInterface {
2531
public _defineCommandType(name) {
2632
let type
2733

28-
if (typeof name === 'string') {
29-
type = TYPE_STRING
30-
if (name.includes('${')) {
31-
type = TYPE_FIGURE
34+
if (typeof name === 'function') {
35+
type = TYPE_MATCHER
3236
}
37+
if (typeof name === 'string') {
38+
type = TYPE_STRING
39+
if (name.includes('${')) {
40+
type = TYPE_FIGURE
41+
}
3342
} else if (name instanceof RegExp) {
34-
type = TYPE_REGEXP
43+
type = TYPE_REGEXP
3544
} else if (Array.isArray(name)) {
36-
type = TYPE_ARRAY
45+
type = TYPE_ARRAY
3746
} else {
3847
throw new Error(`Command name is not of proper type.
3948
Could be only string, array of strings or regular expression`)

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const TYPE_STRING = 'string'
22
export const TYPE_FIGURE = 'figure'
33
export const TYPE_REGEXP = 'regexp'
44
export const TYPE_ARRAY = 'array'
5+
export const TYPE_MATCHER = 'matcher'
56

67
export const ALICE_PROTOCOL_VERSION = '1.0'
78
export const DEFAULT_END_SESSION = false

src/types/command.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import Ctx from '../ctx'
22
import { CtxInterface } from './ctx'
33

44
export type CallbackType = (ctx: CtxInterface) => CtxInterface
5-
6-
export type CommandType = 'string' | 'figure' | 'regexp' | 'array'
5+
export type MatcherType = (ctx: CtxInterface) => boolean
6+
export type CommandNameType = any[] | string | RegExp | MatcherType
7+
export type CommandType = 'string' | 'figure' | 'regexp' | 'array' | 'matcher'
78
export interface CommandInterface {
89
callback: CallbackType
9-
name: any[] | string | RegExp
10+
name: CommandNameType
1011
type: CommandType
1112
}

0 commit comments

Comments
 (0)