src/index.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 73
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
eloc 43
nc 1
dl 0
loc 73
rs 10
c 1
b 0
f 0
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 ➔ devise 0 59 1
1
'use strict'
2
3
import './types/email'
4
import { authenticable } from './models/authenticable'
5
import { confirmable } from './models/confirmable'
6
import { lockable } from './models/lockable'
7
import { recoverable } from './models/recoverable'
8
import { registerable } from './models/registerable'
9
import { trackable } from './models/trackable'
10
11
let options = {}
12
13
export function devise (schema, opts) {
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
  }, opts)
29
30
  /*
31
  * format the string with the past values
32
  */
33
  function stringFormat (key, values) {
34
    let message = options[key]
35
    if (values) {
36
      Object.keys(values).forEach(param => {
37
        message = message.replace(`{{${param}}}`, values[param])
38
      })
39
    }
40
    return message
41
  }
42
43
  /*
44
  * implementation of translator method
45
  */
46
  function t (key, values) {
47
    return options.i18n
48
      ? options.i18n.t(key, values)
49
      : stringFormat(key, values)
50
  }
51
52
  /*
53
  * implementation of notification send
54
  */
55
  function sendNotification (record, action, done) {
56
    done()
57
  }
58
59
  schema.methods.sendNotification = schema.methods.send || sendNotification
60
61
  // i18n adapter methodos
62
  schema.methods.t = schema.methods.t || t
63
  schema.statics.t = schema.statics.t || t
64
65
  authenticable(schema, options)
66
  confirmable(schema, options)
67
  lockable(schema, options)
68
  recoverable(schema, options)
69
  registerable(schema, options)
70
  trackable(schema)
71
}
72
73
export default devise
74