This repository has been archived by the owner on Nov 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
135 lines (124 loc) · 2.96 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'use strict'
// TODO: replace with Array.find once 0.10 support can be dropped
// https://github.com/nodejs/LTS#lts-schedule
var find = function(collection, predicate) {
var i
var element
for (i = 0; i < collection.length; i++) {
element = collection[i]
if (predicate(element)) {
return element
}
}
}
var layerTypes = [
{
id: 'tcu',
name: {
en: 'top copper'
},
match: /((F.Cu)|(top\.gbr$))|(\.((cmp$)|(top$)|(gtl$)))|(\.toplayer\.ger$)|(top copper\.txt$)/i
},
{
id: 'tsm',
name: {
en: 'top soldermask'
},
match: /((F.Mask)|(topmask))|(\.((stc$)|(tsm$)|(gts$)|(smt$)))|(\.topsoldermask\.ger$)|(top solder resist\.txt$)/i
},
{
id: 'tss',
name: {
en: 'top silkscreen'
},
match: /((F.SilkS)|(topsilk))|(\.((plc$)|(tsk$)|(gto$)|(sst$)))|(\.topsilkscreen\.ger$)|(top silk screen\.txt$)/i
},
{
id: 'tsp',
name: {
en: 'top solderpaste'
},
match: /((F.Paste)|(toppaste))|(\.((crc$)|(tsp$)|(gtp$)|(spt$)))|(\.tcream\.ger$)/i
},
{
id: 'bcu',
name: {
en: 'bottom copper'
},
match: /(B.Cu|bottom\.gbr$)|(\.((sol$)|(bot$)|(gbl$)))|(\.bottomlayer\.ger$)|(bottom copper\.txt$)/i
},
{
id: 'bsm',
name: {
en: 'bottom soldermask'
},
match: /(B.Mask|bottommask\.)|(\.((sts$)|(bsm$)|(gbs$)|(smb$)))|(\.bottomsoldermask\.ger$)|(bottom solder resist\.txt$)/i
},
{
id: 'bss',
name: {
en: 'bottom silkscreen'
},
match: /((B.SilkS)|(bottomsilk\.))|(\.((pls$)|(bsk$)|(gbo$)|(ssb$)))|(\.bottomsilkscreen\.ger$)|(bottom silk screen\.txt$)/i
},
{
id: 'bsp',
name: {
en: 'bottom solderpaste'
},
match: /(B.Paste)|(\.((crs$)|(bsp$)|(gbp$)|(spb$)))|(\.bcream\.ger$)/i
},
{
id: 'icu',
name: {
en: 'inner copper'
},
match: /(In(ner)?\d+.Cu)|(\.((ly)|(g)|(in))\d+$)|(\.internalplane\d+\.ger$)/i
},
{
id: 'out',
name: {
en: 'board outline'
},
match: /(Edge.Cuts)|(\.((dim$)|(mil$)|(gm[l\d]$)|(gko$)|(fab$)))|(\.boardoutline\.ger$)|(\.outline\.gbr$)|(mechanical \d+\.txt$)/i
},
{
id: 'drl',
name: {
en: 'drill hits'
},
match: /\.((fab\.gbr$)|(cnc$)|(drl$)|(xln$)|(txt$)|(tap$)|(drd$)|(exc$)|(npt$))/i
},
{
id: 'drw',
name: {
en: 'gerber drawing'
},
match: /.*/
}
]
module.exports = function whatsThatGerber(filename) {
return find(layerTypes, function(type) {
return type.match.test(filename)
}).id
}
module.exports.getAllTypes = function() {
return layerTypes.map(function(type) {
return type.id
})
}
module.exports.isValidType = function(type) {
return layerTypes.some(function(layerType) {
return layerType.id === type
})
}
module.exports.getFullName = function whatsThatGerberTypeName(typeId, locale) {
var type = find(layerTypes, function(type) {
return type.id === typeId
})
locale = locale || 'en'
if (!type || !type.name[locale]) {
return ''
}
return type.name[locale]
}