src/index.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 61
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 61
rs 10
wmc 7
mnd 1
bc 6
fnc 5
bpm 1.2
cpm 1.4
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A index.js ➔ ??? 0 49 1
1
'use strict'
2
3
import './types/email'
4
import Authenticable from './models/authenticable'
5
import Registerable from './models/registerable'
6
import Confirmable from './models/confirmable'
7
import Lockable from './models/lockable'
8
import Recoverable from './models/recoverable'
9
import Trackable from './models/trackable'
10
11
let options = {}
12
13
export default function (schema, opt) {
14
  options = Object.assign({
15
    confirmable: {
16
      tokenLifeSpan: 3
17
    },
18
    lockable: {
19
      tokenLifeSpan: 3,
20
      maximumAllowedFailedAttempts: 3
21
    },
22
    recoverable: {
23
      tokenLifeSpan: 3
24
    },
25
    registerable: {
26
      autoConfirm: false
27
    }
28
  }, opt)
29
30
  // implementation of notification send
31
  schema.methods.send = schema.methods.send || function (record, action, done) {
32
    done()
33
  }
34
35
  // format the string with the past values
36
  function stringFormat (key, values) {
37
    let message = options[key]
38
    if (values) {
39
      Object.keys(values).forEach(param => {
40
        message = message.replace(`{{${param}}}`, values[param])
41
      })
42
    }
43
    return message
44
  }
45
46
  // implementation of translator method
47
  function t (key, values) {
48
    return options.i18n
49
      ? options.i18n.t(key, values)
50
      : stringFormat(key, values)
51
  }
52
  schema.methods.t = schema.methods.t || t
53
  schema.statics.t = schema.statics.t || t
54
55
  Authenticable(schema, options)
56
  Registerable(schema, options)
57
  Confirmable(schema, options)
58
  Lockable(schema, options)
59
  Recoverable(schema, options)
60
  Trackable(schema)
61
}
62