UNPKG

551 BJavaScriptView Raw
1'use strict'
2
3module.exports = quotation
4
5var C_DEFAULT = '"'
6
7function quotation(value, open, close) {
8 var result
9 var index
10 var length
11
12 open = open || C_DEFAULT
13 close = close || open
14
15 if (typeof value === 'string') {
16 return open + value + close
17 }
18
19 if (typeof value !== 'object' || !('length' in value)) {
20 throw new Error('Expected string or array of strings')
21 }
22
23 result = []
24 length = value.length
25 index = -1
26
27 while (++index < length) {
28 result[index] = quotation(value[index], open, close)
29 }
30
31 return result
32}