├── .gitignore
├── .gitmodules
├── .npmignore
├── .travis.yml
├── .zuul.yml
├── LICENSE.md
├── README.md
├── docs
├── bundle.js
├── favicon.ico
├── index.html
└── index.js
├── lib
├── cpl_capacitors.js
├── cpl_leds.js
├── cpl_resistors.js
├── flatten.js
├── grammar.js
├── index.js
├── match_cpl.js
└── parse.js
├── package-lock.json
├── package.json
├── prepare_cpl.js
├── src
├── flatten.js
├── grammar.js
├── grammar.ne
├── index.js
├── letters.ne
├── match_cpl.js
├── metric_prefix.ne
├── package_size.ne
├── parse.js
└── util.ne
├── test
├── test_grammar.js
├── test_match_cpl.js
└── test_parse.js
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | .nyc_output/
3 | node_modules/
4 | test-lib/
5 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "cpl-data"]
2 | path = cpl-data
3 | url = https://github.com/octopart/cpl-data
4 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src/
2 | test/
3 | docs/
4 | coverage/
5 | .nyc_output/
6 | prepare_cpl.js
7 | cpl-data/
8 | .gitmodules
9 | .travis.yml
10 | .zuul.yml
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "6"
4 | - "8"
5 | - "node"
6 | script:
7 | - yarn test
8 | - yarn demo
9 |
--------------------------------------------------------------------------------
/.zuul.yml:
--------------------------------------------------------------------------------
1 | ui: mocha-bdd
2 | globals: token
3 | concurrency: 1
4 | browsers:
5 | - name: chrome
6 | version: [26, latest]
7 | - name: safari
8 | version: [5, latest]
9 | - name: firefox
10 | version: [4, latest]
11 | - name: ie
12 | version: [9, latest]
13 | - name: microsoftedge
14 | version: [13, latest]
15 | - name: opera
16 | version: [11, latest]
17 | - name: android
18 | version: [4.4, latest]
19 | - name: iphone
20 | version: [8.1, latest]
21 | - name: ipad
22 | version: [8.1, latest]
23 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright 2017-2018 Kaspar Emanuel
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Electro Grammar
2 |
3 | [⚡ demo](https://kitspace.github.io/electro-grammar/)
4 |
5 | [](https://www.npmjs.com/package/electro-grammar)
6 |
7 | This is a parser using [Nearley](http://nearley.js.org/) that defines a grammar for describing generic electronic components such as surface mount resistors, capacitors and LEDs.
8 | A function to match the result to parts in the [Common Parts Library][CPL] is also provided.
9 |
10 | ```
11 | npm install electro-grammar
12 | ```
13 |
14 |
15 | ```js
16 | const {parse, matchCPL} = require('electro-grammar')
17 | ```
18 |
19 | ## Where is this used?
20 |
21 | - [1-click BOM browser extension](https://1clickbom.com)
22 | - [Kitspace BOM Builder](https://github.com/kitspace/bom-builder) (currently in alpha)
23 | - [electron-lang](https://github.com/electron-lang/electron) for [`@cpl`](https://github.com/electron-lang/electron/blob/master/docs/reference.md#cpldescr)
24 |
25 | ## Parsing
26 |
27 | ### Capacitors
28 | Parses capacitance, package size, characteristic, tolerance and voltage rating for capacitors.
29 |
30 | ```js
31 | > parse('100nF 0603 C0G 10% 25V')
32 | { type: 'capacitor',
33 | capacitance: 1e-7,
34 | size: '0603',
35 | characteristic: 'C0G',
36 | tolerance: 10,
37 | voltage_rating: 25 }
38 | ```
39 |
40 | For [class 1][CLASS-1] ceramic names and EIA letter codes are understood.
41 | For [class 2][CLASS-2] only EIA letter codes are understood.
42 | In both cases only EIA letter codes are returned.
43 |
44 | ```js
45 | > parse('10pF C0G/NP0')
46 | { type: 'capacitor', capacitance: 1e-11, characteristic: 'C0G' }
47 | > parse('10pF NP0')
48 | { type: 'capacitor', capacitance: 1e-11, characteristic: 'C0G' }
49 | > parse('10pF X7R')
50 | { type: 'capacitor', capacitance: 1e-11, characteristic: 'X7R' }
51 | ```
52 |
53 | ### Resistors
54 | Parses resistance, package size, tolerance and power rating for resistors.
55 |
56 | ```js
57 | > parse('1k 0805 5% 125mW')
58 | { type: 'resistor',
59 | resistance: 1000,
60 | size: '0805',
61 | tolerance: 5,
62 | power_rating: 0.125 }
63 | ```
64 |
65 | Electro-grammar supports several different ways to express resistance.
66 |
67 | ```js
68 | > parse('1.5k')
69 | { type: 'resistor', resistance: 1500 }
70 | > parse('1k5')
71 | { type: 'resistor', resistance: 1500 }
72 | > parse('500R')
73 | { type: 'resistor', resistance: 500 }
74 | > parse('1500 ohm')
75 | { type: 'resistor', resistance: 1500 }
76 | > parse('1500.0 ohm')
77 | { type: 'resistor', resistance: 1500 }
78 | > parse('1500 Ω')
79 | { type: 'resistor', resistance: 1500 }
80 | > parse('resistor 1500')
81 | { type: 'resistor', resistance: 1500 }
82 | ```
83 |
84 | ### LEDs
85 |
86 | LEDs need to include the word 'LED' or 'led'.
87 |
88 | ```js
89 | > parse('LED red')
90 | { type: 'led', color: 'red' }
91 | > parse('LED 0603')
92 | { type: 'led', size: '0603' }
93 | > parse('green led 1206')
94 | { type: 'led', color: 'green', size: '1206' }
95 | ```
96 |
97 |
98 | ### Parsing Details
99 |
100 | Converts all units to floating point numbers.
101 |
102 | ```js
103 | > parse('100nF')
104 | { type: 'capacitor', capacitance: 1e-7 }
105 | > parse('0.1uF')
106 | { type: 'capacitor', capacitance: 1e-7 }
107 | ```
108 |
109 | The order of the terms doesn't matter.
110 |
111 | ```js
112 | > parse('1% 0603 1uF')
113 | { type: 'capacitor'
114 | capacitance: 0.000001,
115 | tolerance: 1,
116 | size: "0603" }
117 | > parse('0603 1% 1uF')
118 | { type: 'capacitor',
119 | capacitance: 0.000001,
120 | tolerance: 1,
121 | size: "0603" }
122 | ```
123 |
124 | If no match is found an empty object is returned.
125 |
126 | ```js
127 | > parse('')
128 | {}
129 | > parse('NE555P')
130 | {}
131 | ```
132 |
133 | But invalid input types will throw.
134 |
135 | ```js
136 | > parse({})
137 | TypeError: str.split is not a function
138 | ```
139 |
140 | Text that is not part of the grammar is simply ignored.
141 |
142 | ```js
143 | > parse('NE555P 1uF')
144 | { type: 'capacitor', capacitance: 0.000001 }
145 | > parse('these words 1k are ignored 0805')
146 | { type: 'resistor', resistance: 1000, size: '0805' }
147 | ```
148 |
149 | You can use metric package sizes as long as you make it clear by using the `metric` keyword.
150 | Output for package sizes is always in imperial.
151 |
152 | ```js
153 | > parse('1k metric 0603')
154 | { type: 'resistor', resistance: 1000, size: '0201' }
155 | > parse('1k 0603 metric')
156 | { type: 'resistor', resistance: 1000, size: '0201' }
157 | ```
158 |
159 | You can give it a hint to the type of component by starting off with that. For instance you can leave of F or farad if you start off with 'capacitor' or 'c'
160 |
161 | ```js
162 | > parse('capacitor 1u')
163 | { type: 'capacitor', capacitance: 0.000001 }
164 | > parse('c 1u')
165 | { type: 'capacitor', capacitance: 0.000001 }
166 | > parse('resistor 100')
167 | { type: 'resistor', resistance: 100 }
168 | > parse('res 100')
169 | { type: 'resistor', resistance: 100 }
170 | > parse('r 100')
171 | { type: 'resistor', resistance: 100 }
172 | ```
173 |
174 | ## CPL Matching
175 | `matchCPL` tries to find as many matches as it can from the [Common Parts Library][CPL] and returns an array of CPL IDs.
176 | You could match these against [CPL data][CPL-Data] or search for them on Octopart to get exact part numbers.
177 | If no matches are found or the function is given invalid input an empty array is returned.
178 |
179 | ```js
180 | > c = parse('0.1uF 0805 25V')
181 | { type: 'capacitor',
182 | capacitance: 1e-7,
183 | size: '0805',
184 | voltage_rating: 25 }
185 | > matchCPL(c)
186 | [ 'CPL-CAP-X7R-0805-100NF-50V' ]
187 |
188 | > r = parse('10k 0603')
189 | { type: 'resistor', resistance: 10000, size: '0603' }
190 | > matchCPL(r)
191 | [ 'CPL-RES-0603-10K-0.1W' ]
192 |
193 | > // I don't think it's possible to make such a resistor
194 | > r = parse('1k 1000000W')
195 | { type: 'resistor', resistance: 1000, power_rating: 1000000 }
196 | > matchCPL(r)
197 | []
198 |
199 | > matchCPL({invalid: 'input'})
200 | []
201 |
202 | > matchCPL(null)
203 | []
204 | ```
205 |
206 | ## Roadmap
207 |
208 | We are currently working on v2 of Electro Grammar which will have parsers in many more languages:
209 |
210 | ### v1
211 |
212 | - JavaScript only
213 | - Capacitors, resistors and LEDs (SMD only)
214 | - Lax parser only (any-order, ignores invalid input)
215 |
216 | ### v2
217 |
218 | - Work in progress!
219 | - Uses Antlr4: JavaScript (API compatible with v1), Python, Java, C (& C++), Go
220 | - Capacitors, resistors, LEDs, diodes, transistors (SMD & through-hole)
221 | - Strict and lax parser
222 |
223 | Head to the [issue tracker][ISSUES] or the [Gitter Room][CHAT] if you want to help or need to know more details.
224 |
225 | ## License
226 |
227 | Electro Grammar is MIT licensed. It can be freely used in open source and
228 | propietary work as long as you include the copyright notice in all copies. See
229 | the [LICENSE.md][LICENSE] file for details.
230 |
231 | [CPL]: https://octopart.com/common-parts-library#Resistors
232 | [CPL-DATA]: https://github.com/octopart/CPL-Data
233 | [BADGE]: https://travis-ci.org/kitspace/electro-grammar.svg?branch=master
234 | [BUILD]: https://travis-ci.org/kitspace/electro-grammar
235 | [CLASS-1]: https://en.wikipedia.org/wiki/Ceramic_capacitor#Class_1_ceramic_capacitors
236 | [CLASS-2]: https://en.wikipedia.org/wiki/Ceramic_capacitor#Class_2_ceramic_capacitors
237 | [ISSUES]: https://github.com/kitspace/electro-grammar/issues
238 | [CHAT]: https://gitter.im/monostable/electro-grammar
239 | [LICENSE]: https://github.com/kitspace/electro-grammar/blob/master/LICENSE.md
240 |
--------------------------------------------------------------------------------
/docs/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kitspace/electro-grammar/393a079814847f39e16bd584a39087382b57c6d4/docs/favicon.ico
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Electro Grammar Demo
6 |
7 |
8 |
13 |
14 |
15 |
21 |
22 | This is a demo of
23 |
24 | electro-grammar ,
25 | a lightning fast parser of electronic component descriptions.
26 | Electro-grammar defines a grammar
28 | of electronic parts which is executed by Nearley . Currently only surface mount
30 | resistors, capacitors and LEDs are supported but the grammar could be expanded to
31 | include other parts. A function to match the result to a part in the Common
33 | Parts Library is also provided.
34 |
35 |
36 | Try typing in a description of a surface mount resistor, capacitor or LED below.
37 |
38 |
39 |
40 |
41 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/docs/index.js:
--------------------------------------------------------------------------------
1 | var electroGrammar = require('../lib/index')
2 |
3 | var parse = electroGrammar.parse
4 | var matchCPL = electroGrammar.matchCPL
5 |
6 | var input = document.getElementById('input')
7 | var component = document.getElementById('component')
8 | var cplids = document.getElementById('cplids')
9 |
10 | function setOutput() {
11 | var c = parse(input.value || input.placeholder)
12 | component.innerHTML = JSON.stringify(c, null, 2)
13 | var cplParts = matchCPL(c)
14 | while (cplids.hasChildNodes()) {
15 | cplids.removeChild(cplids.lastChild);
16 | }
17 | cplParts.forEach(function(p) {
18 | var li = document.createElement('li')
19 | var a = document.createElement('a')
20 | a.href = 'https://octopart.com/search?q=' + p
21 | a.appendChild(document.createTextNode(p))
22 | li.appendChild(a)
23 | cplids.appendChild(li)
24 | })
25 |
26 | }
27 |
28 | setOutput()
29 | input.oninput = setOutput
30 |
--------------------------------------------------------------------------------
/lib/cpl_capacitors.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | "type": "capacitor",
4 | "capacitance": 1e-12,
5 | "voltage_rating": 50,
6 | "size": "0402",
7 | "characteristic": "C0G",
8 | "cplid": "CPL-CAP-C0G-0402-1PF-50V"
9 | },
10 | {
11 | "type": "capacitor",
12 | "capacitance": 1e-12,
13 | "voltage_rating": 50,
14 | "size": "0603",
15 | "characteristic": "C0G",
16 | "cplid": "CPL-CAP-C0G-0603-1PF-50V"
17 | },
18 | {
19 | "type": "capacitor",
20 | "capacitance": 1e-11,
21 | "tolerance": 5,
22 | "voltage_rating": 50,
23 | "size": "0402",
24 | "characteristic": "C0G",
25 | "cplid": "CPL-CAP-C0G-0402-10PF-50V"
26 | },
27 | {
28 | "type": "capacitor",
29 | "capacitance": 1e-11,
30 | "tolerance": 5,
31 | "voltage_rating": 50,
32 | "size": "0603",
33 | "characteristic": "C0G",
34 | "cplid": "CPL-CAP-C0G-0603-10PF-50V"
35 | },
36 | {
37 | "type": "capacitor",
38 | "capacitance": 1.2e-11,
39 | "tolerance": 5,
40 | "voltage_rating": 50,
41 | "size": "0603",
42 | "characteristic": "C0G",
43 | "cplid": "CPL-CAP-C0G-0603-12PF-50V"
44 | },
45 | {
46 | "type": "capacitor",
47 | "capacitance": 1.8e-11,
48 | "tolerance": 5,
49 | "voltage_rating": 50,
50 | "size": "0603",
51 | "characteristic": "C0G",
52 | "cplid": "CPL-CAP-C0G-0603-18PF-50V"
53 | },
54 | {
55 | "type": "capacitor",
56 | "capacitance": 2.2e-11,
57 | "tolerance": 5,
58 | "voltage_rating": 50,
59 | "size": "0402",
60 | "characteristic": "C0G",
61 | "cplid": "CPL-CAP-C0G-0402-22PF-50V"
62 | },
63 | {
64 | "type": "capacitor",
65 | "capacitance": 2.2e-11,
66 | "tolerance": 5,
67 | "voltage_rating": 50,
68 | "size": "0603",
69 | "characteristic": "C0G",
70 | "cplid": "CPL-CAP-C0G-0603-22PF-50V"
71 | },
72 | {
73 | "type": "capacitor",
74 | "capacitance": 2.7e-11,
75 | "tolerance": 5,
76 | "voltage_rating": 50,
77 | "size": "0603",
78 | "characteristic": "C0G",
79 | "cplid": "CPL-CAP-C0G-0603-27PF-50V"
80 | },
81 | {
82 | "type": "capacitor",
83 | "capacitance": 3.3e-11,
84 | "tolerance": 5,
85 | "voltage_rating": 50,
86 | "size": "0603",
87 | "characteristic": "C0G",
88 | "cplid": "CPL-CAP-C0G-0603-33PF-50V"
89 | },
90 | {
91 | "type": "capacitor",
92 | "capacitance": 1e-10,
93 | "tolerance": 5,
94 | "voltage_rating": 50,
95 | "size": "0603",
96 | "characteristic": "C0G",
97 | "cplid": "CPL-CAP-C0G-0603-100PF-50V"
98 | },
99 | {
100 | "type": "capacitor",
101 | "capacitance": 2.2e-10,
102 | "tolerance": 5,
103 | "voltage_rating": 50,
104 | "size": "0603",
105 | "characteristic": "C0G",
106 | "cplid": "CPL-CAP-C0G-0603-220PF-50V"
107 | },
108 | {
109 | "type": "capacitor",
110 | "capacitance": 1e-9,
111 | "tolerance": 5,
112 | "voltage_rating": 50,
113 | "size": "0603",
114 | "characteristic": "C0G",
115 | "cplid": "CPL-CAP-C0G-0603-1NF-50V"
116 | },
117 | {
118 | "type": "capacitor",
119 | "capacitance": 1e-9,
120 | "tolerance": 10,
121 | "voltage_rating": 50,
122 | "size": "0402",
123 | "characteristic": "X7R",
124 | "cplid": "CPL-CAP-X7R-0402-1NF-50V"
125 | },
126 | {
127 | "type": "capacitor",
128 | "capacitance": 1e-9,
129 | "tolerance": 10,
130 | "voltage_rating": 50,
131 | "size": "0603",
132 | "characteristic": "X7R",
133 | "cplid": "CPL-CAP-X7R-0603-1NF-50V"
134 | },
135 | {
136 | "type": "capacitor",
137 | "capacitance": 4.7e-9,
138 | "tolerance": 10,
139 | "voltage_rating": 50,
140 | "size": "0603",
141 | "characteristic": "X7R",
142 | "cplid": "CPL-CAP-X7R-0603-4.7NF-50V"
143 | },
144 | {
145 | "type": "capacitor",
146 | "capacitance": 1e-8,
147 | "tolerance": 10,
148 | "voltage_rating": 50,
149 | "size": "0402",
150 | "characteristic": "X7R",
151 | "cplid": "CPL-CAP-X7R-0402-10NF-50V"
152 | },
153 | {
154 | "type": "capacitor",
155 | "capacitance": 1e-8,
156 | "tolerance": 10,
157 | "voltage_rating": 50,
158 | "size": "0603",
159 | "characteristic": "X7R",
160 | "cplid": "CPL-CAP-X7R-0603-10NF-50V"
161 | },
162 | {
163 | "type": "capacitor",
164 | "capacitance": 2.2e-8,
165 | "tolerance": 10,
166 | "voltage_rating": 50,
167 | "size": "0603",
168 | "characteristic": "X7R",
169 | "cplid": "CPL-CAP-X7R-0603-22NF-50V"
170 | },
171 | {
172 | "type": "capacitor",
173 | "capacitance": 4.7e-8,
174 | "tolerance": 10,
175 | "voltage_rating": 50,
176 | "size": "0603",
177 | "characteristic": "X7R",
178 | "cplid": "CPL-CAP-X7R-0603-47NF-50V"
179 | },
180 | {
181 | "type": "capacitor",
182 | "capacitance": 1e-7,
183 | "tolerance": 10,
184 | "voltage_rating": 16,
185 | "size": "0402",
186 | "characteristic": "X7R",
187 | "cplid": "CPL-CAP-X7R-0402-100NF-16V"
188 | },
189 | {
190 | "type": "capacitor",
191 | "capacitance": 1e-7,
192 | "tolerance": 10,
193 | "voltage_rating": 50,
194 | "size": "0603",
195 | "characteristic": "X7R",
196 | "cplid": "CPL-CAP-X7R-0603-100NF-50V"
197 | },
198 | {
199 | "type": "capacitor",
200 | "capacitance": 1e-7,
201 | "tolerance": 10,
202 | "voltage_rating": 50,
203 | "size": "0805",
204 | "characteristic": "X7R",
205 | "cplid": "CPL-CAP-X7R-0805-100NF-50V"
206 | },
207 | {
208 | "type": "capacitor",
209 | "capacitance": 2.2e-7,
210 | "tolerance": 10,
211 | "voltage_rating": 16,
212 | "size": "0603",
213 | "characteristic": "X7R",
214 | "cplid": "CPL-CAP-X7R-0603-220NF-16V"
215 | },
216 | {
217 | "type": "capacitor",
218 | "capacitance": 0.000001,
219 | "tolerance": 10,
220 | "voltage_rating": 6.3,
221 | "size": "0402",
222 | "characteristic": "X5R",
223 | "cplid": "CPL-CAP-X5R-0402-1UF-6.3V"
224 | },
225 | {
226 | "type": "capacitor",
227 | "capacitance": 0.000001,
228 | "tolerance": 10,
229 | "voltage_rating": 25,
230 | "size": "0603",
231 | "characteristic": "X7R",
232 | "cplid": "CPL-CAP-X7R-0603-1UF-25V"
233 | },
234 | {
235 | "type": "capacitor",
236 | "capacitance": 0.000001,
237 | "tolerance": 10,
238 | "voltage_rating": 25,
239 | "size": "0805",
240 | "characteristic": "X7R",
241 | "cplid": "CPL-CAP-X7R-0805-1UF-25V"
242 | },
243 | {
244 | "type": "capacitor",
245 | "capacitance": 0.0000047,
246 | "tolerance": 10,
247 | "voltage_rating": 10,
248 | "size": "0603",
249 | "characteristic": "X5R",
250 | "cplid": "CPL-CAP-X5R-0603-4.7UF-10V"
251 | },
252 | {
253 | "type": "capacitor",
254 | "capacitance": 0.0000047,
255 | "tolerance": 10,
256 | "voltage_rating": 25,
257 | "size": "0805",
258 | "characteristic": "X5R",
259 | "cplid": "CPL-CAP-X5R-0805-4.7UF-25V"
260 | },
261 | {
262 | "type": "capacitor",
263 | "capacitance": 0.00001,
264 | "tolerance": 10,
265 | "voltage_rating": 16,
266 | "size": "0805",
267 | "characteristic": "X5R",
268 | "cplid": "CPL-CAP-X5R-0805-10UF-16V"
269 | },
270 | {
271 | "type": "capacitor",
272 | "capacitance": 0.000022,
273 | "tolerance": 20,
274 | "voltage_rating": 6.3,
275 | "size": "0805",
276 | "characteristic": "X5R",
277 | "cplid": "CPL-CAP-X5R-0805-22UF-6.3V"
278 | },
279 | {
280 | "type": "capacitor",
281 | "capacitance": 0.0001,
282 | "tolerance": 20,
283 | "voltage_rating": 6.3,
284 | "size": "1206",
285 | "characteristic": "X5R",
286 | "cplid": "CPL-CAP-X5R-1206-100UF-6.3V"
287 | },
288 | {
289 | "type": "capacitor",
290 | "capacitance": 0.000001,
291 | "tolerance": 10,
292 | "voltage_rating": 35,
293 | "size": "1206",
294 | "cplid": "CPL-CAP-TAN-1206-1UF-35V"
295 | },
296 | {
297 | "type": "capacitor",
298 | "capacitance": 0.0000047,
299 | "tolerance": 10,
300 | "voltage_rating": 16,
301 | "size": "1206",
302 | "cplid": "CPL-CAP-TAN-1206-4.7UF-16V"
303 | },
304 | {
305 | "type": "capacitor",
306 | "capacitance": 0.00001,
307 | "tolerance": 10,
308 | "voltage_rating": 16,
309 | "size": "1206",
310 | "cplid": "CPL-CAP-TAN-1206-10UF-16V"
311 | },
312 | {
313 | "type": "capacitor",
314 | "capacitance": 0.00001,
315 | "tolerance": 10,
316 | "voltage_rating": 16,
317 | "size": "1210",
318 | "cplid": "CPL-CAP-TAN-1210-10UF-16V"
319 | },
320 | {
321 | "type": "capacitor",
322 | "capacitance": 0.000022,
323 | "tolerance": 10,
324 | "voltage_rating": 16,
325 | "size": "1210",
326 | "cplid": "CPL-CAP-TAN-1210-22UF-16V"
327 | },
328 | {
329 | "type": "capacitor",
330 | "capacitance": 0.000047,
331 | "tolerance": 10,
332 | "voltage_rating": 16,
333 | "cplid": "CPL-CAP-TAN-2312-47UF-16V"
334 | },
335 | {
336 | "type": "capacitor",
337 | "capacitance": 0.0001,
338 | "tolerance": 10,
339 | "voltage_rating": 16,
340 | "cplid": "CPL-CAP-TAN-2312-100UF-16V"
341 | },
342 | {
343 | "type": "capacitor",
344 | "capacitance": 0.0001,
345 | "tolerance": 10,
346 | "voltage_rating": 10,
347 | "cplid": "CPL-CAP-TAN-2312-100UF-10V"
348 | },
349 | {
350 | "type": "capacitor",
351 | "capacitance": 0.0000022,
352 | "tolerance": 20,
353 | "voltage_rating": 50,
354 | "cplid": "CPL-CAP-ALU-RAD-2.2UF-50V"
355 | },
356 | {
357 | "type": "capacitor",
358 | "capacitance": 0.0000047,
359 | "tolerance": 20,
360 | "voltage_rating": 50,
361 | "cplid": "CPL-CAP-ALU-RAD-4.7UF-50V"
362 | },
363 | {
364 | "type": "capacitor",
365 | "capacitance": 0.00001,
366 | "tolerance": 20,
367 | "voltage_rating": 50,
368 | "cplid": "CPL-CAP-ALU-RAD-10UF-50V"
369 | },
370 | {
371 | "type": "capacitor",
372 | "capacitance": 0.000022,
373 | "tolerance": 20,
374 | "voltage_rating": 50,
375 | "cplid": "CPL-CAP-ALU-RAD-22UF-50V"
376 | },
377 | {
378 | "type": "capacitor",
379 | "capacitance": 0.000047,
380 | "tolerance": 20,
381 | "voltage_rating": 50,
382 | "cplid": "CPL-CAP-ALU-RAD-47UF-50V"
383 | },
384 | {
385 | "type": "capacitor",
386 | "capacitance": 0.0001,
387 | "tolerance": 20,
388 | "voltage_rating": 50,
389 | "cplid": "CPL-CAP-ALU-RAD-100UF-50V"
390 | },
391 | {
392 | "type": "capacitor",
393 | "capacitance": 0.00022,
394 | "tolerance": 20,
395 | "voltage_rating": 50,
396 | "cplid": "CPL-CAP-ALU-RAD-220UF-50V"
397 | },
398 | {
399 | "type": "capacitor",
400 | "capacitance": 0.00047,
401 | "tolerance": 20,
402 | "voltage_rating": 50,
403 | "cplid": "CPL-CAP-ALU-RAD-470UF-50V"
404 | },
405 | {
406 | "type": "capacitor",
407 | "capacitance": 0.001,
408 | "tolerance": 20,
409 | "voltage_rating": 25,
410 | "cplid": "CPL-CAP-ALU-RAD-1000UF-25V"
411 | }
412 | ]
--------------------------------------------------------------------------------
/lib/cpl_leds.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | "type": "led",
4 | "color": "green",
5 | "size": "0603",
6 | "cplid": "CPL-LED-0603-GREEN"
7 | },
8 | {
9 | "type": "led",
10 | "color": "red",
11 | "size": "0603",
12 | "cplid": "CPL-LED-0603-RED"
13 | },
14 | {
15 | "type": "led",
16 | "color": "yellow",
17 | "size": "0603",
18 | "cplid": "CPL-LED-0603-YELLOW"
19 | },
20 | {
21 | "type": "led",
22 | "color": "orange",
23 | "size": "0603",
24 | "cplid": "CPL-LED-0603-ORANGE"
25 | },
26 | {
27 | "type": "led",
28 | "color": "amber",
29 | "size": "0603",
30 | "cplid": "CPL-LED-0603-AMBER"
31 | },
32 | {
33 | "type": "led",
34 | "color": "blue",
35 | "size": "0603",
36 | "cplid": "CPL-LED-0603-BLUE"
37 | },
38 | {
39 | "type": "led",
40 | "color": "white",
41 | "size": "0603",
42 | "cplid": "CPL-LED-0603-WHITE"
43 | }
44 | ]
--------------------------------------------------------------------------------
/lib/cpl_resistors.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | {
3 | "type": "resistor",
4 | "resistance": 0,
5 | "size": "0402",
6 | "power_rating": 0.063,
7 | "cplid": "CPL-RES-0402-0-0.063W"
8 | },
9 | {
10 | "type": "resistor",
11 | "resistance": 0,
12 | "size": "0603",
13 | "power_rating": 0.1,
14 | "cplid": "CPL-RES-0603-0-0.1W"
15 | },
16 | {
17 | "type": "resistor",
18 | "resistance": 0,
19 | "size": "0805",
20 | "power_rating": 0.125,
21 | "cplid": "CPL-RES-0805-0-0.125W"
22 | },
23 | {
24 | "type": "resistor",
25 | "resistance": 0,
26 | "size": "1206",
27 | "power_rating": 0.25,
28 | "cplid": "CPL-RES-1206-0-0.25W"
29 | },
30 | {
31 | "type": "resistor",
32 | "resistance": 10,
33 | "tolerance": 1,
34 | "size": "0402",
35 | "power_rating": 0.063,
36 | "cplid": "CPL-RES-0402-10-0.063W"
37 | },
38 | {
39 | "type": "resistor",
40 | "resistance": 10,
41 | "tolerance": 1,
42 | "size": "0603",
43 | "power_rating": 0.1,
44 | "cplid": "CPL-RES-0603-10-0.1W"
45 | },
46 | {
47 | "type": "resistor",
48 | "resistance": 10,
49 | "tolerance": 1,
50 | "size": "0805",
51 | "power_rating": 0.125,
52 | "cplid": "CPL-RES-0805-10-0.125W"
53 | },
54 | {
55 | "type": "resistor",
56 | "resistance": 10,
57 | "tolerance": 1,
58 | "size": "1206",
59 | "power_rating": 0.25,
60 | "cplid": "CPL-RES-1206-10-0.25W"
61 | },
62 | {
63 | "type": "resistor",
64 | "resistance": 12,
65 | "tolerance": 1,
66 | "size": "0603",
67 | "power_rating": 0.1,
68 | "cplid": "CPL-RES-0603-12-0.1W"
69 | },
70 | {
71 | "type": "resistor",
72 | "resistance": 15,
73 | "tolerance": 1,
74 | "size": "0603",
75 | "power_rating": 0.1,
76 | "cplid": "CPL-RES-0603-15-0.1W"
77 | },
78 | {
79 | "type": "resistor",
80 | "resistance": 22,
81 | "tolerance": 1,
82 | "size": "0603",
83 | "power_rating": 0.1,
84 | "cplid": "CPL-RES-0603-22-0.1W"
85 | },
86 | {
87 | "type": "resistor",
88 | "resistance": 33.2,
89 | "tolerance": 1,
90 | "size": "0603",
91 | "power_rating": 0.1,
92 | "cplid": "CPL-RES-0603-33.2-0.1W"
93 | },
94 | {
95 | "type": "resistor",
96 | "resistance": 47,
97 | "tolerance": 1,
98 | "size": "0603",
99 | "power_rating": 0.1,
100 | "cplid": "CPL-RES-0603-47-0.1W"
101 | },
102 | {
103 | "type": "resistor",
104 | "resistance": 49.9,
105 | "tolerance": 1,
106 | "size": "0603",
107 | "power_rating": 0.1,
108 | "cplid": "CPL-RES-0603-49.9-0.1W"
109 | },
110 | {
111 | "type": "resistor",
112 | "resistance": 56.2,
113 | "tolerance": 1,
114 | "size": "0603",
115 | "power_rating": 0.1,
116 | "cplid": "CPL-RES-0603-56.2-0.1W"
117 | },
118 | {
119 | "type": "resistor",
120 | "resistance": 68.1,
121 | "tolerance": 1,
122 | "size": "0603",
123 | "power_rating": 0.1,
124 | "cplid": "CPL-RES-0603-68.1-0.1W"
125 | },
126 | {
127 | "type": "resistor",
128 | "resistance": 75,
129 | "tolerance": 1,
130 | "size": "0603",
131 | "power_rating": 0.1,
132 | "cplid": "CPL-RES-0603-75-0.1W"
133 | },
134 | {
135 | "type": "resistor",
136 | "resistance": 82.5,
137 | "tolerance": 1,
138 | "size": "0603",
139 | "power_rating": 0.1,
140 | "cplid": "CPL-RES-0603-82.5-0.1W"
141 | },
142 | {
143 | "type": "resistor",
144 | "resistance": 100,
145 | "tolerance": 1,
146 | "size": "0402",
147 | "power_rating": 0.063,
148 | "cplid": "CPL-RES-0402-100-0.063W"
149 | },
150 | {
151 | "type": "resistor",
152 | "resistance": 100,
153 | "tolerance": 1,
154 | "size": "0603",
155 | "power_rating": 0.1,
156 | "cplid": "CPL-RES-0603-100-0.1W"
157 | },
158 | {
159 | "type": "resistor",
160 | "resistance": 100,
161 | "tolerance": 1,
162 | "size": "0805",
163 | "power_rating": 0.125,
164 | "cplid": "CPL-RES-0805-100-0.125W"
165 | },
166 | {
167 | "type": "resistor",
168 | "resistance": 100,
169 | "tolerance": 1,
170 | "size": "1206",
171 | "power_rating": 0.25,
172 | "cplid": "CPL-RES-1206-100-0.25W"
173 | },
174 | {
175 | "type": "resistor",
176 | "resistance": 120,
177 | "tolerance": 1,
178 | "size": "0603",
179 | "power_rating": 0.1,
180 | "cplid": "CPL-RES-0603-120-0.1W"
181 | },
182 | {
183 | "type": "resistor",
184 | "resistance": 150,
185 | "tolerance": 1,
186 | "size": "0603",
187 | "power_rating": 0.1,
188 | "cplid": "CPL-RES-0603-150-0.1W"
189 | },
190 | {
191 | "type": "resistor",
192 | "resistance": 220,
193 | "tolerance": 1,
194 | "size": "0603",
195 | "power_rating": 0.1,
196 | "cplid": "CPL-RES-0603-220-0.1W"
197 | },
198 | {
199 | "type": "resistor",
200 | "resistance": 330,
201 | "tolerance": 1,
202 | "size": "0603",
203 | "power_rating": 0.1,
204 | "cplid": "CPL-RES-0603-330-0.1W"
205 | },
206 | {
207 | "type": "resistor",
208 | "resistance": 390,
209 | "tolerance": 1,
210 | "size": "0603",
211 | "power_rating": 0.1,
212 | "cplid": "CPL-RES-0603-390-0.1W"
213 | },
214 | {
215 | "type": "resistor",
216 | "resistance": 470,
217 | "tolerance": 1,
218 | "size": "0603",
219 | "power_rating": 0.1,
220 | "cplid": "CPL-RES-0603-470-0.1W"
221 | },
222 | {
223 | "type": "resistor",
224 | "resistance": 560,
225 | "tolerance": 1,
226 | "size": "0603",
227 | "power_rating": 0.1,
228 | "cplid": "CPL-RES-0603-560-0.1W"
229 | },
230 | {
231 | "type": "resistor",
232 | "resistance": 681,
233 | "tolerance": 1,
234 | "size": "0603",
235 | "power_rating": 0.1,
236 | "cplid": "CPL-RES-0603-681-0.1W"
237 | },
238 | {
239 | "type": "resistor",
240 | "resistance": 820,
241 | "tolerance": 1,
242 | "size": "0603",
243 | "power_rating": 0.1,
244 | "cplid": "CPL-RES-0603-820-0.1W"
245 | },
246 | {
247 | "type": "resistor",
248 | "resistance": 1000,
249 | "tolerance": 1,
250 | "size": "0402",
251 | "power_rating": 0.063,
252 | "cplid": "CPL-RES-0402-1K-0.063W"
253 | },
254 | {
255 | "type": "resistor",
256 | "resistance": 1000,
257 | "tolerance": 1,
258 | "size": "0603",
259 | "power_rating": 0.1,
260 | "cplid": "CPL-RES-0603-1K-0.1W"
261 | },
262 | {
263 | "type": "resistor",
264 | "resistance": 1000,
265 | "tolerance": 1,
266 | "size": "0805",
267 | "power_rating": 0.125,
268 | "cplid": "CPL-RES-0805-1K-0.125W"
269 | },
270 | {
271 | "type": "resistor",
272 | "resistance": 1000,
273 | "tolerance": 1,
274 | "size": "1206",
275 | "power_rating": 0.25,
276 | "cplid": "CPL-RES-1206-1K-0.25W"
277 | },
278 | {
279 | "type": "resistor",
280 | "resistance": 1200,
281 | "tolerance": 1,
282 | "size": "0603",
283 | "power_rating": 0.1,
284 | "cplid": "CPL-RES-0603-1.2K-0.1W"
285 | },
286 | {
287 | "type": "resistor",
288 | "resistance": 1500,
289 | "tolerance": 1,
290 | "size": "0603",
291 | "power_rating": 0.1,
292 | "cplid": "CPL-RES-0603-1.5K-0.1W"
293 | },
294 | {
295 | "type": "resistor",
296 | "resistance": 2000,
297 | "tolerance": 1,
298 | "size": "0603",
299 | "power_rating": 0.1,
300 | "cplid": "CPL-RES-0603-2K-0.1W"
301 | },
302 | {
303 | "type": "resistor",
304 | "resistance": 3300,
305 | "tolerance": 1,
306 | "size": "0402",
307 | "power_rating": 0.063,
308 | "cplid": "CPL-RES-0603-3.3K-0.1W"
309 | },
310 | {
311 | "type": "resistor",
312 | "resistance": 3300,
313 | "tolerance": 1,
314 | "size": "0603",
315 | "power_rating": 0.1,
316 | "cplid": "CPL-RES-0603-3.3K-0.1W"
317 | },
318 | {
319 | "type": "resistor",
320 | "resistance": 3300,
321 | "tolerance": 1,
322 | "size": "0805",
323 | "power_rating": 0.125,
324 | "cplid": "CPL-RES-0603-3.3K-0.1W"
325 | },
326 | {
327 | "type": "resistor",
328 | "resistance": 3300,
329 | "tolerance": 1,
330 | "size": "1206",
331 | "power_rating": 0.25,
332 | "cplid": "CPL-RES-0603-3.3K-0.1W"
333 | },
334 | {
335 | "type": "resistor",
336 | "resistance": 3600,
337 | "tolerance": 1,
338 | "size": "0603",
339 | "power_rating": 0.1,
340 | "cplid": "CPL-RES-0603-3.6K-0.1W"
341 | },
342 | {
343 | "type": "resistor",
344 | "resistance": 4700,
345 | "tolerance": 1,
346 | "size": "0402",
347 | "power_rating": 0.063,
348 | "cplid": "CPL-RES-0402-4.7K-0.063W"
349 | },
350 | {
351 | "type": "resistor",
352 | "resistance": 4700,
353 | "tolerance": 1,
354 | "size": "0603",
355 | "power_rating": 0.1,
356 | "cplid": "CPL-RES-0603-4.7K-0.1W"
357 | },
358 | {
359 | "type": "resistor",
360 | "resistance": 4700,
361 | "tolerance": 1,
362 | "size": "0805",
363 | "power_rating": 0.125,
364 | "cplid": "CPL-RES-0805-4.7K-0.125W"
365 | },
366 | {
367 | "type": "resistor",
368 | "resistance": 4700,
369 | "tolerance": 1,
370 | "size": "1206",
371 | "power_rating": 0.25,
372 | "cplid": "CPL-RES-1206-4.7K-0.25W"
373 | },
374 | {
375 | "type": "resistor",
376 | "resistance": 5600,
377 | "tolerance": 1,
378 | "size": "0603",
379 | "power_rating": 0.1,
380 | "cplid": "CPL-RES-0603-5.6K-0.1W"
381 | },
382 | {
383 | "type": "resistor",
384 | "resistance": 6800,
385 | "tolerance": 1,
386 | "size": "0603",
387 | "power_rating": 0.1,
388 | "cplid": "CPL-RES-0603-6.8K-0.1W"
389 | },
390 | {
391 | "type": "resistor",
392 | "resistance": 8200,
393 | "tolerance": 1,
394 | "size": "0603",
395 | "power_rating": 0.1,
396 | "cplid": "CPL-RES-0603-8.2K-0.1W"
397 | },
398 | {
399 | "type": "resistor",
400 | "resistance": 10000,
401 | "tolerance": 1,
402 | "size": "0402",
403 | "power_rating": 0.063,
404 | "cplid": "CPL-RES-0402-10K-0.063W"
405 | },
406 | {
407 | "type": "resistor",
408 | "resistance": 10000,
409 | "tolerance": 1,
410 | "size": "0603",
411 | "power_rating": 0.1,
412 | "cplid": "CPL-RES-0603-10K-0.1W"
413 | },
414 | {
415 | "type": "resistor",
416 | "resistance": 10000,
417 | "tolerance": 1,
418 | "size": "0805",
419 | "power_rating": 0.125,
420 | "cplid": "CPL-RES-0805-10K-0.125W"
421 | },
422 | {
423 | "type": "resistor",
424 | "resistance": 10000,
425 | "tolerance": 1,
426 | "size": "1206",
427 | "power_rating": 0.25,
428 | "cplid": "CPL-RES-1206-10K-0.25W"
429 | },
430 | {
431 | "type": "resistor",
432 | "resistance": 12000,
433 | "tolerance": 1,
434 | "size": "0603",
435 | "power_rating": 0.1,
436 | "cplid": "CPL-RES-0603-12K-0.1W"
437 | },
438 | {
439 | "type": "resistor",
440 | "resistance": 15000,
441 | "tolerance": 1,
442 | "size": "0603",
443 | "power_rating": 0.1,
444 | "cplid": "CPL-RES-0603-15K-0.1W"
445 | },
446 | {
447 | "type": "resistor",
448 | "resistance": 22000,
449 | "tolerance": 1,
450 | "size": "0603",
451 | "power_rating": 0.1,
452 | "cplid": "CPL-RES-0603-22K-0.1W"
453 | },
454 | {
455 | "type": "resistor",
456 | "resistance": 33200,
457 | "tolerance": 1,
458 | "size": "0603",
459 | "power_rating": 0.1,
460 | "cplid": "CPL-RES-0603-33.2K-0.1W"
461 | },
462 | {
463 | "type": "resistor",
464 | "resistance": 47000,
465 | "tolerance": 1,
466 | "size": "0603",
467 | "power_rating": 0.1,
468 | "cplid": "CPL-RES-0603-47K-0.1W"
469 | },
470 | {
471 | "type": "resistor",
472 | "resistance": 56200,
473 | "tolerance": 1,
474 | "size": "0603",
475 | "power_rating": 0.1,
476 | "cplid": "CPL-RES-0603-56.2K-0.1W"
477 | },
478 | {
479 | "type": "resistor",
480 | "resistance": 68100,
481 | "tolerance": 1,
482 | "size": "0603",
483 | "power_rating": 0.1,
484 | "cplid": "CPL-RES-0603-68.1K-0.1W"
485 | },
486 | {
487 | "type": "resistor",
488 | "resistance": 82500,
489 | "tolerance": 1,
490 | "size": "0603",
491 | "power_rating": 0.1,
492 | "cplid": "CPL-RES-0603-82.5K-0.1W"
493 | },
494 | {
495 | "type": "resistor",
496 | "resistance": 100000,
497 | "tolerance": 1,
498 | "size": "0402",
499 | "power_rating": 0.063,
500 | "cplid": "CPL-RES-0402-100K-0.063W"
501 | },
502 | {
503 | "type": "resistor",
504 | "resistance": 100000,
505 | "tolerance": 1,
506 | "size": "0603",
507 | "power_rating": 0.1,
508 | "cplid": "CPL-RES-0603-100K-0.1W"
509 | },
510 | {
511 | "type": "resistor",
512 | "resistance": 100000,
513 | "tolerance": 1,
514 | "size": "0805",
515 | "power_rating": 0.125,
516 | "cplid": "CPL-RES-0805-100K-0.125W"
517 | },
518 | {
519 | "type": "resistor",
520 | "resistance": 100000,
521 | "tolerance": 1,
522 | "size": "1206",
523 | "power_rating": 0.25,
524 | "cplid": "CPL-RES-1206-100K-0.25W"
525 | },
526 | {
527 | "type": "resistor",
528 | "resistance": 120000,
529 | "tolerance": 1,
530 | "size": "0603",
531 | "power_rating": 0.1,
532 | "cplid": "CPL-RES-0603-120K-0.1W"
533 | },
534 | {
535 | "type": "resistor",
536 | "resistance": 150000,
537 | "tolerance": 1,
538 | "size": "0603",
539 | "power_rating": 0.1,
540 | "cplid": "CPL-RES-0603-150K-0.1W"
541 | },
542 | {
543 | "type": "resistor",
544 | "resistance": 220000,
545 | "tolerance": 1,
546 | "size": "0603",
547 | "power_rating": 0.1,
548 | "cplid": "CPL-RES-0603-220K-0.1W"
549 | },
550 | {
551 | "type": "resistor",
552 | "resistance": 332000,
553 | "tolerance": 1,
554 | "size": "0603",
555 | "power_rating": 0.1,
556 | "cplid": "CPL-RES-0603-332K-0.1W"
557 | },
558 | {
559 | "type": "resistor",
560 | "resistance": 470000,
561 | "tolerance": 1,
562 | "size": "0603",
563 | "power_rating": 0.1,
564 | "cplid": "CPL-RES-0603-470K-0.1W"
565 | },
566 | {
567 | "type": "resistor",
568 | "resistance": 562000,
569 | "tolerance": 1,
570 | "size": "0603",
571 | "power_rating": 0.1,
572 | "cplid": "CPL-RES-0603-562K-0.1W"
573 | },
574 | {
575 | "type": "resistor",
576 | "resistance": 681000,
577 | "tolerance": 1,
578 | "size": "0603",
579 | "power_rating": 0.1,
580 | "cplid": "CPL-RES-0603-681K-0.1W"
581 | },
582 | {
583 | "type": "resistor",
584 | "resistance": 825000,
585 | "tolerance": 1,
586 | "size": "0603",
587 | "power_rating": 0.1,
588 | "cplid": "CPL-RES-0603-825K-0.1W"
589 | },
590 | {
591 | "type": "resistor",
592 | "resistance": 1000000,
593 | "tolerance": 1,
594 | "size": "0603",
595 | "power_rating": 0.1,
596 | "cplid": "CPL-RES-0603-1M-0.1W"
597 | },
598 | {
599 | "type": "resistor",
600 | "resistance": 0.05,
601 | "tolerance": 1,
602 | "size": "1206",
603 | "power_rating": 1,
604 | "cplid": "CPL-RES-1206-0.05-1W"
605 | }
606 | ]
--------------------------------------------------------------------------------
/lib/flatten.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * arr-flatten
3 | *
4 | * Copyright (c) 2014-2017, Jon Schlinkert.
5 | * Released under the MIT License.
6 | */
7 |
8 | 'use strict';
9 |
10 | module.exports = function (arr) {
11 | return flat(arr, []);
12 | };
13 |
14 | function flat(arr, res) {
15 | var i = 0,
16 | cur;
17 | var len = arr.length;
18 | for (; i < len; i++) {
19 | cur = arr[i];
20 | Array.isArray(cur) ? flat(cur, res) : res.push(cur);
21 | }
22 | return res;
23 | }
--------------------------------------------------------------------------------
/lib/grammar.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
4 |
5 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6 |
7 | // Generated automatically by nearley, version 2.15.1
8 | // http://github.com/Hardmath123/nearley
9 | (function () {
10 | function id(x) {
11 | return x[0];
12 | }
13 |
14 | var flatten = require('./flatten');
15 |
16 | var filter = function filter(d) {
17 | return d.filter(function (t) {
18 | return t !== null;
19 | });
20 | };
21 |
22 | var assignAll = function assignAll(objs) {
23 | return objs.reduce(function (prev, obj) {
24 | return _extends(prev, obj);
25 | });
26 | };
27 |
28 | var nuller = function nuller() {
29 | return null;
30 | };
31 |
32 | var toImperial = {
33 | '0402': '01005',
34 | '0603': '0201',
35 | '1005': '0402',
36 | '1608': '0603',
37 | '2012': '0805',
38 | '2520': '1008',
39 | '3216': '1206',
40 | '3225': '1210',
41 | '4516': '1806',
42 | '4532': '1812',
43 | '5025': '2010',
44 | '6332': '2512'
45 | };
46 |
47 | function type(t) {
48 | return function (d) {
49 | return [{ type: t }].concat(d);
50 | };
51 | }
52 |
53 | function voltage_rating(d, i, reject) {
54 | var _d = _slicedToArray(d, 3),
55 | integral = _d[0],
56 | _d$ = _slicedToArray(_d[2], 2),
57 | v = _d$[0],
58 | fractional = _d$[1];
59 |
60 | if (fractional) {
61 | if (/\./.test(integral.toString())) {
62 | return reject;
63 | }
64 | var quantity = integral + '.' + fractional;
65 | } else {
66 | var quantity = integral;
67 | }
68 | return { voltage_rating: parseFloat(quantity) };
69 | }
70 |
71 | function capacitance(d, i, reject) {
72 | var _d2 = _slicedToArray(d, 3),
73 | integral = _d2[0],
74 | _d2$ = _slicedToArray(_d2[2], 2),
75 | metricPrefix = _d2$[0],
76 | fractional = _d2$[1];
77 |
78 | if (fractional) {
79 | if (/\./.test(integral) || metricPrefix === "") {
80 | return reject;
81 | }
82 | var quantity = integral + '.' + fractional;
83 | } else {
84 | if (/1005|201|402|603|805|1206/.test(integral.toString())) {
85 | return reject;
86 | }
87 | var quantity = integral;
88 | }
89 | return { capacitance: parseFloat('' + quantity + metricPrefix) };
90 | }
91 |
92 | function resistance(d, i, reject) {
93 | var _d3 = _slicedToArray(d, 3),
94 | integral = _d3[0],
95 | _d3$ = _slicedToArray(_d3[2], 3),
96 | metricPrefix = _d3$[0],
97 | fractional = _d3$[1],
98 | ohm = _d3$[2];
99 |
100 | if (fractional) {
101 | if (/\./.test(integral.toString())) {
102 | return reject;
103 | }
104 | var quantity = integral + '.' + fractional;
105 | } else {
106 | if (/1005|201|402|603|805|1206/.test(integral.toString())) {
107 | return reject;
108 | }
109 | var quantity = integral;
110 | }
111 | return { resistance: parseFloat('' + quantity + metricPrefix) };
112 | }
113 | var grammar = {
114 | Lexer: undefined,
115 | ParserRules: [{ "name": "unsigned_int$ebnf$1", "symbols": [/[0-9]/] }, { "name": "unsigned_int$ebnf$1", "symbols": ["unsigned_int$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {
116 | return d[0].concat([d[1]]);
117 | } }, { "name": "unsigned_int", "symbols": ["unsigned_int$ebnf$1"], "postprocess": function postprocess(d) {
118 | return parseInt(d[0].join(""));
119 | }
120 | }, { "name": "int$ebnf$1$subexpression$1", "symbols": [{ "literal": "-" }] }, { "name": "int$ebnf$1$subexpression$1", "symbols": [{ "literal": "+" }] }, { "name": "int$ebnf$1", "symbols": ["int$ebnf$1$subexpression$1"], "postprocess": id }, { "name": "int$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
121 | return null;
122 | } }, { "name": "int$ebnf$2", "symbols": [/[0-9]/] }, { "name": "int$ebnf$2", "symbols": ["int$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {
123 | return d[0].concat([d[1]]);
124 | } }, { "name": "int", "symbols": ["int$ebnf$1", "int$ebnf$2"], "postprocess": function postprocess(d) {
125 | if (d[0]) {
126 | return parseInt(d[0][0] + d[1].join(""));
127 | } else {
128 | return parseInt(d[1].join(""));
129 | }
130 | }
131 | }, { "name": "unsigned_decimal$ebnf$1", "symbols": [/[0-9]/] }, { "name": "unsigned_decimal$ebnf$1", "symbols": ["unsigned_decimal$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {
132 | return d[0].concat([d[1]]);
133 | } }, { "name": "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", "symbols": [/[0-9]/] }, { "name": "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", "symbols": ["unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {
134 | return d[0].concat([d[1]]);
135 | } }, { "name": "unsigned_decimal$ebnf$2$subexpression$1", "symbols": [{ "literal": "." }, "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1"] }, { "name": "unsigned_decimal$ebnf$2", "symbols": ["unsigned_decimal$ebnf$2$subexpression$1"], "postprocess": id }, { "name": "unsigned_decimal$ebnf$2", "symbols": [], "postprocess": function postprocess(d) {
136 | return null;
137 | } }, { "name": "unsigned_decimal", "symbols": ["unsigned_decimal$ebnf$1", "unsigned_decimal$ebnf$2"], "postprocess": function postprocess(d) {
138 | return parseFloat(d[0].join("") + (d[1] ? "." + d[1][1].join("") : ""));
139 | }
140 | }, { "name": "decimal$ebnf$1", "symbols": [{ "literal": "-" }], "postprocess": id }, { "name": "decimal$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
141 | return null;
142 | } }, { "name": "decimal$ebnf$2", "symbols": [/[0-9]/] }, { "name": "decimal$ebnf$2", "symbols": ["decimal$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {
143 | return d[0].concat([d[1]]);
144 | } }, { "name": "decimal$ebnf$3$subexpression$1$ebnf$1", "symbols": [/[0-9]/] }, { "name": "decimal$ebnf$3$subexpression$1$ebnf$1", "symbols": ["decimal$ebnf$3$subexpression$1$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {
145 | return d[0].concat([d[1]]);
146 | } }, { "name": "decimal$ebnf$3$subexpression$1", "symbols": [{ "literal": "." }, "decimal$ebnf$3$subexpression$1$ebnf$1"] }, { "name": "decimal$ebnf$3", "symbols": ["decimal$ebnf$3$subexpression$1"], "postprocess": id }, { "name": "decimal$ebnf$3", "symbols": [], "postprocess": function postprocess(d) {
147 | return null;
148 | } }, { "name": "decimal", "symbols": ["decimal$ebnf$1", "decimal$ebnf$2", "decimal$ebnf$3"], "postprocess": function postprocess(d) {
149 | return parseFloat((d[0] || "") + d[1].join("") + (d[2] ? "." + d[2][1].join("") : ""));
150 | }
151 | }, { "name": "percentage", "symbols": ["decimal", { "literal": "%" }], "postprocess": function postprocess(d) {
152 | return d[0] / 100;
153 | }
154 | }, { "name": "jsonfloat$ebnf$1", "symbols": [{ "literal": "-" }], "postprocess": id }, { "name": "jsonfloat$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
155 | return null;
156 | } }, { "name": "jsonfloat$ebnf$2", "symbols": [/[0-9]/] }, { "name": "jsonfloat$ebnf$2", "symbols": ["jsonfloat$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {
157 | return d[0].concat([d[1]]);
158 | } }, { "name": "jsonfloat$ebnf$3$subexpression$1$ebnf$1", "symbols": [/[0-9]/] }, { "name": "jsonfloat$ebnf$3$subexpression$1$ebnf$1", "symbols": ["jsonfloat$ebnf$3$subexpression$1$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {
159 | return d[0].concat([d[1]]);
160 | } }, { "name": "jsonfloat$ebnf$3$subexpression$1", "symbols": [{ "literal": "." }, "jsonfloat$ebnf$3$subexpression$1$ebnf$1"] }, { "name": "jsonfloat$ebnf$3", "symbols": ["jsonfloat$ebnf$3$subexpression$1"], "postprocess": id }, { "name": "jsonfloat$ebnf$3", "symbols": [], "postprocess": function postprocess(d) {
161 | return null;
162 | } }, { "name": "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "symbols": [/[+-]/], "postprocess": id }, { "name": "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
163 | return null;
164 | } }, { "name": "jsonfloat$ebnf$4$subexpression$1$ebnf$2", "symbols": [/[0-9]/] }, { "name": "jsonfloat$ebnf$4$subexpression$1$ebnf$2", "symbols": ["jsonfloat$ebnf$4$subexpression$1$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {
165 | return d[0].concat([d[1]]);
166 | } }, { "name": "jsonfloat$ebnf$4$subexpression$1", "symbols": [/[eE]/, "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "jsonfloat$ebnf$4$subexpression$1$ebnf$2"] }, { "name": "jsonfloat$ebnf$4", "symbols": ["jsonfloat$ebnf$4$subexpression$1"], "postprocess": id }, { "name": "jsonfloat$ebnf$4", "symbols": [], "postprocess": function postprocess(d) {
167 | return null;
168 | } }, { "name": "jsonfloat", "symbols": ["jsonfloat$ebnf$1", "jsonfloat$ebnf$2", "jsonfloat$ebnf$3", "jsonfloat$ebnf$4"], "postprocess": function postprocess(d) {
169 | return parseFloat((d[0] || "") + d[1].join("") + (d[2] ? "." + d[2][1].join("") : "") + (d[3] ? "e" + (d[3][1] || "+") + d[3][2].join("") : ""));
170 | }
171 | }, { "name": "_$ebnf$1", "symbols": [] }, { "name": "_$ebnf$1", "symbols": ["_$ebnf$1", /[\s]/], "postprocess": function arrpush(d) {
172 | return d[0].concat([d[1]]);
173 | } }, { "name": "_", "symbols": ["_$ebnf$1"], "postprocess": function postprocess() {
174 | return null;
175 | } }, { "name": "__$ebnf$1", "symbols": [/[\s]/] }, { "name": "__$ebnf$1", "symbols": ["__$ebnf$1", /[\s]/], "postprocess": function arrpush(d) {
176 | return d[0].concat([d[1]]);
177 | } }, { "name": "__", "symbols": ["__$ebnf$1"], "postprocess": function postprocess() {
178 | return null;
179 | } }, { "name": "A", "symbols": [{ "literal": "A" }] }, { "name": "A", "symbols": [{ "literal": "a" }] }, { "name": "B", "symbols": [{ "literal": "B" }] }, { "name": "B", "symbols": [{ "literal": "b" }] }, { "name": "C", "symbols": [{ "literal": "C" }] }, { "name": "C", "symbols": [{ "literal": "c" }] }, { "name": "D", "symbols": [{ "literal": "D" }] }, { "name": "D", "symbols": [{ "literal": "d" }] }, { "name": "E", "symbols": [{ "literal": "E" }] }, { "name": "E", "symbols": [{ "literal": "e" }] }, { "name": "F", "symbols": [{ "literal": "F" }] }, { "name": "F", "symbols": [{ "literal": "f" }] }, { "name": "G", "symbols": [{ "literal": "G" }] }, { "name": "G", "symbols": [{ "literal": "g" }] }, { "name": "H", "symbols": [{ "literal": "H" }] }, { "name": "H", "symbols": [{ "literal": "h" }] }, { "name": "I", "symbols": [{ "literal": "I" }] }, { "name": "I", "symbols": [{ "literal": "i" }] }, { "name": "J", "symbols": [{ "literal": "J" }] }, { "name": "J", "symbols": [{ "literal": "j" }] }, { "name": "K", "symbols": [{ "literal": "K" }] }, { "name": "K", "symbols": [{ "literal": "k" }] }, { "name": "L", "symbols": [{ "literal": "L" }] }, { "name": "L", "symbols": [{ "literal": "l" }] }, { "name": "M", "symbols": [{ "literal": "M" }] }, { "name": "M", "symbols": [{ "literal": "m" }] }, { "name": "N", "symbols": [{ "literal": "N" }] }, { "name": "N", "symbols": [{ "literal": "n" }] }, { "name": "O", "symbols": [{ "literal": "O" }] }, { "name": "O", "symbols": [{ "literal": "o" }] }, { "name": "P", "symbols": [{ "literal": "P" }] }, { "name": "P", "symbols": [{ "literal": "p" }] }, { "name": "Q", "symbols": [{ "literal": "Q" }] }, { "name": "Q", "symbols": [{ "literal": "q" }] }, { "name": "R", "symbols": [{ "literal": "R" }] }, { "name": "R", "symbols": [{ "literal": "r" }] }, { "name": "S", "symbols": [{ "literal": "S" }] }, { "name": "S", "symbols": [{ "literal": "s" }] }, { "name": "T", "symbols": [{ "literal": "T" }] }, { "name": "T", "symbols": [{ "literal": "t" }] }, { "name": "U", "symbols": [{ "literal": "U" }] }, { "name": "U", "symbols": [{ "literal": "u" }] }, { "name": "V", "symbols": [{ "literal": "V" }] }, { "name": "V", "symbols": [{ "literal": "v" }] }, { "name": "W", "symbols": [{ "literal": "W" }] }, { "name": "W", "symbols": [{ "literal": "w" }] }, { "name": "X", "symbols": [{ "literal": "X" }] }, { "name": "X", "symbols": [{ "literal": "x" }] }, { "name": "Y", "symbols": [{ "literal": "Y" }] }, { "name": "Y", "symbols": [{ "literal": "y" }] }, { "name": "Z", "symbols": [{ "literal": "Z" }] }, { "name": "Z", "symbols": [{ "literal": "z" }] }, { "name": "exa", "symbols": [{ "literal": "E" }] }, { "name": "exa", "symbols": ["E", "X", "A"] }, { "name": "peta", "symbols": [{ "literal": "P" }] }, { "name": "peta", "symbols": ["P", "E", "T", "A"] }, { "name": "tera", "symbols": [{ "literal": "T" }] }, { "name": "tera", "symbols": ["T", "E", "R", "A"] }, { "name": "giga", "symbols": [{ "literal": "G" }] }, { "name": "giga", "symbols": ["G", "I", "G"] }, { "name": "giga", "symbols": ["G", "I", "G", "A"] }, { "name": "mega", "symbols": [{ "literal": "M" }] }, { "name": "mega", "symbols": ["M", "E", "G"] }, { "name": "mega", "symbols": ["M", "E", "G", "A"] }, { "name": "kilo", "symbols": ["K"] }, { "name": "kilo", "symbols": ["K", "I", "L", "O"] }, { "name": "hecto", "symbols": [{ "literal": "h" }] }, { "name": "hecto", "symbols": ["H", "E", "C", "T", "O"] }, { "name": "deci", "symbols": [{ "literal": "d" }] }, { "name": "deci", "symbols": ["D", "E", "C", "I"] }, { "name": "centi", "symbols": [{ "literal": "c" }] }, { "name": "centi", "symbols": ["C", "E", "N", "T", "I"] }, { "name": "milli", "symbols": [{ "literal": "m" }] }, { "name": "milli", "symbols": ["M", "I", "L", "L", "I"] }, { "name": "micro", "symbols": ["U"] }, { "name": "micro", "symbols": [/[\u03BC]/] }, { "name": "micro", "symbols": [/[\u00B5]/] }, { "name": "micro", "symbols": [/[\uD835]/, /[\uDECD]/] }, { "name": "micro", "symbols": [/[\uD835]/, /[\uDF07]/] }, { "name": "micro", "symbols": [/[\uD835]/, /[\uDF41]/] }, { "name": "micro", "symbols": [/[\uD835]/, /[\uDF7B]/] }, { "name": "micro", "symbols": [/[\uD835]/, /[\uDFB5]/] }, { "name": "micro", "symbols": ["M", "I", "C", "R", "O"] }, { "name": "nano", "symbols": ["N"] }, { "name": "nano", "symbols": ["N", "A", "N"] }, { "name": "nano", "symbols": ["N", "A", "N", "O"] }, { "name": "pico", "symbols": ["P"] }, { "name": "pico", "symbols": ["P", "I", "C", "O"] }, { "name": "femto", "symbols": [{ "literal": "f" }] }, { "name": "femto", "symbols": ["F", "E", "M", "T", "O"] }, { "name": "atto", "symbols": [{ "literal": "a" }] }, { "name": "atto", "symbols": ["A", "T", "T", "O"] }, { "name": "packageSize", "symbols": ["_packageSize"], "postprocess": function postprocess(d) {
180 | return { size: filter(flatten(d))[0] };
181 | } }, { "name": "_packageSize", "symbols": ["_imperialSize"] }, { "name": "_packageSize", "symbols": ["_metricSize"] }, { "name": "_imperialSize$string$1", "symbols": [{ "literal": "0" }, { "literal": "1" }, { "literal": "0" }, { "literal": "0" }, { "literal": "5" }], "postprocess": function joiner(d) {
182 | return d.join('');
183 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$1"] }, { "name": "_imperialSize$string$2", "symbols": [{ "literal": "0" }, { "literal": "2" }, { "literal": "0" }, { "literal": "1" }], "postprocess": function joiner(d) {
184 | return d.join('');
185 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$2"] }, { "name": "_imperialSize$string$3", "symbols": [{ "literal": "0" }, { "literal": "4" }, { "literal": "0" }, { "literal": "2" }], "postprocess": function joiner(d) {
186 | return d.join('');
187 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$3"] }, { "name": "_imperialSize$string$4", "symbols": [{ "literal": "0" }, { "literal": "6" }, { "literal": "0" }, { "literal": "3" }], "postprocess": function joiner(d) {
188 | return d.join('');
189 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$4"] }, { "name": "_imperialSize$string$5", "symbols": [{ "literal": "0" }, { "literal": "8" }, { "literal": "0" }, { "literal": "5" }], "postprocess": function joiner(d) {
190 | return d.join('');
191 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$5"] }, { "name": "_imperialSize$string$6", "symbols": [{ "literal": "1" }, { "literal": "0" }, { "literal": "0" }, { "literal": "8" }], "postprocess": function joiner(d) {
192 | return d.join('');
193 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$6"] }, { "name": "_imperialSize$string$7", "symbols": [{ "literal": "1" }, { "literal": "2" }, { "literal": "0" }, { "literal": "6" }], "postprocess": function joiner(d) {
194 | return d.join('');
195 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$7"] }, { "name": "_imperialSize$string$8", "symbols": [{ "literal": "1" }, { "literal": "2" }, { "literal": "1" }, { "literal": "0" }], "postprocess": function joiner(d) {
196 | return d.join('');
197 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$8"] }, { "name": "_imperialSize$string$9", "symbols": [{ "literal": "1" }, { "literal": "8" }, { "literal": "0" }, { "literal": "6" }], "postprocess": function joiner(d) {
198 | return d.join('');
199 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$9"] }, { "name": "_imperialSize$string$10", "symbols": [{ "literal": "2" }, { "literal": "0" }, { "literal": "1" }, { "literal": "0" }], "postprocess": function joiner(d) {
200 | return d.join('');
201 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$10"] }, { "name": "_imperialSize$string$11", "symbols": [{ "literal": "2" }, { "literal": "5" }, { "literal": "1" }, { "literal": "2" }], "postprocess": function joiner(d) {
202 | return d.join('');
203 | } }, { "name": "_imperialSize", "symbols": ["_imperialSize$string$11"] }, { "name": "_metricSize$ebnf$1", "symbols": [] }, { "name": "_metricSize$ebnf$1", "symbols": ["_metricSize$ebnf$1", /[\s]/], "postprocess": function arrpush(d) {
204 | return d[0].concat([d[1]]);
205 | } }, { "name": "_metricSize", "symbols": ["__metricSize", "_metricSize$ebnf$1", "M", "E", "T", "R", "I", "C"], "postprocess": function postprocess(d) {
206 | return toImperial[d[0]];
207 | } }, { "name": "_metricSize$ebnf$2", "symbols": [] }, { "name": "_metricSize$ebnf$2", "symbols": ["_metricSize$ebnf$2", /[\s]/], "postprocess": function arrpush(d) {
208 | return d[0].concat([d[1]]);
209 | } }, { "name": "_metricSize", "symbols": ["M", "E", "T", "R", "I", "C", "_metricSize$ebnf$2", "__metricSize"], "postprocess": function postprocess(d) {
210 | return toImperial[d[7]];
211 | } }, { "name": "_metricSize", "symbols": ["unambigiousMetricSize"], "postprocess": function postprocess(d) {
212 | return toImperial[d[0]];
213 | } }, { "name": "unambigiousMetricSize$string$1", "symbols": [{ "literal": "1" }, { "literal": "0" }, { "literal": "0" }, { "literal": "5" }], "postprocess": function joiner(d) {
214 | return d.join('');
215 | } }, { "name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$1"] }, { "name": "unambigiousMetricSize$string$2", "symbols": [{ "literal": "1" }, { "literal": "6" }, { "literal": "0" }, { "literal": "8" }], "postprocess": function joiner(d) {
216 | return d.join('');
217 | } }, { "name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$2"] }, { "name": "unambigiousMetricSize$string$3", "symbols": [{ "literal": "2" }, { "literal": "0" }, { "literal": "1" }, { "literal": "2" }], "postprocess": function joiner(d) {
218 | return d.join('');
219 | } }, { "name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$3"] }, { "name": "unambigiousMetricSize$string$4", "symbols": [{ "literal": "2" }, { "literal": "5" }, { "literal": "2" }, { "literal": "0" }], "postprocess": function joiner(d) {
220 | return d.join('');
221 | } }, { "name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$4"] }, { "name": "unambigiousMetricSize$string$5", "symbols": [{ "literal": "3" }, { "literal": "2" }, { "literal": "1" }, { "literal": "6" }], "postprocess": function joiner(d) {
222 | return d.join('');
223 | } }, { "name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$5"] }, { "name": "unambigiousMetricSize$string$6", "symbols": [{ "literal": "3" }, { "literal": "2" }, { "literal": "2" }, { "literal": "5" }], "postprocess": function joiner(d) {
224 | return d.join('');
225 | } }, { "name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$6"] }, { "name": "unambigiousMetricSize$string$7", "symbols": [{ "literal": "4" }, { "literal": "5" }, { "literal": "1" }, { "literal": "6" }], "postprocess": function joiner(d) {
226 | return d.join('');
227 | } }, { "name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$7"] }, { "name": "unambigiousMetricSize$string$8", "symbols": [{ "literal": "5" }, { "literal": "0" }, { "literal": "2" }, { "literal": "5" }], "postprocess": function joiner(d) {
228 | return d.join('');
229 | } }, { "name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$8"] }, { "name": "unambigiousMetricSize$string$9", "symbols": [{ "literal": "6" }, { "literal": "3" }, { "literal": "3" }, { "literal": "2" }], "postprocess": function joiner(d) {
230 | return d.join('');
231 | } }, { "name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$9"] }, { "name": "__metricSize", "symbols": ["unambigiousMetricSize"] }, { "name": "__metricSize$string$1", "symbols": [{ "literal": "0" }, { "literal": "4" }, { "literal": "0" }, { "literal": "2" }], "postprocess": function joiner(d) {
232 | return d.join('');
233 | } }, { "name": "__metricSize", "symbols": ["__metricSize$string$1"] }, { "name": "__metricSize$string$2", "symbols": [{ "literal": "0" }, { "literal": "6" }, { "literal": "0" }, { "literal": "3" }], "postprocess": function joiner(d) {
234 | return d.join('');
235 | } }, { "name": "__metricSize", "symbols": ["__metricSize$string$2"] }, { "name": "M", "symbols": [{ "literal": "M" }] }, { "name": "M", "symbols": [{ "literal": "m" }] }, { "name": "E", "symbols": [{ "literal": "E" }] }, { "name": "E", "symbols": [{ "literal": "e" }] }, { "name": "T", "symbols": [{ "literal": "T" }] }, { "name": "T", "symbols": [{ "literal": "t" }] }, { "name": "R", "symbols": [{ "literal": "R" }] }, { "name": "R", "symbols": [{ "literal": "r" }] }, { "name": "I", "symbols": [{ "literal": "I" }] }, { "name": "I", "symbols": [{ "literal": "i" }] }, { "name": "C", "symbols": [{ "literal": "C" }] }, { "name": "C", "symbols": [{ "literal": "c" }] }, { "name": "main", "symbols": ["component"], "postprocess": function postprocess(d) {
236 | return assignAll(filter(flatten(d)));
237 | } }, { "name": "component", "symbols": ["capacitor"], "postprocess": type('capacitor') }, { "name": "component", "symbols": ["resistor"], "postprocess": type('resistor') }, { "name": "component", "symbols": ["led"], "postprocess": type('led') }, { "name": "capacitor$ebnf$1", "symbols": ["packageSize"], "postprocess": id }, { "name": "capacitor$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
238 | return null;
239 | } }, { "name": "capacitor", "symbols": ["cSpecs", "capacitance", "cSpecs", "capacitor$ebnf$1", "cSpecs"] }, { "name": "capacitor$ebnf$2", "symbols": ["packageSize"], "postprocess": id }, { "name": "capacitor$ebnf$2", "symbols": [], "postprocess": function postprocess(d) {
240 | return null;
241 | } }, { "name": "capacitor", "symbols": ["cSpecs", "capacitor$ebnf$2", "cSpecs", "capacitance", "cSpecs"] }, { "name": "capacitor$ebnf$3", "symbols": ["packageSize"], "postprocess": id }, { "name": "capacitor$ebnf$3", "symbols": [], "postprocess": function postprocess(d) {
242 | return null;
243 | } }, { "name": "capacitor$ebnf$4$subexpression$1", "symbols": ["capacitanceNoFarad"] }, { "name": "capacitor$ebnf$4$subexpression$1", "symbols": ["capacitance"] }, { "name": "capacitor$ebnf$4", "symbols": ["capacitor$ebnf$4$subexpression$1"], "postprocess": id }, { "name": "capacitor$ebnf$4", "symbols": [], "postprocess": function postprocess(d) {
244 | return null;
245 | } }, { "name": "capacitor", "symbols": ["cap", "cSpecs", "capacitor$ebnf$3", "cSpecs", "capacitor$ebnf$4", "cSpecs"] }, { "name": "capacitor$ebnf$5$subexpression$1", "symbols": ["capacitanceNoFarad"] }, { "name": "capacitor$ebnf$5$subexpression$1", "symbols": ["capacitance"] }, { "name": "capacitor$ebnf$5", "symbols": ["capacitor$ebnf$5$subexpression$1"], "postprocess": id }, { "name": "capacitor$ebnf$5", "symbols": [], "postprocess": function postprocess(d) {
246 | return null;
247 | } }, { "name": "capacitor$ebnf$6", "symbols": ["packageSize"], "postprocess": id }, { "name": "capacitor$ebnf$6", "symbols": [], "postprocess": function postprocess(d) {
248 | return null;
249 | } }, { "name": "capacitor", "symbols": ["cap", "cSpecs", "capacitor$ebnf$5", "cSpecs", "capacitor$ebnf$6", "cSpecs"] }, { "name": "cap$ebnf$1", "symbols": ["A"], "postprocess": id }, { "name": "cap$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
250 | return null;
251 | } }, { "name": "cap$ebnf$2", "symbols": ["P"], "postprocess": id }, { "name": "cap$ebnf$2", "symbols": [], "postprocess": function postprocess(d) {
252 | return null;
253 | } }, { "name": "cap$ebnf$3", "symbols": ["A"], "postprocess": id }, { "name": "cap$ebnf$3", "symbols": [], "postprocess": function postprocess(d) {
254 | return null;
255 | } }, { "name": "cap$ebnf$4", "symbols": ["C"], "postprocess": id }, { "name": "cap$ebnf$4", "symbols": [], "postprocess": function postprocess(d) {
256 | return null;
257 | } }, { "name": "cap$ebnf$5", "symbols": ["I"], "postprocess": id }, { "name": "cap$ebnf$5", "symbols": [], "postprocess": function postprocess(d) {
258 | return null;
259 | } }, { "name": "cap$ebnf$6", "symbols": ["T"], "postprocess": id }, { "name": "cap$ebnf$6", "symbols": [], "postprocess": function postprocess(d) {
260 | return null;
261 | } }, { "name": "cap$ebnf$7", "symbols": ["O"], "postprocess": id }, { "name": "cap$ebnf$7", "symbols": [], "postprocess": function postprocess(d) {
262 | return null;
263 | } }, { "name": "cap$ebnf$8", "symbols": ["R"], "postprocess": id }, { "name": "cap$ebnf$8", "symbols": [], "postprocess": function postprocess(d) {
264 | return null;
265 | } }, { "name": "cap", "symbols": ["C", "cap$ebnf$1", "cap$ebnf$2", "cap$ebnf$3", "cap$ebnf$4", "cap$ebnf$5", "cap$ebnf$6", "cap$ebnf$7", "cap$ebnf$8"], "postprocess": nuller }, { "name": "cSpecs$ebnf$1", "symbols": [] }, { "name": "cSpecs$ebnf$1$subexpression$1", "symbols": ["_", "cSpec", "_"] }, { "name": "cSpecs$ebnf$1", "symbols": ["cSpecs$ebnf$1", "cSpecs$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {
266 | return d[0].concat([d[1]]);
267 | } }, { "name": "cSpecs", "symbols": ["cSpecs$ebnf$1"] }, { "name": "cSpecs", "symbols": ["__"] }, { "name": "cSpec", "symbols": ["tolerance"] }, { "name": "cSpec", "symbols": ["characteristic"] }, { "name": "cSpec", "symbols": ["voltage_rating"] }, { "name": "voltage_rating", "symbols": ["decimal", "_", "voltageRest"], "postprocess": voltage_rating }, { "name": "voltageRest$ebnf$1", "symbols": ["int"], "postprocess": id }, { "name": "voltageRest$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
268 | return null;
269 | } }, { "name": "voltageRest", "symbols": ["V", "voltageRest$ebnf$1"] }, { "name": "characteristic", "symbols": ["characteristic_"], "postprocess": function postprocess(d) {
270 | return { characteristic: d[0][0] };
271 | } }, { "name": "characteristic_", "symbols": ["class1"] }, { "name": "characteristic_", "symbols": ["class2"] }, { "name": "class1$macrocall$2", "symbols": ["C", { "literal": "0" }, "G"] }, { "name": "class1$macrocall$3", "symbols": ["N", "P", { "literal": "0" }] }, { "name": "class1$macrocall$1", "symbols": ["class1$macrocall$2"] }, { "name": "class1$macrocall$1", "symbols": ["class1$macrocall$3"] }, { "name": "class1$macrocall$1", "symbols": ["class1$macrocall$2", { "literal": "/" }, "class1$macrocall$3"] }, { "name": "class1$macrocall$1", "symbols": ["class1$macrocall$3", { "literal": "/" }, "class1$macrocall$2"] }, { "name": "class1", "symbols": ["class1$macrocall$1"], "postprocess": function postprocess() {
272 | return 'C0G';
273 | } }, { "name": "class1$macrocall$5", "symbols": ["C", "O", "G"] }, { "name": "class1$macrocall$6", "symbols": ["N", "P", "O"] }, { "name": "class1$macrocall$4", "symbols": ["class1$macrocall$5"] }, { "name": "class1$macrocall$4", "symbols": ["class1$macrocall$6"] }, { "name": "class1$macrocall$4", "symbols": ["class1$macrocall$5", { "literal": "/" }, "class1$macrocall$6"] }, { "name": "class1$macrocall$4", "symbols": ["class1$macrocall$6", { "literal": "/" }, "class1$macrocall$5"] }, { "name": "class1", "symbols": ["class1$macrocall$4"], "postprocess": function postprocess() {
274 | return 'C0G';
275 | } }, { "name": "class1$macrocall$8$string$1", "symbols": [{ "literal": "1" }, { "literal": "0" }, { "literal": "0" }], "postprocess": function joiner(d) {
276 | return d.join('');
277 | } }, { "name": "class1$macrocall$8", "symbols": ["P", "class1$macrocall$8$string$1"] }, { "name": "class1$macrocall$9", "symbols": ["M", { "literal": "7" }, "G"] }, { "name": "class1$macrocall$7", "symbols": ["class1$macrocall$8"] }, { "name": "class1$macrocall$7", "symbols": ["class1$macrocall$9"] }, { "name": "class1$macrocall$7", "symbols": ["class1$macrocall$8", { "literal": "/" }, "class1$macrocall$9"] }, { "name": "class1$macrocall$7", "symbols": ["class1$macrocall$9", { "literal": "/" }, "class1$macrocall$8"] }, { "name": "class1", "symbols": ["class1$macrocall$7"], "postprocess": function postprocess() {
278 | return 'M7G';
279 | } }, { "name": "class1$macrocall$11$string$1", "symbols": [{ "literal": "3" }, { "literal": "3" }], "postprocess": function joiner(d) {
280 | return d.join('');
281 | } }, { "name": "class1$macrocall$11", "symbols": ["N", "class1$macrocall$11$string$1"] }, { "name": "class1$macrocall$12", "symbols": ["H", { "literal": "2" }, "G"] }, { "name": "class1$macrocall$10", "symbols": ["class1$macrocall$11"] }, { "name": "class1$macrocall$10", "symbols": ["class1$macrocall$12"] }, { "name": "class1$macrocall$10", "symbols": ["class1$macrocall$11", { "literal": "/" }, "class1$macrocall$12"] }, { "name": "class1$macrocall$10", "symbols": ["class1$macrocall$12", { "literal": "/" }, "class1$macrocall$11"] }, { "name": "class1", "symbols": ["class1$macrocall$10"], "postprocess": function postprocess() {
282 | return 'H2G';
283 | } }, { "name": "class1$macrocall$14$string$1", "symbols": [{ "literal": "7" }, { "literal": "5" }], "postprocess": function joiner(d) {
284 | return d.join('');
285 | } }, { "name": "class1$macrocall$14", "symbols": ["N", "class1$macrocall$14$string$1"] }, { "name": "class1$macrocall$15", "symbols": ["L", { "literal": "2" }, "G"] }, { "name": "class1$macrocall$13", "symbols": ["class1$macrocall$14"] }, { "name": "class1$macrocall$13", "symbols": ["class1$macrocall$15"] }, { "name": "class1$macrocall$13", "symbols": ["class1$macrocall$14", { "literal": "/" }, "class1$macrocall$15"] }, { "name": "class1$macrocall$13", "symbols": ["class1$macrocall$15", { "literal": "/" }, "class1$macrocall$14"] }, { "name": "class1", "symbols": ["class1$macrocall$13"], "postprocess": function postprocess() {
286 | return 'L2G';
287 | } }, { "name": "class1$macrocall$17$string$1", "symbols": [{ "literal": "1" }, { "literal": "5" }, { "literal": "0" }], "postprocess": function joiner(d) {
288 | return d.join('');
289 | } }, { "name": "class1$macrocall$17", "symbols": ["N", "class1$macrocall$17$string$1"] }, { "name": "class1$macrocall$18", "symbols": ["P", { "literal": "2" }, "H"] }, { "name": "class1$macrocall$16", "symbols": ["class1$macrocall$17"] }, { "name": "class1$macrocall$16", "symbols": ["class1$macrocall$18"] }, { "name": "class1$macrocall$16", "symbols": ["class1$macrocall$17", { "literal": "/" }, "class1$macrocall$18"] }, { "name": "class1$macrocall$16", "symbols": ["class1$macrocall$18", { "literal": "/" }, "class1$macrocall$17"] }, { "name": "class1", "symbols": ["class1$macrocall$16"], "postprocess": function postprocess() {
290 | return 'P2H';
291 | } }, { "name": "class1$macrocall$20$string$1", "symbols": [{ "literal": "2" }, { "literal": "2" }, { "literal": "0" }], "postprocess": function joiner(d) {
292 | return d.join('');
293 | } }, { "name": "class1$macrocall$20", "symbols": ["N", "class1$macrocall$20$string$1"] }, { "name": "class1$macrocall$21", "symbols": ["R", { "literal": "2" }, "H"] }, { "name": "class1$macrocall$19", "symbols": ["class1$macrocall$20"] }, { "name": "class1$macrocall$19", "symbols": ["class1$macrocall$21"] }, { "name": "class1$macrocall$19", "symbols": ["class1$macrocall$20", { "literal": "/" }, "class1$macrocall$21"] }, { "name": "class1$macrocall$19", "symbols": ["class1$macrocall$21", { "literal": "/" }, "class1$macrocall$20"] }, { "name": "class1", "symbols": ["class1$macrocall$19"], "postprocess": function postprocess() {
294 | return 'R2H';
295 | } }, { "name": "class1$macrocall$23$string$1", "symbols": [{ "literal": "3" }, { "literal": "3" }, { "literal": "0" }], "postprocess": function joiner(d) {
296 | return d.join('');
297 | } }, { "name": "class1$macrocall$23", "symbols": ["N", "class1$macrocall$23$string$1"] }, { "name": "class1$macrocall$24", "symbols": ["S", { "literal": "2" }, "H"] }, { "name": "class1$macrocall$22", "symbols": ["class1$macrocall$23"] }, { "name": "class1$macrocall$22", "symbols": ["class1$macrocall$24"] }, { "name": "class1$macrocall$22", "symbols": ["class1$macrocall$23", { "literal": "/" }, "class1$macrocall$24"] }, { "name": "class1$macrocall$22", "symbols": ["class1$macrocall$24", { "literal": "/" }, "class1$macrocall$23"] }, { "name": "class1", "symbols": ["class1$macrocall$22"], "postprocess": function postprocess() {
298 | return 'S2H';
299 | } }, { "name": "class1$macrocall$26$string$1", "symbols": [{ "literal": "4" }, { "literal": "7" }, { "literal": "0" }], "postprocess": function joiner(d) {
300 | return d.join('');
301 | } }, { "name": "class1$macrocall$26", "symbols": ["N", "class1$macrocall$26$string$1"] }, { "name": "class1$macrocall$27", "symbols": ["T", { "literal": "2" }, "H"] }, { "name": "class1$macrocall$25", "symbols": ["class1$macrocall$26"] }, { "name": "class1$macrocall$25", "symbols": ["class1$macrocall$27"] }, { "name": "class1$macrocall$25", "symbols": ["class1$macrocall$26", { "literal": "/" }, "class1$macrocall$27"] }, { "name": "class1$macrocall$25", "symbols": ["class1$macrocall$27", { "literal": "/" }, "class1$macrocall$26"] }, { "name": "class1", "symbols": ["class1$macrocall$25"], "postprocess": function postprocess() {
302 | return 'T2H';
303 | } }, { "name": "class1$macrocall$29$string$1", "symbols": [{ "literal": "7" }, { "literal": "5" }, { "literal": "0" }], "postprocess": function joiner(d) {
304 | return d.join('');
305 | } }, { "name": "class1$macrocall$29", "symbols": ["N", "class1$macrocall$29$string$1"] }, { "name": "class1$macrocall$30", "symbols": ["U", { "literal": "2" }, "J"] }, { "name": "class1$macrocall$28", "symbols": ["class1$macrocall$29"] }, { "name": "class1$macrocall$28", "symbols": ["class1$macrocall$30"] }, { "name": "class1$macrocall$28", "symbols": ["class1$macrocall$29", { "literal": "/" }, "class1$macrocall$30"] }, { "name": "class1$macrocall$28", "symbols": ["class1$macrocall$30", { "literal": "/" }, "class1$macrocall$29"] }, { "name": "class1", "symbols": ["class1$macrocall$28"], "postprocess": function postprocess() {
306 | return 'U2J';
307 | } }, { "name": "class1$macrocall$32$string$1", "symbols": [{ "literal": "1" }, { "literal": "0" }, { "literal": "0" }, { "literal": "0" }], "postprocess": function joiner(d) {
308 | return d.join('');
309 | } }, { "name": "class1$macrocall$32", "symbols": ["N", "class1$macrocall$32$string$1"] }, { "name": "class1$macrocall$33", "symbols": ["Q", { "literal": "3" }, "K"] }, { "name": "class1$macrocall$31", "symbols": ["class1$macrocall$32"] }, { "name": "class1$macrocall$31", "symbols": ["class1$macrocall$33"] }, { "name": "class1$macrocall$31", "symbols": ["class1$macrocall$32", { "literal": "/" }, "class1$macrocall$33"] }, { "name": "class1$macrocall$31", "symbols": ["class1$macrocall$33", { "literal": "/" }, "class1$macrocall$32"] }, { "name": "class1", "symbols": ["class1$macrocall$31"], "postprocess": function postprocess() {
310 | return 'Q3K';
311 | } }, { "name": "class1$macrocall$35$string$1", "symbols": [{ "literal": "1" }, { "literal": "5" }, { "literal": "0" }, { "literal": "0" }], "postprocess": function joiner(d) {
312 | return d.join('');
313 | } }, { "name": "class1$macrocall$35", "symbols": ["N", "class1$macrocall$35$string$1"] }, { "name": "class1$macrocall$36", "symbols": ["P", { "literal": "3" }, "K"] }, { "name": "class1$macrocall$34", "symbols": ["class1$macrocall$35"] }, { "name": "class1$macrocall$34", "symbols": ["class1$macrocall$36"] }, { "name": "class1$macrocall$34", "symbols": ["class1$macrocall$35", { "literal": "/" }, "class1$macrocall$36"] }, { "name": "class1$macrocall$34", "symbols": ["class1$macrocall$36", { "literal": "/" }, "class1$macrocall$35"] }, { "name": "class1", "symbols": ["class1$macrocall$34"], "postprocess": function postprocess() {
314 | return 'P3K';
315 | } }, { "name": "class2", "symbols": ["class2_letter", "class2_number", "class2_code"], "postprocess": function postprocess(d) {
316 | return d.join('').toUpperCase();
317 | } }, { "name": "class2_letter", "symbols": ["X"] }, { "name": "class2_letter", "symbols": ["Y"] }, { "name": "class2_letter", "symbols": ["Z"] }, { "name": "class2_number", "symbols": [{ "literal": "4" }] }, { "name": "class2_number", "symbols": [{ "literal": "5" }] }, { "name": "class2_number", "symbols": [{ "literal": "6" }] }, { "name": "class2_number", "symbols": [{ "literal": "7" }] }, { "name": "class2_number", "symbols": [{ "literal": "8" }] }, { "name": "class2_number", "symbols": [{ "literal": "9" }] }, { "name": "class2_code", "symbols": ["P"] }, { "name": "class2_code", "symbols": ["R"] }, { "name": "class2_code", "symbols": ["S"] }, { "name": "class2_code", "symbols": ["T"] }, { "name": "class2_code", "symbols": ["U"] }, { "name": "class2_code", "symbols": ["V"] }, { "name": "tolerance$ebnf$1$subexpression$1", "symbols": ["plusMinus", "_"] }, { "name": "tolerance$ebnf$1", "symbols": ["tolerance$ebnf$1$subexpression$1"], "postprocess": id }, { "name": "tolerance$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
318 | return null;
319 | } }, { "name": "tolerance", "symbols": ["tolerance$ebnf$1", "decimal", "_", { "literal": "%" }], "postprocess": function postprocess(d) {
320 | return { tolerance: d[1] };
321 | } }, { "name": "plusMinus$string$1", "symbols": [{ "literal": "+" }, { "literal": "/" }, { "literal": "-" }], "postprocess": function joiner(d) {
322 | return d.join('');
323 | } }, { "name": "plusMinus", "symbols": ["plusMinus$string$1"] }, { "name": "plusMinus", "symbols": [{ "literal": "±" }] }, { "name": "plusMinus$string$2", "symbols": [{ "literal": "+" }, { "literal": "-" }], "postprocess": function joiner(d) {
324 | return d.join('');
325 | } }, { "name": "plusMinus", "symbols": ["plusMinus$string$2"] }, { "name": "capacitance", "symbols": ["capacitanceNoFarad", "_", "farad"], "postprocess": id }, { "name": "capacitanceNoFarad", "symbols": ["decimal", "_", "capacitanceRest"], "postprocess": capacitance }, { "name": "capacitanceRest$ebnf$1", "symbols": ["int"], "postprocess": id }, { "name": "capacitanceRest$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
326 | return null;
327 | } }, { "name": "capacitanceRest", "symbols": ["cMetricPrefix", "capacitanceRest$ebnf$1"] }, { "name": "farad", "symbols": ["F"], "postprocess": nuller }, { "name": "farad", "symbols": ["F", "A", "R", "A", "D"], "postprocess": nuller }, { "name": "resistor$ebnf$1", "symbols": ["resistor_prefix"], "postprocess": id }, { "name": "resistor$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
328 | return null;
329 | } }, { "name": "resistor$ebnf$2", "symbols": ["packageSize"], "postprocess": id }, { "name": "resistor$ebnf$2", "symbols": [], "postprocess": function postprocess(d) {
330 | return null;
331 | } }, { "name": "resistor", "symbols": ["resistor$ebnf$1", "rSpecs", "resistance", "rSpecs", "resistor$ebnf$2", "rSpecs"] }, { "name": "resistor$ebnf$3", "symbols": ["resistor_prefix"], "postprocess": id }, { "name": "resistor$ebnf$3", "symbols": [], "postprocess": function postprocess(d) {
332 | return null;
333 | } }, { "name": "resistor$ebnf$4", "symbols": ["packageSize"], "postprocess": id }, { "name": "resistor$ebnf$4", "symbols": [], "postprocess": function postprocess(d) {
334 | return null;
335 | } }, { "name": "resistor", "symbols": ["resistor$ebnf$3", "rSpecs", "resistor$ebnf$4", "rSpecs", "resistance", "rSpecs"] }, { "name": "resistor$ebnf$5", "symbols": ["resistanceNoR"], "postprocess": id }, { "name": "resistor$ebnf$5", "symbols": [], "postprocess": function postprocess(d) {
336 | return null;
337 | } }, { "name": "resistor$ebnf$6", "symbols": ["packageSize"], "postprocess": id }, { "name": "resistor$ebnf$6", "symbols": [], "postprocess": function postprocess(d) {
338 | return null;
339 | } }, { "name": "resistor", "symbols": ["resistor_prefix", "rSpecs", "resistor$ebnf$5", "rSpecs", "resistor$ebnf$6", "rSpecs"] }, { "name": "resistor$ebnf$7", "symbols": ["packageSize"], "postprocess": id }, { "name": "resistor$ebnf$7", "symbols": [], "postprocess": function postprocess(d) {
340 | return null;
341 | } }, { "name": "resistor$ebnf$8", "symbols": ["resistanceNoR"], "postprocess": id }, { "name": "resistor$ebnf$8", "symbols": [], "postprocess": function postprocess(d) {
342 | return null;
343 | } }, { "name": "resistor", "symbols": ["resistor_prefix", "rSpecs", "resistor$ebnf$7", "rSpecs", "resistor$ebnf$8", "rSpecs"] }, { "name": "resistor_prefix", "symbols": ["R"], "postprocess": nuller }, { "name": "resistor_prefix", "symbols": ["R", "E", "S"], "postprocess": nuller }, { "name": "resistor_prefix", "symbols": ["R", "E", "S", "I", "S", "T", "O", "R"], "postprocess": nuller }, { "name": "rSpecs$ebnf$1", "symbols": [] }, { "name": "rSpecs$ebnf$1$subexpression$1", "symbols": ["_", "rSpec", "_"] }, { "name": "rSpecs$ebnf$1", "symbols": ["rSpecs$ebnf$1", "rSpecs$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {
344 | return d[0].concat([d[1]]);
345 | } }, { "name": "rSpecs", "symbols": ["rSpecs$ebnf$1"] }, { "name": "rSpecs", "symbols": ["__"] }, { "name": "rSpec", "symbols": ["tolerance"] }, { "name": "rSpec", "symbols": ["power_rating"] }, { "name": "power_rating", "symbols": ["power_rating_decimal"] }, { "name": "power_rating", "symbols": ["power_rating_fraction"] }, { "name": "power_rating_fraction", "symbols": ["decimal", { "literal": "/" }, "decimal", "_", "watts"], "postprocess": function postprocess(d) {
346 | var _d4 = _slicedToArray(d, 3),
347 | n1 = _d4[0],
348 | _ = _d4[1],
349 | n2 = _d4[2];
350 |
351 | return { power_rating: n1 / n2 };
352 | } }, { "name": "power_rating_decimal", "symbols": ["decimal", "_", "powerMetricPrefix", "_", "watts"], "postprocess": function postprocess(d) {
353 | var _d5 = _slicedToArray(d, 3),
354 | quantity = _d5[0],
355 | metricPrefix = _d5[2];
356 |
357 | return { power_rating: parseFloat('' + quantity + metricPrefix) };
358 | } }, { "name": "watts", "symbols": ["watts_"], "postprocess": nuller }, { "name": "watts_", "symbols": ["W"] }, { "name": "watts_", "symbols": ["W", "A", "T", "T", "S"] }, { "name": "resistance", "symbols": ["decimal", "_", "rest"], "postprocess": resistance }, { "name": "rest$ebnf$1", "symbols": ["int"], "postprocess": id }, { "name": "rest$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
359 | return null;
360 | } }, { "name": "rest$ebnf$2$subexpression$1", "symbols": ["_", "ohm"] }, { "name": "rest$ebnf$2", "symbols": ["rest$ebnf$2$subexpression$1"], "postprocess": id }, { "name": "rest$ebnf$2", "symbols": [], "postprocess": function postprocess(d) {
361 | return null;
362 | } }, { "name": "rest", "symbols": ["rMetricPrefix", "rest$ebnf$1", "rest$ebnf$2"] }, { "name": "rest", "symbols": ["ohm"] }, { "name": "resistanceNoR", "symbols": ["decimal"], "postprocess": function postprocess(d) {
363 | return { resistance: d[0] };
364 | } }, { "name": "ohm", "symbols": ["ohm_"], "postprocess": nuller }, { "name": "ohm_$subexpression$1$ebnf$1", "symbols": ["S"], "postprocess": id }, { "name": "ohm_$subexpression$1$ebnf$1", "symbols": [], "postprocess": function postprocess(d) {
365 | return null;
366 | } }, { "name": "ohm_$subexpression$1", "symbols": ["ohm_$subexpression$1$ebnf$1"] }, { "name": "ohm_", "symbols": ["O", "H", "M", "ohm_$subexpression$1"] }, { "name": "ohm_", "symbols": [{ "literal": "Ω" }] }, { "name": "ohm_", "symbols": [{ "literal": "Ω" }] }, { "name": "led", "symbols": ["led_letters", "ledSpecs"] }, { "name": "led", "symbols": ["ledSpecs", "led_letters"] }, { "name": "led", "symbols": ["ledSpecs", "led_letters", "ledSpecs"] }, { "name": "led_letters", "symbols": ["L", "E", "D"], "postprocess": nuller }, { "name": "ledSpecs$ebnf$1$subexpression$1", "symbols": ["_", "ledSpec", "_"] }, { "name": "ledSpecs$ebnf$1", "symbols": ["ledSpecs$ebnf$1$subexpression$1"] }, { "name": "ledSpecs$ebnf$1$subexpression$2", "symbols": ["_", "ledSpec", "_"] }, { "name": "ledSpecs$ebnf$1", "symbols": ["ledSpecs$ebnf$1", "ledSpecs$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {
367 | return d[0].concat([d[1]]);
368 | } }, { "name": "ledSpecs", "symbols": ["ledSpecs$ebnf$1"] }, { "name": "ledSpec", "symbols": ["packageSize"] }, { "name": "ledSpec", "symbols": ["color"] }, { "name": "color", "symbols": ["color_name"], "postprocess": function postprocess(d) {
369 | return { color: d[0] };
370 | } }, { "name": "color_name", "symbols": ["R", "E", "D"], "postprocess": function postprocess() {
371 | return 'red';
372 | } }, { "name": "color_name", "symbols": ["G", "R", "E", "E", "N"], "postprocess": function postprocess() {
373 | return 'green';
374 | } }, { "name": "color_name", "symbols": ["B", "L", "U", "E"], "postprocess": function postprocess() {
375 | return 'blue';
376 | } }, { "name": "color_name", "symbols": ["Y", "E", "L", "L", "O", "W"], "postprocess": function postprocess() {
377 | return 'yellow';
378 | } }, { "name": "color_name", "symbols": ["O", "R", "A", "N", "G", "E"], "postprocess": function postprocess() {
379 | return 'orange';
380 | } }, { "name": "color_name", "symbols": ["W", "H", "I", "T", "E"], "postprocess": function postprocess() {
381 | return 'white';
382 | } }, { "name": "color_name", "symbols": ["A", "M", "B", "E", "R"], "postprocess": function postprocess() {
383 | return 'amber';
384 | } }, { "name": "color_name", "symbols": ["C", "Y", "A", "N"], "postprocess": function postprocess() {
385 | return 'cyan';
386 | } }, { "name": "color_name", "symbols": ["P", "U", "R", "P", "L", "E"], "postprocess": function postprocess() {
387 | return 'purple';
388 | } }, { "name": "color_name", "symbols": ["Y", "E", "L", "L", "O", "W", "_", "G", "R", "E", "E", "N"], "postprocess": function postprocess() {
389 | return 'yellow green';
390 | } }, { "name": "powerMetricPrefix", "symbols": ["giga"], "postprocess": function postprocess() {
391 | return 'e9 ';
392 | } }, { "name": "powerMetricPrefix", "symbols": ["mega"], "postprocess": function postprocess() {
393 | return 'e6 ';
394 | } }, { "name": "powerMetricPrefix", "symbols": ["kilo"], "postprocess": function postprocess() {
395 | return 'e3 ';
396 | } }, { "name": "powerMetricPrefix", "symbols": ["milli"], "postprocess": function postprocess() {
397 | return 'e-3 ';
398 | } }, { "name": "powerMetricPrefix", "symbols": ["micro"], "postprocess": function postprocess() {
399 | return 'e-6 ';
400 | } }, { "name": "powerMetricPrefix", "symbols": ["nano"], "postprocess": function postprocess() {
401 | return 'e-9 ';
402 | } }, { "name": "powerMetricPrefix", "symbols": ["pico"], "postprocess": function postprocess() {
403 | return 'e-12';
404 | } }, { "name": "powerMetricPrefix", "symbols": ["femto"], "postprocess": function postprocess() {
405 | return 'e-15';
406 | } }, { "name": "powerMetricPrefix", "symbols": [], "postprocess": function postprocess() {
407 | return '';
408 | } }, { "name": "rMetricPrefix", "symbols": ["giga"], "postprocess": function postprocess() {
409 | return 'e9 ';
410 | } }, { "name": "rMetricPrefix", "symbols": ["mega"], "postprocess": function postprocess() {
411 | return 'e6 ';
412 | } }, { "name": "rMetricPrefix", "symbols": ["kilo"], "postprocess": function postprocess() {
413 | return 'e3 ';
414 | } }, { "name": "rMetricPrefix", "symbols": ["R"], "postprocess": function postprocess() {
415 | return '';
416 | } }, { "name": "rMetricPrefix", "symbols": ["milli"], "postprocess": function postprocess() {
417 | return 'e-3 ';
418 | } }, { "name": "rMetricPrefix", "symbols": ["micro"], "postprocess": function postprocess() {
419 | return 'e-6 ';
420 | } }, { "name": "cMetricPrefix", "symbols": ["milli"], "postprocess": function postprocess() {
421 | return 'e-3 ';
422 | } }, { "name": "cMetricPrefix", "symbols": ["micro"], "postprocess": function postprocess() {
423 | return 'e-6 ';
424 | } }, { "name": "cMetricPrefix", "symbols": ["nano"], "postprocess": function postprocess() {
425 | return 'e-9 ';
426 | } }, { "name": "cMetricPrefix", "symbols": ["pico"], "postprocess": function postprocess() {
427 | return 'e-12';
428 | } }, { "name": "cMetricPrefix", "symbols": [], "postprocess": function postprocess() {
429 | return '';
430 | } }],
431 | ParserStart: "main"
432 | };
433 | if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
434 | module.exports = grammar;
435 | } else {
436 | window.grammar = grammar;
437 | }
438 | })();
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var parse = require('./parse');
4 | var matchCPL = require('./match_cpl');
5 | module.exports = { parse: parse, matchCPL: matchCPL };
--------------------------------------------------------------------------------
/lib/match_cpl.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var resistors = require('./cpl_resistors');
4 | var capacitors = require('./cpl_capacitors');
5 | var leds = require('./cpl_leds');
6 |
7 | function matchCPL(component) {
8 | component = component || {};
9 | switch (component.type) {
10 | case 'capacitor':
11 | return matchCapacitor(component);
12 | case 'resistor':
13 | return matchResistor(component);
14 | case 'led':
15 | return matchLED(component);
16 | }
17 | return [];
18 | }
19 |
20 | function matchResistor(c) {
21 | return resistors.reduce(function (prev, cpl) {
22 | var resistance = cpl.resistance === c.resistance;
23 | var size = c.size == null || cpl.size === c.size;
24 | var tolerance = c.tolerance == null || cpl.tolerance <= c.tolerance;
25 | var power_rating = c.power_rating == null || cpl.power_rating >= c.power_rating;
26 | if (resistance && size && tolerance && power_rating) {
27 | return prev.concat([cpl.cplid]);
28 | }
29 | return prev;
30 | }, []);
31 | }
32 |
33 | function matchCapacitor(c) {
34 | return capacitors.reduce(function (prev, cpl) {
35 | var capacitance = cpl.capacitance === c.capacitance;
36 | var size = c.size == null || cpl.size === c.size;
37 | var characteristic = c.characteristic == null || cpl.characteristic === c.characteristic;
38 | var tolerance = c.tolerance == null || cpl.tolerance <= c.tolerance;
39 | var voltage_rating = c.voltage_rating == null || cpl.voltage_rating >= c.voltage_rating;
40 | if (capacitance && size && characteristic && tolerance && voltage_rating) {
41 | return prev.concat([cpl.cplid]);
42 | }
43 | return prev;
44 | }, []);
45 | }
46 |
47 | function matchLED(c) {
48 | return leds.reduce(function (prev, cpl) {
49 | var color = c.color == null || cpl.color === c.color;
50 | var size = c.size == null || cpl.size === c.size;
51 | if (color && size) {
52 | return prev.concat([cpl.cplid]);
53 | }
54 | return prev;
55 | }, []);
56 | }
57 |
58 | module.exports = matchCPL;
--------------------------------------------------------------------------------
/lib/parse.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var nearley = require('nearley');
4 | var grammar = require('./grammar');
5 |
6 | function parse(str) {
7 | var parser = new nearley.Parser(grammar.ParserRules, grammar.ParserStart, { keepHistory: true });
8 | var words = str.split(' ');
9 | var info = parser.save();
10 | return words.reduce(function (prev, word) {
11 | word = word.replace(/,|;/, '') + ' ';
12 | //if it fails, roll it back
13 | try {
14 | parser.feed(word);
15 | } catch (e) {
16 | parser.restore(info);
17 | }
18 | info = parser.save();
19 | //return the latest valid result
20 | return parser.results[0] || prev;
21 | }, {});
22 | }
23 |
24 | module.exports = parse;
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "electro-grammar",
3 | "description": "Parser electronic components descriptions such as surface-mount resistors and capacitors.",
4 | "version": "1.2.0",
5 | "main": "lib/index.js",
6 | "keywords": [
7 | "electronics",
8 | "grammar",
9 | "parser",
10 | "pcb"
11 | ],
12 | "license": "MIT",
13 | "repository": "https://github.com/monostable/electro-grammar",
14 | "scripts": {
15 | "build:grammar": "nearleyc src/grammar.ne --out src/grammar.js",
16 | "build:lib": "babel src/ -d lib/",
17 | "build:cpl": "node prepare_cpl.js",
18 | "demo": "browserify docs/index.js > docs/bundle.js",
19 | "build": "npm run build:grammar && npm run build:cpl && npm run build:lib",
20 | "pretest": "npm run build",
21 | "test": "nyc -- mocha --check-leaks",
22 | "coverage": "nyc report",
23 | "coverage:html": "nyc report --reporter=html",
24 | "test:browser": "zuul --local -- test/*.js",
25 | "pretest:sauce": "babel test/ -d test-lib/",
26 | "test:sauce": "zuul -- test-lib/*.js"
27 | },
28 | "dependencies": {
29 | "nearley": "^2.15.1"
30 | },
31 | "devDependencies": {
32 | "babel-cli": "^6.24.1",
33 | "babel-plugin-transform-object-assign": "^6.22.0",
34 | "babel-preset-es2015": "^6.24.1",
35 | "better-assert": "^1.0.2",
36 | "browserify": "^16.2.2",
37 | "js-yaml": "^3.9.1",
38 | "mocha": "^5.2.0",
39 | "nyc": "^13.0.1",
40 | "zuul": "^3.12.0"
41 | },
42 | "babel": {
43 | "presets": [
44 | "es2015"
45 | ],
46 | "plugins": [
47 | "transform-object-assign"
48 | ]
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/prepare_cpl.js:
--------------------------------------------------------------------------------
1 | const yaml = require('js-yaml')
2 | const fs = require('fs')
3 | const parse = require('./src/parse')
4 |
5 | let resistors = fs.readFileSync('./cpl-data/CPL for Production/Resistors.yaml')
6 | resistors = yaml.safeLoad(resistors)
7 | resistors = resistors.rows.map(r => {
8 | //ignore potentiometers and resistor arrays
9 | if (!/RES/.test(r.cplid)) {
10 | return
11 | }
12 | const v = parse(r.title)
13 | if (v.type === 'resistor') {
14 | v.cplid = r.cplid
15 | return v
16 | }
17 | }).filter(v => v)
18 | resistors = 'module.exports = ' + JSON.stringify(resistors, null, 2)
19 | fs.writeFileSync('./lib/cpl_resistors.js', resistors)
20 |
21 | let capacitors = fs.readFileSync('./cpl-data/CPL for Production/Capacitors.yaml')
22 | capacitors = yaml.safeLoad(capacitors)
23 | capacitors = capacitors.rows.map(c => {
24 | const v = parse(`${c.title} ${c.extravals.Characteristic}`)
25 | if (v.type === 'capacitor') {
26 | v.cplid = c.cplid
27 | return v
28 | }
29 | }).filter(v => v)
30 | capacitors = 'module.exports = ' + JSON.stringify(capacitors, null, 2)
31 | fs.writeFileSync('./lib/cpl_capacitors.js', capacitors)
32 |
33 | let leds = fs.readFileSync('./cpl-data/CPL for Production/LEDs.yaml')
34 | leds = yaml.safeLoad(leds)
35 | leds = leds.rows.map(c => {
36 | const v = parse(c.title)
37 | if (v.type === 'led') {
38 | v.cplid = c.cplid
39 | return v
40 | }
41 | }).filter(v => v)
42 | leds = 'module.exports = ' + JSON.stringify(leds, null, 2)
43 | fs.writeFileSync('./lib/cpl_leds.js', leds)
44 |
--------------------------------------------------------------------------------
/src/flatten.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * arr-flatten
3 | *
4 | * Copyright (c) 2014-2017, Jon Schlinkert.
5 | * Released under the MIT License.
6 | */
7 |
8 | 'use strict';
9 |
10 | module.exports = function (arr) {
11 | return flat(arr, []);
12 | };
13 |
14 | function flat(arr, res) {
15 | var i = 0, cur;
16 | var len = arr.length;
17 | for (; i < len; i++) {
18 | cur = arr[i];
19 | Array.isArray(cur) ? flat(cur, res) : res.push(cur);
20 | }
21 | return res;
22 | }
23 |
--------------------------------------------------------------------------------
/src/grammar.js:
--------------------------------------------------------------------------------
1 | // Generated automatically by nearley, version 2.15.1
2 | // http://github.com/Hardmath123/nearley
3 | (function () {
4 | function id(x) { return x[0]; }
5 |
6 | const flatten = require('./flatten')
7 |
8 | const filter = d => d.filter(t => t !== null)
9 |
10 | const assignAll = objs => objs.reduce((prev, obj) => Object.assign(prev, obj))
11 |
12 | const nuller = () => null
13 |
14 |
15 | const toImperial = {
16 | '0402': '01005',
17 | '0603': '0201',
18 | '1005': '0402',
19 | '1608': '0603',
20 | '2012': '0805',
21 | '2520': '1008',
22 | '3216': '1206',
23 | '3225': '1210',
24 | '4516': '1806',
25 | '4532': '1812',
26 | '5025': '2010',
27 | '6332': '2512',
28 | }
29 |
30 |
31 | function type(t) {
32 | return d => [{type: t}].concat(d)
33 | }
34 |
35 |
36 | function voltage_rating(d, i, reject) {
37 | const [integral, , [v, fractional]] = d
38 | if (fractional) {
39 | if (/\./.test(integral.toString())) {
40 | return reject
41 | }
42 | var quantity = `${integral}.${fractional}`
43 | } else {
44 | var quantity = integral
45 | }
46 | return {voltage_rating: parseFloat(quantity)}
47 | }
48 |
49 |
50 | function capacitance(d, i, reject) {
51 | const [integral, , [metricPrefix, fractional]] = d
52 | if (fractional) {
53 | if (/\./.test(integral) || metricPrefix === "") {
54 | return reject
55 | }
56 | var quantity = `${integral}.${fractional}`
57 | } else {
58 | if (/1005|201|402|603|805|1206/.test(integral.toString())) {
59 | return reject
60 | }
61 | var quantity = integral
62 | }
63 | return {capacitance: parseFloat(`${quantity}${metricPrefix}`)}
64 | }
65 |
66 |
67 | function resistance(d, i, reject) {
68 | const [integral, , [metricPrefix, fractional, ohm]] = d
69 | if (fractional) {
70 | if (/\./.test(integral.toString())) {
71 | return reject
72 | }
73 | var quantity = `${integral}.${fractional}`
74 | } else {
75 | if (/1005|201|402|603|805|1206/.test(integral.toString())) {
76 | return reject
77 | }
78 | var quantity = integral
79 | }
80 | return {resistance: parseFloat(`${quantity}${metricPrefix}`)}
81 | }
82 | var grammar = {
83 | Lexer: undefined,
84 | ParserRules: [
85 | {"name": "unsigned_int$ebnf$1", "symbols": [/[0-9]/]},
86 | {"name": "unsigned_int$ebnf$1", "symbols": ["unsigned_int$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
87 | {"name": "unsigned_int", "symbols": ["unsigned_int$ebnf$1"], "postprocess":
88 | function(d) {
89 | return parseInt(d[0].join(""));
90 | }
91 | },
92 | {"name": "int$ebnf$1$subexpression$1", "symbols": [{"literal":"-"}]},
93 | {"name": "int$ebnf$1$subexpression$1", "symbols": [{"literal":"+"}]},
94 | {"name": "int$ebnf$1", "symbols": ["int$ebnf$1$subexpression$1"], "postprocess": id},
95 | {"name": "int$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
96 | {"name": "int$ebnf$2", "symbols": [/[0-9]/]},
97 | {"name": "int$ebnf$2", "symbols": ["int$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
98 | {"name": "int", "symbols": ["int$ebnf$1", "int$ebnf$2"], "postprocess":
99 | function(d) {
100 | if (d[0]) {
101 | return parseInt(d[0][0]+d[1].join(""));
102 | } else {
103 | return parseInt(d[1].join(""));
104 | }
105 | }
106 | },
107 | {"name": "unsigned_decimal$ebnf$1", "symbols": [/[0-9]/]},
108 | {"name": "unsigned_decimal$ebnf$1", "symbols": ["unsigned_decimal$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
109 | {"name": "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", "symbols": [/[0-9]/]},
110 | {"name": "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", "symbols": ["unsigned_decimal$ebnf$2$subexpression$1$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
111 | {"name": "unsigned_decimal$ebnf$2$subexpression$1", "symbols": [{"literal":"."}, "unsigned_decimal$ebnf$2$subexpression$1$ebnf$1"]},
112 | {"name": "unsigned_decimal$ebnf$2", "symbols": ["unsigned_decimal$ebnf$2$subexpression$1"], "postprocess": id},
113 | {"name": "unsigned_decimal$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
114 | {"name": "unsigned_decimal", "symbols": ["unsigned_decimal$ebnf$1", "unsigned_decimal$ebnf$2"], "postprocess":
115 | function(d) {
116 | return parseFloat(
117 | d[0].join("") +
118 | (d[1] ? "."+d[1][1].join("") : "")
119 | );
120 | }
121 | },
122 | {"name": "decimal$ebnf$1", "symbols": [{"literal":"-"}], "postprocess": id},
123 | {"name": "decimal$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
124 | {"name": "decimal$ebnf$2", "symbols": [/[0-9]/]},
125 | {"name": "decimal$ebnf$2", "symbols": ["decimal$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
126 | {"name": "decimal$ebnf$3$subexpression$1$ebnf$1", "symbols": [/[0-9]/]},
127 | {"name": "decimal$ebnf$3$subexpression$1$ebnf$1", "symbols": ["decimal$ebnf$3$subexpression$1$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
128 | {"name": "decimal$ebnf$3$subexpression$1", "symbols": [{"literal":"."}, "decimal$ebnf$3$subexpression$1$ebnf$1"]},
129 | {"name": "decimal$ebnf$3", "symbols": ["decimal$ebnf$3$subexpression$1"], "postprocess": id},
130 | {"name": "decimal$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
131 | {"name": "decimal", "symbols": ["decimal$ebnf$1", "decimal$ebnf$2", "decimal$ebnf$3"], "postprocess":
132 | function(d) {
133 | return parseFloat(
134 | (d[0] || "") +
135 | d[1].join("") +
136 | (d[2] ? "."+d[2][1].join("") : "")
137 | );
138 | }
139 | },
140 | {"name": "percentage", "symbols": ["decimal", {"literal":"%"}], "postprocess":
141 | function(d) {
142 | return d[0]/100;
143 | }
144 | },
145 | {"name": "jsonfloat$ebnf$1", "symbols": [{"literal":"-"}], "postprocess": id},
146 | {"name": "jsonfloat$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
147 | {"name": "jsonfloat$ebnf$2", "symbols": [/[0-9]/]},
148 | {"name": "jsonfloat$ebnf$2", "symbols": ["jsonfloat$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
149 | {"name": "jsonfloat$ebnf$3$subexpression$1$ebnf$1", "symbols": [/[0-9]/]},
150 | {"name": "jsonfloat$ebnf$3$subexpression$1$ebnf$1", "symbols": ["jsonfloat$ebnf$3$subexpression$1$ebnf$1", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
151 | {"name": "jsonfloat$ebnf$3$subexpression$1", "symbols": [{"literal":"."}, "jsonfloat$ebnf$3$subexpression$1$ebnf$1"]},
152 | {"name": "jsonfloat$ebnf$3", "symbols": ["jsonfloat$ebnf$3$subexpression$1"], "postprocess": id},
153 | {"name": "jsonfloat$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
154 | {"name": "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "symbols": [/[+-]/], "postprocess": id},
155 | {"name": "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
156 | {"name": "jsonfloat$ebnf$4$subexpression$1$ebnf$2", "symbols": [/[0-9]/]},
157 | {"name": "jsonfloat$ebnf$4$subexpression$1$ebnf$2", "symbols": ["jsonfloat$ebnf$4$subexpression$1$ebnf$2", /[0-9]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
158 | {"name": "jsonfloat$ebnf$4$subexpression$1", "symbols": [/[eE]/, "jsonfloat$ebnf$4$subexpression$1$ebnf$1", "jsonfloat$ebnf$4$subexpression$1$ebnf$2"]},
159 | {"name": "jsonfloat$ebnf$4", "symbols": ["jsonfloat$ebnf$4$subexpression$1"], "postprocess": id},
160 | {"name": "jsonfloat$ebnf$4", "symbols": [], "postprocess": function(d) {return null;}},
161 | {"name": "jsonfloat", "symbols": ["jsonfloat$ebnf$1", "jsonfloat$ebnf$2", "jsonfloat$ebnf$3", "jsonfloat$ebnf$4"], "postprocess":
162 | function(d) {
163 | return parseFloat(
164 | (d[0] || "") +
165 | d[1].join("") +
166 | (d[2] ? "."+d[2][1].join("") : "") +
167 | (d[3] ? "e" + (d[3][1] || "+") + d[3][2].join("") : "")
168 | );
169 | }
170 | },
171 | {"name": "_$ebnf$1", "symbols": []},
172 | {"name": "_$ebnf$1", "symbols": ["_$ebnf$1", /[\s]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
173 | {"name": "_", "symbols": ["_$ebnf$1"], "postprocess": () => null},
174 | {"name": "__$ebnf$1", "symbols": [/[\s]/]},
175 | {"name": "__$ebnf$1", "symbols": ["__$ebnf$1", /[\s]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
176 | {"name": "__", "symbols": ["__$ebnf$1"], "postprocess": () => null},
177 | {"name": "A", "symbols": [{"literal":"A"}]},
178 | {"name": "A", "symbols": [{"literal":"a"}]},
179 | {"name": "B", "symbols": [{"literal":"B"}]},
180 | {"name": "B", "symbols": [{"literal":"b"}]},
181 | {"name": "C", "symbols": [{"literal":"C"}]},
182 | {"name": "C", "symbols": [{"literal":"c"}]},
183 | {"name": "D", "symbols": [{"literal":"D"}]},
184 | {"name": "D", "symbols": [{"literal":"d"}]},
185 | {"name": "E", "symbols": [{"literal":"E"}]},
186 | {"name": "E", "symbols": [{"literal":"e"}]},
187 | {"name": "F", "symbols": [{"literal":"F"}]},
188 | {"name": "F", "symbols": [{"literal":"f"}]},
189 | {"name": "G", "symbols": [{"literal":"G"}]},
190 | {"name": "G", "symbols": [{"literal":"g"}]},
191 | {"name": "H", "symbols": [{"literal":"H"}]},
192 | {"name": "H", "symbols": [{"literal":"h"}]},
193 | {"name": "I", "symbols": [{"literal":"I"}]},
194 | {"name": "I", "symbols": [{"literal":"i"}]},
195 | {"name": "J", "symbols": [{"literal":"J"}]},
196 | {"name": "J", "symbols": [{"literal":"j"}]},
197 | {"name": "K", "symbols": [{"literal":"K"}]},
198 | {"name": "K", "symbols": [{"literal":"k"}]},
199 | {"name": "L", "symbols": [{"literal":"L"}]},
200 | {"name": "L", "symbols": [{"literal":"l"}]},
201 | {"name": "M", "symbols": [{"literal":"M"}]},
202 | {"name": "M", "symbols": [{"literal":"m"}]},
203 | {"name": "N", "symbols": [{"literal":"N"}]},
204 | {"name": "N", "symbols": [{"literal":"n"}]},
205 | {"name": "O", "symbols": [{"literal":"O"}]},
206 | {"name": "O", "symbols": [{"literal":"o"}]},
207 | {"name": "P", "symbols": [{"literal":"P"}]},
208 | {"name": "P", "symbols": [{"literal":"p"}]},
209 | {"name": "Q", "symbols": [{"literal":"Q"}]},
210 | {"name": "Q", "symbols": [{"literal":"q"}]},
211 | {"name": "R", "symbols": [{"literal":"R"}]},
212 | {"name": "R", "symbols": [{"literal":"r"}]},
213 | {"name": "S", "symbols": [{"literal":"S"}]},
214 | {"name": "S", "symbols": [{"literal":"s"}]},
215 | {"name": "T", "symbols": [{"literal":"T"}]},
216 | {"name": "T", "symbols": [{"literal":"t"}]},
217 | {"name": "U", "symbols": [{"literal":"U"}]},
218 | {"name": "U", "symbols": [{"literal":"u"}]},
219 | {"name": "V", "symbols": [{"literal":"V"}]},
220 | {"name": "V", "symbols": [{"literal":"v"}]},
221 | {"name": "W", "symbols": [{"literal":"W"}]},
222 | {"name": "W", "symbols": [{"literal":"w"}]},
223 | {"name": "X", "symbols": [{"literal":"X"}]},
224 | {"name": "X", "symbols": [{"literal":"x"}]},
225 | {"name": "Y", "symbols": [{"literal":"Y"}]},
226 | {"name": "Y", "symbols": [{"literal":"y"}]},
227 | {"name": "Z", "symbols": [{"literal":"Z"}]},
228 | {"name": "Z", "symbols": [{"literal":"z"}]},
229 | {"name": "exa", "symbols": [{"literal":"E"}]},
230 | {"name": "exa", "symbols": ["E", "X", "A"]},
231 | {"name": "peta", "symbols": [{"literal":"P"}]},
232 | {"name": "peta", "symbols": ["P", "E", "T", "A"]},
233 | {"name": "tera", "symbols": [{"literal":"T"}]},
234 | {"name": "tera", "symbols": ["T", "E", "R", "A"]},
235 | {"name": "giga", "symbols": [{"literal":"G"}]},
236 | {"name": "giga", "symbols": ["G", "I", "G"]},
237 | {"name": "giga", "symbols": ["G", "I", "G", "A"]},
238 | {"name": "mega", "symbols": [{"literal":"M"}]},
239 | {"name": "mega", "symbols": ["M", "E", "G"]},
240 | {"name": "mega", "symbols": ["M", "E", "G", "A"]},
241 | {"name": "kilo", "symbols": ["K"]},
242 | {"name": "kilo", "symbols": ["K", "I", "L", "O"]},
243 | {"name": "hecto", "symbols": [{"literal":"h"}]},
244 | {"name": "hecto", "symbols": ["H", "E", "C", "T", "O"]},
245 | {"name": "deci", "symbols": [{"literal":"d"}]},
246 | {"name": "deci", "symbols": ["D", "E", "C", "I"]},
247 | {"name": "centi", "symbols": [{"literal":"c"}]},
248 | {"name": "centi", "symbols": ["C", "E", "N", "T", "I"]},
249 | {"name": "milli", "symbols": [{"literal":"m"}]},
250 | {"name": "milli", "symbols": ["M", "I", "L", "L", "I"]},
251 | {"name": "micro", "symbols": ["U"]},
252 | {"name": "micro", "symbols": [/[\u03BC]/]},
253 | {"name": "micro", "symbols": [/[\u00B5]/]},
254 | {"name": "micro", "symbols": [/[\uD835]/, /[\uDECD]/]},
255 | {"name": "micro", "symbols": [/[\uD835]/, /[\uDF07]/]},
256 | {"name": "micro", "symbols": [/[\uD835]/, /[\uDF41]/]},
257 | {"name": "micro", "symbols": [/[\uD835]/, /[\uDF7B]/]},
258 | {"name": "micro", "symbols": [/[\uD835]/, /[\uDFB5]/]},
259 | {"name": "micro", "symbols": ["M", "I", "C", "R", "O"]},
260 | {"name": "nano", "symbols": ["N"]},
261 | {"name": "nano", "symbols": ["N", "A", "N"]},
262 | {"name": "nano", "symbols": ["N", "A", "N", "O"]},
263 | {"name": "pico", "symbols": ["P"]},
264 | {"name": "pico", "symbols": ["P", "I", "C", "O"]},
265 | {"name": "femto", "symbols": [{"literal":"f"}]},
266 | {"name": "femto", "symbols": ["F", "E", "M", "T", "O"]},
267 | {"name": "atto", "symbols": [{"literal":"a"}]},
268 | {"name": "atto", "symbols": ["A", "T", "T", "O"]},
269 | {"name": "packageSize", "symbols": ["_packageSize"], "postprocess": d => ({size: filter(flatten(d))[0]})},
270 | {"name": "_packageSize", "symbols": ["_imperialSize"]},
271 | {"name": "_packageSize", "symbols": ["_metricSize"]},
272 | {"name": "_imperialSize$string$1", "symbols": [{"literal":"0"}, {"literal":"1"}, {"literal":"0"}, {"literal":"0"}, {"literal":"5"}], "postprocess": function joiner(d) {return d.join('');}},
273 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$1"]},
274 | {"name": "_imperialSize$string$2", "symbols": [{"literal":"0"}, {"literal":"2"}, {"literal":"0"}, {"literal":"1"}], "postprocess": function joiner(d) {return d.join('');}},
275 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$2"]},
276 | {"name": "_imperialSize$string$3", "symbols": [{"literal":"0"}, {"literal":"4"}, {"literal":"0"}, {"literal":"2"}], "postprocess": function joiner(d) {return d.join('');}},
277 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$3"]},
278 | {"name": "_imperialSize$string$4", "symbols": [{"literal":"0"}, {"literal":"6"}, {"literal":"0"}, {"literal":"3"}], "postprocess": function joiner(d) {return d.join('');}},
279 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$4"]},
280 | {"name": "_imperialSize$string$5", "symbols": [{"literal":"0"}, {"literal":"8"}, {"literal":"0"}, {"literal":"5"}], "postprocess": function joiner(d) {return d.join('');}},
281 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$5"]},
282 | {"name": "_imperialSize$string$6", "symbols": [{"literal":"1"}, {"literal":"0"}, {"literal":"0"}, {"literal":"8"}], "postprocess": function joiner(d) {return d.join('');}},
283 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$6"]},
284 | {"name": "_imperialSize$string$7", "symbols": [{"literal":"1"}, {"literal":"2"}, {"literal":"0"}, {"literal":"6"}], "postprocess": function joiner(d) {return d.join('');}},
285 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$7"]},
286 | {"name": "_imperialSize$string$8", "symbols": [{"literal":"1"}, {"literal":"2"}, {"literal":"1"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
287 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$8"]},
288 | {"name": "_imperialSize$string$9", "symbols": [{"literal":"1"}, {"literal":"8"}, {"literal":"0"}, {"literal":"6"}], "postprocess": function joiner(d) {return d.join('');}},
289 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$9"]},
290 | {"name": "_imperialSize$string$10", "symbols": [{"literal":"2"}, {"literal":"0"}, {"literal":"1"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
291 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$10"]},
292 | {"name": "_imperialSize$string$11", "symbols": [{"literal":"2"}, {"literal":"5"}, {"literal":"1"}, {"literal":"2"}], "postprocess": function joiner(d) {return d.join('');}},
293 | {"name": "_imperialSize", "symbols": ["_imperialSize$string$11"]},
294 | {"name": "_metricSize$ebnf$1", "symbols": []},
295 | {"name": "_metricSize$ebnf$1", "symbols": ["_metricSize$ebnf$1", /[\s]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
296 | {"name": "_metricSize", "symbols": ["__metricSize", "_metricSize$ebnf$1", "M", "E", "T", "R", "I", "C"], "postprocess": d => toImperial[d[0]]},
297 | {"name": "_metricSize$ebnf$2", "symbols": []},
298 | {"name": "_metricSize$ebnf$2", "symbols": ["_metricSize$ebnf$2", /[\s]/], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
299 | {"name": "_metricSize", "symbols": ["M", "E", "T", "R", "I", "C", "_metricSize$ebnf$2", "__metricSize"], "postprocess": d => toImperial[d[7]]},
300 | {"name": "_metricSize", "symbols": ["unambigiousMetricSize"], "postprocess": d => toImperial[d[0]]},
301 | {"name": "unambigiousMetricSize$string$1", "symbols": [{"literal":"1"}, {"literal":"0"}, {"literal":"0"}, {"literal":"5"}], "postprocess": function joiner(d) {return d.join('');}},
302 | {"name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$1"]},
303 | {"name": "unambigiousMetricSize$string$2", "symbols": [{"literal":"1"}, {"literal":"6"}, {"literal":"0"}, {"literal":"8"}], "postprocess": function joiner(d) {return d.join('');}},
304 | {"name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$2"]},
305 | {"name": "unambigiousMetricSize$string$3", "symbols": [{"literal":"2"}, {"literal":"0"}, {"literal":"1"}, {"literal":"2"}], "postprocess": function joiner(d) {return d.join('');}},
306 | {"name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$3"]},
307 | {"name": "unambigiousMetricSize$string$4", "symbols": [{"literal":"2"}, {"literal":"5"}, {"literal":"2"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
308 | {"name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$4"]},
309 | {"name": "unambigiousMetricSize$string$5", "symbols": [{"literal":"3"}, {"literal":"2"}, {"literal":"1"}, {"literal":"6"}], "postprocess": function joiner(d) {return d.join('');}},
310 | {"name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$5"]},
311 | {"name": "unambigiousMetricSize$string$6", "symbols": [{"literal":"3"}, {"literal":"2"}, {"literal":"2"}, {"literal":"5"}], "postprocess": function joiner(d) {return d.join('');}},
312 | {"name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$6"]},
313 | {"name": "unambigiousMetricSize$string$7", "symbols": [{"literal":"4"}, {"literal":"5"}, {"literal":"1"}, {"literal":"6"}], "postprocess": function joiner(d) {return d.join('');}},
314 | {"name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$7"]},
315 | {"name": "unambigiousMetricSize$string$8", "symbols": [{"literal":"5"}, {"literal":"0"}, {"literal":"2"}, {"literal":"5"}], "postprocess": function joiner(d) {return d.join('');}},
316 | {"name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$8"]},
317 | {"name": "unambigiousMetricSize$string$9", "symbols": [{"literal":"6"}, {"literal":"3"}, {"literal":"3"}, {"literal":"2"}], "postprocess": function joiner(d) {return d.join('');}},
318 | {"name": "unambigiousMetricSize", "symbols": ["unambigiousMetricSize$string$9"]},
319 | {"name": "__metricSize", "symbols": ["unambigiousMetricSize"]},
320 | {"name": "__metricSize$string$1", "symbols": [{"literal":"0"}, {"literal":"4"}, {"literal":"0"}, {"literal":"2"}], "postprocess": function joiner(d) {return d.join('');}},
321 | {"name": "__metricSize", "symbols": ["__metricSize$string$1"]},
322 | {"name": "__metricSize$string$2", "symbols": [{"literal":"0"}, {"literal":"6"}, {"literal":"0"}, {"literal":"3"}], "postprocess": function joiner(d) {return d.join('');}},
323 | {"name": "__metricSize", "symbols": ["__metricSize$string$2"]},
324 | {"name": "M", "symbols": [{"literal":"M"}]},
325 | {"name": "M", "symbols": [{"literal":"m"}]},
326 | {"name": "E", "symbols": [{"literal":"E"}]},
327 | {"name": "E", "symbols": [{"literal":"e"}]},
328 | {"name": "T", "symbols": [{"literal":"T"}]},
329 | {"name": "T", "symbols": [{"literal":"t"}]},
330 | {"name": "R", "symbols": [{"literal":"R"}]},
331 | {"name": "R", "symbols": [{"literal":"r"}]},
332 | {"name": "I", "symbols": [{"literal":"I"}]},
333 | {"name": "I", "symbols": [{"literal":"i"}]},
334 | {"name": "C", "symbols": [{"literal":"C"}]},
335 | {"name": "C", "symbols": [{"literal":"c"}]},
336 | {"name": "main", "symbols": ["component"], "postprocess": d => assignAll(filter(flatten(d)))},
337 | {"name": "component", "symbols": ["capacitor"], "postprocess": type('capacitor')},
338 | {"name": "component", "symbols": ["resistor"], "postprocess": type('resistor')},
339 | {"name": "component", "symbols": ["led"], "postprocess": type('led')},
340 | {"name": "capacitor$ebnf$1", "symbols": ["packageSize"], "postprocess": id},
341 | {"name": "capacitor$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
342 | {"name": "capacitor", "symbols": ["cSpecs", "capacitance", "cSpecs", "capacitor$ebnf$1", "cSpecs"]},
343 | {"name": "capacitor$ebnf$2", "symbols": ["packageSize"], "postprocess": id},
344 | {"name": "capacitor$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
345 | {"name": "capacitor", "symbols": ["cSpecs", "capacitor$ebnf$2", "cSpecs", "capacitance", "cSpecs"]},
346 | {"name": "capacitor$ebnf$3", "symbols": ["packageSize"], "postprocess": id},
347 | {"name": "capacitor$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
348 | {"name": "capacitor$ebnf$4$subexpression$1", "symbols": ["capacitanceNoFarad"]},
349 | {"name": "capacitor$ebnf$4$subexpression$1", "symbols": ["capacitance"]},
350 | {"name": "capacitor$ebnf$4", "symbols": ["capacitor$ebnf$4$subexpression$1"], "postprocess": id},
351 | {"name": "capacitor$ebnf$4", "symbols": [], "postprocess": function(d) {return null;}},
352 | {"name": "capacitor", "symbols": ["cap", "cSpecs", "capacitor$ebnf$3", "cSpecs", "capacitor$ebnf$4", "cSpecs"]},
353 | {"name": "capacitor$ebnf$5$subexpression$1", "symbols": ["capacitanceNoFarad"]},
354 | {"name": "capacitor$ebnf$5$subexpression$1", "symbols": ["capacitance"]},
355 | {"name": "capacitor$ebnf$5", "symbols": ["capacitor$ebnf$5$subexpression$1"], "postprocess": id},
356 | {"name": "capacitor$ebnf$5", "symbols": [], "postprocess": function(d) {return null;}},
357 | {"name": "capacitor$ebnf$6", "symbols": ["packageSize"], "postprocess": id},
358 | {"name": "capacitor$ebnf$6", "symbols": [], "postprocess": function(d) {return null;}},
359 | {"name": "capacitor", "symbols": ["cap", "cSpecs", "capacitor$ebnf$5", "cSpecs", "capacitor$ebnf$6", "cSpecs"]},
360 | {"name": "cap$ebnf$1", "symbols": ["A"], "postprocess": id},
361 | {"name": "cap$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
362 | {"name": "cap$ebnf$2", "symbols": ["P"], "postprocess": id},
363 | {"name": "cap$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
364 | {"name": "cap$ebnf$3", "symbols": ["A"], "postprocess": id},
365 | {"name": "cap$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
366 | {"name": "cap$ebnf$4", "symbols": ["C"], "postprocess": id},
367 | {"name": "cap$ebnf$4", "symbols": [], "postprocess": function(d) {return null;}},
368 | {"name": "cap$ebnf$5", "symbols": ["I"], "postprocess": id},
369 | {"name": "cap$ebnf$5", "symbols": [], "postprocess": function(d) {return null;}},
370 | {"name": "cap$ebnf$6", "symbols": ["T"], "postprocess": id},
371 | {"name": "cap$ebnf$6", "symbols": [], "postprocess": function(d) {return null;}},
372 | {"name": "cap$ebnf$7", "symbols": ["O"], "postprocess": id},
373 | {"name": "cap$ebnf$7", "symbols": [], "postprocess": function(d) {return null;}},
374 | {"name": "cap$ebnf$8", "symbols": ["R"], "postprocess": id},
375 | {"name": "cap$ebnf$8", "symbols": [], "postprocess": function(d) {return null;}},
376 | {"name": "cap", "symbols": ["C", "cap$ebnf$1", "cap$ebnf$2", "cap$ebnf$3", "cap$ebnf$4", "cap$ebnf$5", "cap$ebnf$6", "cap$ebnf$7", "cap$ebnf$8"], "postprocess": nuller},
377 | {"name": "cSpecs$ebnf$1", "symbols": []},
378 | {"name": "cSpecs$ebnf$1$subexpression$1", "symbols": ["_", "cSpec", "_"]},
379 | {"name": "cSpecs$ebnf$1", "symbols": ["cSpecs$ebnf$1", "cSpecs$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
380 | {"name": "cSpecs", "symbols": ["cSpecs$ebnf$1"]},
381 | {"name": "cSpecs", "symbols": ["__"]},
382 | {"name": "cSpec", "symbols": ["tolerance"]},
383 | {"name": "cSpec", "symbols": ["characteristic"]},
384 | {"name": "cSpec", "symbols": ["voltage_rating"]},
385 | {"name": "voltage_rating", "symbols": ["decimal", "_", "voltageRest"], "postprocess": voltage_rating},
386 | {"name": "voltageRest$ebnf$1", "symbols": ["int"], "postprocess": id},
387 | {"name": "voltageRest$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
388 | {"name": "voltageRest", "symbols": ["V", "voltageRest$ebnf$1"]},
389 | {"name": "characteristic", "symbols": ["characteristic_"], "postprocess": d => ({characteristic: d[0][0]})},
390 | {"name": "characteristic_", "symbols": ["class1"]},
391 | {"name": "characteristic_", "symbols": ["class2"]},
392 | {"name": "class1$macrocall$2", "symbols": ["C", {"literal":"0"}, "G"]},
393 | {"name": "class1$macrocall$3", "symbols": ["N", "P", {"literal":"0"}]},
394 | {"name": "class1$macrocall$1", "symbols": ["class1$macrocall$2"]},
395 | {"name": "class1$macrocall$1", "symbols": ["class1$macrocall$3"]},
396 | {"name": "class1$macrocall$1", "symbols": ["class1$macrocall$2", {"literal":"/"}, "class1$macrocall$3"]},
397 | {"name": "class1$macrocall$1", "symbols": ["class1$macrocall$3", {"literal":"/"}, "class1$macrocall$2"]},
398 | {"name": "class1", "symbols": ["class1$macrocall$1"], "postprocess": () => 'C0G'},
399 | {"name": "class1$macrocall$5", "symbols": ["C", "O", "G"]},
400 | {"name": "class1$macrocall$6", "symbols": ["N", "P", "O"]},
401 | {"name": "class1$macrocall$4", "symbols": ["class1$macrocall$5"]},
402 | {"name": "class1$macrocall$4", "symbols": ["class1$macrocall$6"]},
403 | {"name": "class1$macrocall$4", "symbols": ["class1$macrocall$5", {"literal":"/"}, "class1$macrocall$6"]},
404 | {"name": "class1$macrocall$4", "symbols": ["class1$macrocall$6", {"literal":"/"}, "class1$macrocall$5"]},
405 | {"name": "class1", "symbols": ["class1$macrocall$4"], "postprocess": () => 'C0G'},
406 | {"name": "class1$macrocall$8$string$1", "symbols": [{"literal":"1"}, {"literal":"0"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
407 | {"name": "class1$macrocall$8", "symbols": ["P", "class1$macrocall$8$string$1"]},
408 | {"name": "class1$macrocall$9", "symbols": ["M", {"literal":"7"}, "G"]},
409 | {"name": "class1$macrocall$7", "symbols": ["class1$macrocall$8"]},
410 | {"name": "class1$macrocall$7", "symbols": ["class1$macrocall$9"]},
411 | {"name": "class1$macrocall$7", "symbols": ["class1$macrocall$8", {"literal":"/"}, "class1$macrocall$9"]},
412 | {"name": "class1$macrocall$7", "symbols": ["class1$macrocall$9", {"literal":"/"}, "class1$macrocall$8"]},
413 | {"name": "class1", "symbols": ["class1$macrocall$7"], "postprocess": () => 'M7G'},
414 | {"name": "class1$macrocall$11$string$1", "symbols": [{"literal":"3"}, {"literal":"3"}], "postprocess": function joiner(d) {return d.join('');}},
415 | {"name": "class1$macrocall$11", "symbols": ["N", "class1$macrocall$11$string$1"]},
416 | {"name": "class1$macrocall$12", "symbols": ["H", {"literal":"2"}, "G"]},
417 | {"name": "class1$macrocall$10", "symbols": ["class1$macrocall$11"]},
418 | {"name": "class1$macrocall$10", "symbols": ["class1$macrocall$12"]},
419 | {"name": "class1$macrocall$10", "symbols": ["class1$macrocall$11", {"literal":"/"}, "class1$macrocall$12"]},
420 | {"name": "class1$macrocall$10", "symbols": ["class1$macrocall$12", {"literal":"/"}, "class1$macrocall$11"]},
421 | {"name": "class1", "symbols": ["class1$macrocall$10"], "postprocess": () => 'H2G'},
422 | {"name": "class1$macrocall$14$string$1", "symbols": [{"literal":"7"}, {"literal":"5"}], "postprocess": function joiner(d) {return d.join('');}},
423 | {"name": "class1$macrocall$14", "symbols": ["N", "class1$macrocall$14$string$1"]},
424 | {"name": "class1$macrocall$15", "symbols": ["L", {"literal":"2"}, "G"]},
425 | {"name": "class1$macrocall$13", "symbols": ["class1$macrocall$14"]},
426 | {"name": "class1$macrocall$13", "symbols": ["class1$macrocall$15"]},
427 | {"name": "class1$macrocall$13", "symbols": ["class1$macrocall$14", {"literal":"/"}, "class1$macrocall$15"]},
428 | {"name": "class1$macrocall$13", "symbols": ["class1$macrocall$15", {"literal":"/"}, "class1$macrocall$14"]},
429 | {"name": "class1", "symbols": ["class1$macrocall$13"], "postprocess": () => 'L2G'},
430 | {"name": "class1$macrocall$17$string$1", "symbols": [{"literal":"1"}, {"literal":"5"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
431 | {"name": "class1$macrocall$17", "symbols": ["N", "class1$macrocall$17$string$1"]},
432 | {"name": "class1$macrocall$18", "symbols": ["P", {"literal":"2"}, "H"]},
433 | {"name": "class1$macrocall$16", "symbols": ["class1$macrocall$17"]},
434 | {"name": "class1$macrocall$16", "symbols": ["class1$macrocall$18"]},
435 | {"name": "class1$macrocall$16", "symbols": ["class1$macrocall$17", {"literal":"/"}, "class1$macrocall$18"]},
436 | {"name": "class1$macrocall$16", "symbols": ["class1$macrocall$18", {"literal":"/"}, "class1$macrocall$17"]},
437 | {"name": "class1", "symbols": ["class1$macrocall$16"], "postprocess": () => 'P2H'},
438 | {"name": "class1$macrocall$20$string$1", "symbols": [{"literal":"2"}, {"literal":"2"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
439 | {"name": "class1$macrocall$20", "symbols": ["N", "class1$macrocall$20$string$1"]},
440 | {"name": "class1$macrocall$21", "symbols": ["R", {"literal":"2"}, "H"]},
441 | {"name": "class1$macrocall$19", "symbols": ["class1$macrocall$20"]},
442 | {"name": "class1$macrocall$19", "symbols": ["class1$macrocall$21"]},
443 | {"name": "class1$macrocall$19", "symbols": ["class1$macrocall$20", {"literal":"/"}, "class1$macrocall$21"]},
444 | {"name": "class1$macrocall$19", "symbols": ["class1$macrocall$21", {"literal":"/"}, "class1$macrocall$20"]},
445 | {"name": "class1", "symbols": ["class1$macrocall$19"], "postprocess": () => 'R2H'},
446 | {"name": "class1$macrocall$23$string$1", "symbols": [{"literal":"3"}, {"literal":"3"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
447 | {"name": "class1$macrocall$23", "symbols": ["N", "class1$macrocall$23$string$1"]},
448 | {"name": "class1$macrocall$24", "symbols": ["S", {"literal":"2"}, "H"]},
449 | {"name": "class1$macrocall$22", "symbols": ["class1$macrocall$23"]},
450 | {"name": "class1$macrocall$22", "symbols": ["class1$macrocall$24"]},
451 | {"name": "class1$macrocall$22", "symbols": ["class1$macrocall$23", {"literal":"/"}, "class1$macrocall$24"]},
452 | {"name": "class1$macrocall$22", "symbols": ["class1$macrocall$24", {"literal":"/"}, "class1$macrocall$23"]},
453 | {"name": "class1", "symbols": ["class1$macrocall$22"], "postprocess": () => 'S2H'},
454 | {"name": "class1$macrocall$26$string$1", "symbols": [{"literal":"4"}, {"literal":"7"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
455 | {"name": "class1$macrocall$26", "symbols": ["N", "class1$macrocall$26$string$1"]},
456 | {"name": "class1$macrocall$27", "symbols": ["T", {"literal":"2"}, "H"]},
457 | {"name": "class1$macrocall$25", "symbols": ["class1$macrocall$26"]},
458 | {"name": "class1$macrocall$25", "symbols": ["class1$macrocall$27"]},
459 | {"name": "class1$macrocall$25", "symbols": ["class1$macrocall$26", {"literal":"/"}, "class1$macrocall$27"]},
460 | {"name": "class1$macrocall$25", "symbols": ["class1$macrocall$27", {"literal":"/"}, "class1$macrocall$26"]},
461 | {"name": "class1", "symbols": ["class1$macrocall$25"], "postprocess": () => 'T2H'},
462 | {"name": "class1$macrocall$29$string$1", "symbols": [{"literal":"7"}, {"literal":"5"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
463 | {"name": "class1$macrocall$29", "symbols": ["N", "class1$macrocall$29$string$1"]},
464 | {"name": "class1$macrocall$30", "symbols": ["U", {"literal":"2"}, "J"]},
465 | {"name": "class1$macrocall$28", "symbols": ["class1$macrocall$29"]},
466 | {"name": "class1$macrocall$28", "symbols": ["class1$macrocall$30"]},
467 | {"name": "class1$macrocall$28", "symbols": ["class1$macrocall$29", {"literal":"/"}, "class1$macrocall$30"]},
468 | {"name": "class1$macrocall$28", "symbols": ["class1$macrocall$30", {"literal":"/"}, "class1$macrocall$29"]},
469 | {"name": "class1", "symbols": ["class1$macrocall$28"], "postprocess": () => 'U2J'},
470 | {"name": "class1$macrocall$32$string$1", "symbols": [{"literal":"1"}, {"literal":"0"}, {"literal":"0"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
471 | {"name": "class1$macrocall$32", "symbols": ["N", "class1$macrocall$32$string$1"]},
472 | {"name": "class1$macrocall$33", "symbols": ["Q", {"literal":"3"}, "K"]},
473 | {"name": "class1$macrocall$31", "symbols": ["class1$macrocall$32"]},
474 | {"name": "class1$macrocall$31", "symbols": ["class1$macrocall$33"]},
475 | {"name": "class1$macrocall$31", "symbols": ["class1$macrocall$32", {"literal":"/"}, "class1$macrocall$33"]},
476 | {"name": "class1$macrocall$31", "symbols": ["class1$macrocall$33", {"literal":"/"}, "class1$macrocall$32"]},
477 | {"name": "class1", "symbols": ["class1$macrocall$31"], "postprocess": () => 'Q3K'},
478 | {"name": "class1$macrocall$35$string$1", "symbols": [{"literal":"1"}, {"literal":"5"}, {"literal":"0"}, {"literal":"0"}], "postprocess": function joiner(d) {return d.join('');}},
479 | {"name": "class1$macrocall$35", "symbols": ["N", "class1$macrocall$35$string$1"]},
480 | {"name": "class1$macrocall$36", "symbols": ["P", {"literal":"3"}, "K"]},
481 | {"name": "class1$macrocall$34", "symbols": ["class1$macrocall$35"]},
482 | {"name": "class1$macrocall$34", "symbols": ["class1$macrocall$36"]},
483 | {"name": "class1$macrocall$34", "symbols": ["class1$macrocall$35", {"literal":"/"}, "class1$macrocall$36"]},
484 | {"name": "class1$macrocall$34", "symbols": ["class1$macrocall$36", {"literal":"/"}, "class1$macrocall$35"]},
485 | {"name": "class1", "symbols": ["class1$macrocall$34"], "postprocess": () => 'P3K'},
486 | {"name": "class2", "symbols": ["class2_letter", "class2_number", "class2_code"], "postprocess": d => d.join('').toUpperCase()},
487 | {"name": "class2_letter", "symbols": ["X"]},
488 | {"name": "class2_letter", "symbols": ["Y"]},
489 | {"name": "class2_letter", "symbols": ["Z"]},
490 | {"name": "class2_number", "symbols": [{"literal":"4"}]},
491 | {"name": "class2_number", "symbols": [{"literal":"5"}]},
492 | {"name": "class2_number", "symbols": [{"literal":"6"}]},
493 | {"name": "class2_number", "symbols": [{"literal":"7"}]},
494 | {"name": "class2_number", "symbols": [{"literal":"8"}]},
495 | {"name": "class2_number", "symbols": [{"literal":"9"}]},
496 | {"name": "class2_code", "symbols": ["P"]},
497 | {"name": "class2_code", "symbols": ["R"]},
498 | {"name": "class2_code", "symbols": ["S"]},
499 | {"name": "class2_code", "symbols": ["T"]},
500 | {"name": "class2_code", "symbols": ["U"]},
501 | {"name": "class2_code", "symbols": ["V"]},
502 | {"name": "tolerance$ebnf$1$subexpression$1", "symbols": ["plusMinus", "_"]},
503 | {"name": "tolerance$ebnf$1", "symbols": ["tolerance$ebnf$1$subexpression$1"], "postprocess": id},
504 | {"name": "tolerance$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
505 | {"name": "tolerance", "symbols": ["tolerance$ebnf$1", "decimal", "_", {"literal":"%"}], "postprocess": d => ({tolerance: d[1]})},
506 | {"name": "plusMinus$string$1", "symbols": [{"literal":"+"}, {"literal":"/"}, {"literal":"-"}], "postprocess": function joiner(d) {return d.join('');}},
507 | {"name": "plusMinus", "symbols": ["plusMinus$string$1"]},
508 | {"name": "plusMinus", "symbols": [{"literal":"±"}]},
509 | {"name": "plusMinus$string$2", "symbols": [{"literal":"+"}, {"literal":"-"}], "postprocess": function joiner(d) {return d.join('');}},
510 | {"name": "plusMinus", "symbols": ["plusMinus$string$2"]},
511 | {"name": "capacitance", "symbols": ["capacitanceNoFarad", "_", "farad"], "postprocess": id},
512 | {"name": "capacitanceNoFarad", "symbols": ["decimal", "_", "capacitanceRest"], "postprocess": capacitance},
513 | {"name": "capacitanceRest$ebnf$1", "symbols": ["int"], "postprocess": id},
514 | {"name": "capacitanceRest$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
515 | {"name": "capacitanceRest", "symbols": ["cMetricPrefix", "capacitanceRest$ebnf$1"]},
516 | {"name": "farad", "symbols": ["F"], "postprocess": nuller},
517 | {"name": "farad", "symbols": ["F", "A", "R", "A", "D"], "postprocess": nuller},
518 | {"name": "resistor$ebnf$1", "symbols": ["resistor_prefix"], "postprocess": id},
519 | {"name": "resistor$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
520 | {"name": "resistor$ebnf$2", "symbols": ["packageSize"], "postprocess": id},
521 | {"name": "resistor$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
522 | {"name": "resistor", "symbols": ["resistor$ebnf$1", "rSpecs", "resistance", "rSpecs", "resistor$ebnf$2", "rSpecs"]},
523 | {"name": "resistor$ebnf$3", "symbols": ["resistor_prefix"], "postprocess": id},
524 | {"name": "resistor$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
525 | {"name": "resistor$ebnf$4", "symbols": ["packageSize"], "postprocess": id},
526 | {"name": "resistor$ebnf$4", "symbols": [], "postprocess": function(d) {return null;}},
527 | {"name": "resistor", "symbols": ["resistor$ebnf$3", "rSpecs", "resistor$ebnf$4", "rSpecs", "resistance", "rSpecs"]},
528 | {"name": "resistor$ebnf$5", "symbols": ["resistanceNoR"], "postprocess": id},
529 | {"name": "resistor$ebnf$5", "symbols": [], "postprocess": function(d) {return null;}},
530 | {"name": "resistor$ebnf$6", "symbols": ["packageSize"], "postprocess": id},
531 | {"name": "resistor$ebnf$6", "symbols": [], "postprocess": function(d) {return null;}},
532 | {"name": "resistor", "symbols": ["resistor_prefix", "rSpecs", "resistor$ebnf$5", "rSpecs", "resistor$ebnf$6", "rSpecs"]},
533 | {"name": "resistor$ebnf$7", "symbols": ["packageSize"], "postprocess": id},
534 | {"name": "resistor$ebnf$7", "symbols": [], "postprocess": function(d) {return null;}},
535 | {"name": "resistor$ebnf$8", "symbols": ["resistanceNoR"], "postprocess": id},
536 | {"name": "resistor$ebnf$8", "symbols": [], "postprocess": function(d) {return null;}},
537 | {"name": "resistor", "symbols": ["resistor_prefix", "rSpecs", "resistor$ebnf$7", "rSpecs", "resistor$ebnf$8", "rSpecs"]},
538 | {"name": "resistor_prefix", "symbols": ["R"], "postprocess": nuller},
539 | {"name": "resistor_prefix", "symbols": ["R", "E", "S"], "postprocess": nuller},
540 | {"name": "resistor_prefix", "symbols": ["R", "E", "S", "I", "S", "T", "O", "R"], "postprocess": nuller},
541 | {"name": "rSpecs$ebnf$1", "symbols": []},
542 | {"name": "rSpecs$ebnf$1$subexpression$1", "symbols": ["_", "rSpec", "_"]},
543 | {"name": "rSpecs$ebnf$1", "symbols": ["rSpecs$ebnf$1", "rSpecs$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
544 | {"name": "rSpecs", "symbols": ["rSpecs$ebnf$1"]},
545 | {"name": "rSpecs", "symbols": ["__"]},
546 | {"name": "rSpec", "symbols": ["tolerance"]},
547 | {"name": "rSpec", "symbols": ["power_rating"]},
548 | {"name": "power_rating", "symbols": ["power_rating_decimal"]},
549 | {"name": "power_rating", "symbols": ["power_rating_fraction"]},
550 | {"name": "power_rating_fraction", "symbols": ["decimal", {"literal":"/"}, "decimal", "_", "watts"], "postprocess": d => {
551 | const [n1, _, n2] = d
552 | return {power_rating: n1 / n2}
553 | } },
554 | {"name": "power_rating_decimal", "symbols": ["decimal", "_", "powerMetricPrefix", "_", "watts"], "postprocess": d => {
555 | const [quantity, , metricPrefix] = d
556 | return {power_rating: parseFloat(`${quantity}${metricPrefix}`)}
557 | } },
558 | {"name": "watts", "symbols": ["watts_"], "postprocess": nuller},
559 | {"name": "watts_", "symbols": ["W"]},
560 | {"name": "watts_", "symbols": ["W", "A", "T", "T", "S"]},
561 | {"name": "resistance", "symbols": ["decimal", "_", "rest"], "postprocess": resistance},
562 | {"name": "rest$ebnf$1", "symbols": ["int"], "postprocess": id},
563 | {"name": "rest$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
564 | {"name": "rest$ebnf$2$subexpression$1", "symbols": ["_", "ohm"]},
565 | {"name": "rest$ebnf$2", "symbols": ["rest$ebnf$2$subexpression$1"], "postprocess": id},
566 | {"name": "rest$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
567 | {"name": "rest", "symbols": ["rMetricPrefix", "rest$ebnf$1", "rest$ebnf$2"]},
568 | {"name": "rest", "symbols": ["ohm"]},
569 | {"name": "resistanceNoR", "symbols": ["decimal"], "postprocess": d => ({resistance: d[0]})},
570 | {"name": "ohm", "symbols": ["ohm_"], "postprocess": nuller},
571 | {"name": "ohm_$subexpression$1$ebnf$1", "symbols": ["S"], "postprocess": id},
572 | {"name": "ohm_$subexpression$1$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
573 | {"name": "ohm_$subexpression$1", "symbols": ["ohm_$subexpression$1$ebnf$1"]},
574 | {"name": "ohm_", "symbols": ["O", "H", "M", "ohm_$subexpression$1"]},
575 | {"name": "ohm_", "symbols": [{"literal":"Ω"}]},
576 | {"name": "ohm_", "symbols": [{"literal":"Ω"}]},
577 | {"name": "led", "symbols": ["led_letters", "ledSpecs"]},
578 | {"name": "led", "symbols": ["ledSpecs", "led_letters"]},
579 | {"name": "led", "symbols": ["ledSpecs", "led_letters", "ledSpecs"]},
580 | {"name": "led_letters", "symbols": ["L", "E", "D"], "postprocess": nuller},
581 | {"name": "ledSpecs$ebnf$1$subexpression$1", "symbols": ["_", "ledSpec", "_"]},
582 | {"name": "ledSpecs$ebnf$1", "symbols": ["ledSpecs$ebnf$1$subexpression$1"]},
583 | {"name": "ledSpecs$ebnf$1$subexpression$2", "symbols": ["_", "ledSpec", "_"]},
584 | {"name": "ledSpecs$ebnf$1", "symbols": ["ledSpecs$ebnf$1", "ledSpecs$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
585 | {"name": "ledSpecs", "symbols": ["ledSpecs$ebnf$1"]},
586 | {"name": "ledSpec", "symbols": ["packageSize"]},
587 | {"name": "ledSpec", "symbols": ["color"]},
588 | {"name": "color", "symbols": ["color_name"], "postprocess": d => ({color: d[0]})},
589 | {"name": "color_name", "symbols": ["R", "E", "D"], "postprocess": () => 'red'},
590 | {"name": "color_name", "symbols": ["G", "R", "E", "E", "N"], "postprocess": () => 'green'},
591 | {"name": "color_name", "symbols": ["B", "L", "U", "E"], "postprocess": () => 'blue'},
592 | {"name": "color_name", "symbols": ["Y", "E", "L", "L", "O", "W"], "postprocess": () => 'yellow'},
593 | {"name": "color_name", "symbols": ["O", "R", "A", "N", "G", "E"], "postprocess": () => 'orange'},
594 | {"name": "color_name", "symbols": ["W", "H", "I", "T", "E"], "postprocess": () => 'white'},
595 | {"name": "color_name", "symbols": ["A", "M", "B", "E", "R"], "postprocess": () => 'amber'},
596 | {"name": "color_name", "symbols": ["C", "Y", "A", "N"], "postprocess": () => 'cyan'},
597 | {"name": "color_name", "symbols": ["P", "U", "R", "P", "L", "E"], "postprocess": () => 'purple'},
598 | {"name": "color_name", "symbols": ["Y", "E", "L", "L", "O", "W", "_", "G", "R", "E", "E", "N"], "postprocess": () => 'yellow green'},
599 | {"name": "powerMetricPrefix", "symbols": ["giga"], "postprocess": () => 'e9 '},
600 | {"name": "powerMetricPrefix", "symbols": ["mega"], "postprocess": () => 'e6 '},
601 | {"name": "powerMetricPrefix", "symbols": ["kilo"], "postprocess": () => 'e3 '},
602 | {"name": "powerMetricPrefix", "symbols": ["milli"], "postprocess": () => 'e-3 '},
603 | {"name": "powerMetricPrefix", "symbols": ["micro"], "postprocess": () => 'e-6 '},
604 | {"name": "powerMetricPrefix", "symbols": ["nano"], "postprocess": () => 'e-9 '},
605 | {"name": "powerMetricPrefix", "symbols": ["pico"], "postprocess": () => 'e-12'},
606 | {"name": "powerMetricPrefix", "symbols": ["femto"], "postprocess": () => 'e-15'},
607 | {"name": "powerMetricPrefix", "symbols": [], "postprocess": () => ''},
608 | {"name": "rMetricPrefix", "symbols": ["giga"], "postprocess": () => 'e9 '},
609 | {"name": "rMetricPrefix", "symbols": ["mega"], "postprocess": () => 'e6 '},
610 | {"name": "rMetricPrefix", "symbols": ["kilo"], "postprocess": () => 'e3 '},
611 | {"name": "rMetricPrefix", "symbols": ["R"], "postprocess": () => ''},
612 | {"name": "rMetricPrefix", "symbols": ["milli"], "postprocess": () => 'e-3 '},
613 | {"name": "rMetricPrefix", "symbols": ["micro"], "postprocess": () => 'e-6 '},
614 | {"name": "cMetricPrefix", "symbols": ["milli"], "postprocess": () => 'e-3 '},
615 | {"name": "cMetricPrefix", "symbols": ["micro"], "postprocess": () => 'e-6 '},
616 | {"name": "cMetricPrefix", "symbols": ["nano"], "postprocess": () => 'e-9 '},
617 | {"name": "cMetricPrefix", "symbols": ["pico"], "postprocess": () => 'e-12'},
618 | {"name": "cMetricPrefix", "symbols": [], "postprocess": () => ''}
619 | ]
620 | , ParserStart: "main"
621 | }
622 | if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') {
623 | module.exports = grammar;
624 | } else {
625 | window.grammar = grammar;
626 | }
627 | })();
628 |
--------------------------------------------------------------------------------
/src/grammar.ne:
--------------------------------------------------------------------------------
1 | @builtin "number.ne"
2 | @include "util.ne"
3 | @include "metric_prefix.ne"
4 | @include "package_size.ne"
5 |
6 | main -> component {% d => assignAll(filter(flatten(d))) %}
7 |
8 | component ->
9 | capacitor {% type('capacitor') %}
10 | | resistor {% type('resistor') %}
11 | | led {% type('led') %}
12 |
13 | @{%
14 | function type(t) {
15 | return d => [{type: t}].concat(d)
16 | }
17 | %}
18 |
19 |
20 | ## Capacitors ##
21 |
22 | # the description can come in any order
23 | # if it starts with 'c' or 'capacitor' then F or farad can be ommitted
24 | capacitor ->
25 | cSpecs capacitance cSpecs packageSize:? cSpecs
26 | | cSpecs packageSize:? cSpecs capacitance cSpecs
27 | | cap cSpecs packageSize:? cSpecs (capacitanceNoFarad | capacitance):? cSpecs
28 | | cap cSpecs (capacitanceNoFarad | capacitance):? cSpecs packageSize:? cSpecs
29 |
30 |
31 | cap -> C A:? P:? A:? C:? I:? T:? O:? R:? {% nuller %}
32 |
33 | cSpecs -> (_ cSpec _):* | __
34 |
35 | cSpec -> tolerance | characteristic | voltage_rating
36 |
37 | voltage_rating ->
38 | decimal _ voltageRest {% voltage_rating %}
39 |
40 | voltageRest -> V int:?
41 |
42 | @{%
43 | function voltage_rating(d, i, reject) {
44 | const [integral, , [v, fractional]] = d
45 | if (fractional) {
46 | if (/\./.test(integral.toString())) {
47 | return reject
48 | }
49 | var quantity = `${integral}.${fractional}`
50 | } else {
51 | var quantity = integral
52 | }
53 | return {voltage_rating: parseFloat(quantity)}
54 | }
55 | %}
56 |
57 | characteristic -> characteristic_ {% d => ({characteristic: d[0][0]}) %}
58 |
59 | # see https://en.wikipedia.org/wiki/Ceramic_capacitor#Class_1_ceramic_capacitor
60 | # https://en.wikipedia.org/wiki/Ceramic_capacitor#Class_2_ceramic_capacitor
61 | characteristic_ -> class1 | class2
62 |
63 | combine[X, Y] -> $X | $Y | $X "/" $Y | $Y "/" $X
64 | class1 ->
65 | combine[C "0" G, N P "0"] {% () => 'C0G' %}
66 | | combine[C O G, N P O] {% () => 'C0G' %}
67 | | combine[P "100", M "7" G] {% () => 'M7G' %}
68 | | combine[N "33", H "2" G] {% () => 'H2G' %}
69 | | combine[N "75", L "2" G] {% () => 'L2G' %}
70 | | combine[N "150", P "2" H] {% () => 'P2H' %}
71 | | combine[N "220", R "2" H] {% () => 'R2H' %}
72 | | combine[N "330", S "2" H] {% () => 'S2H' %}
73 | | combine[N "470", T "2" H] {% () => 'T2H' %}
74 | | combine[N "750", U "2" J] {% () => 'U2J' %}
75 | | combine[N "1000", Q "3" K] {% () => 'Q3K' %}
76 | | combine[N "1500", P "3" K] {% () => 'P3K' %}
77 |
78 | class2 -> class2_letter class2_number class2_code
79 | {% d => d.join('').toUpperCase() %}
80 | class2_letter -> X | Y | Z
81 | class2_number -> "4" | "5" | "6" | "7" | "8" | "9"
82 | class2_code -> P | R | S | T | U | V
83 |
84 | tolerance -> (plusMinus _):? decimal _ "%" {% d => ({tolerance: d[1]}) %}
85 |
86 | plusMinus -> "+/-" | "±" | "+-"
87 |
88 | capacitance -> capacitanceNoFarad _ farad {% id %}
89 | capacitanceNoFarad -> decimal _ capacitanceRest {% capacitance %}
90 |
91 | capacitanceRest -> cMetricPrefix int:?
92 |
93 | @{%
94 | function capacitance(d, i, reject) {
95 | const [integral, , [metricPrefix, fractional]] = d
96 | if (fractional) {
97 | if (/\./.test(integral) || metricPrefix === "") {
98 | return reject
99 | }
100 | var quantity = `${integral}.${fractional}`
101 | } else {
102 | if (/1005|201|402|603|805|1206/.test(integral.toString())) {
103 | return reject
104 | }
105 | var quantity = integral
106 | }
107 | return {capacitance: parseFloat(`${quantity}${metricPrefix}`)}
108 | }
109 | %}
110 |
111 | farad -> F {% nuller %} | F A R A D {% nuller %}
112 |
113 |
114 | ## Resistors ##
115 |
116 | # the description can come in any order
117 | # if it starts with 'r' or 'resistor' then k, R etc can be ommitted
118 | resistor ->
119 | resistor_prefix:? rSpecs resistance rSpecs packageSize:? rSpecs
120 | | resistor_prefix:? rSpecs packageSize:? rSpecs resistance rSpecs
121 | | resistor_prefix rSpecs resistanceNoR:? rSpecs packageSize:? rSpecs
122 | | resistor_prefix rSpecs packageSize:? rSpecs resistanceNoR:? rSpecs
123 |
124 | resistor_prefix -> R {% nuller %} | R E S {% nuller %} | R E S I S T O R {% nuller %}
125 |
126 | rSpecs -> (_ rSpec _):* | __
127 |
128 | rSpec -> tolerance | power_rating
129 |
130 | power_rating -> power_rating_decimal | power_rating_fraction
131 |
132 | power_rating_fraction -> decimal "/" decimal _ watts {% d => {
133 | const [n1, _, n2] = d
134 | return {power_rating: n1 / n2}
135 | } %}
136 |
137 | power_rating_decimal -> decimal _ powerMetricPrefix _ watts {% d => {
138 | const [quantity, , metricPrefix] = d
139 | return {power_rating: parseFloat(`${quantity}${metricPrefix}`)}
140 | } %}
141 |
142 | watts -> watts_ {% nuller %}
143 | watts_ -> W | W A T T S
144 |
145 | resistance ->
146 | decimal _ rest {% resistance %}
147 |
148 | rest -> rMetricPrefix int:? (_ ohm):? | ohm
149 |
150 | # just a number, no R, K, ohm etc
151 | resistanceNoR -> decimal {% d => ({resistance: d[0]}) %}
152 |
153 | @{%
154 | function resistance(d, i, reject) {
155 | const [integral, , [metricPrefix, fractional, ohm]] = d
156 | if (fractional) {
157 | if (/\./.test(integral.toString())) {
158 | return reject
159 | }
160 | var quantity = `${integral}.${fractional}`
161 | } else {
162 | if (/1005|201|402|603|805|1206/.test(integral.toString())) {
163 | return reject
164 | }
165 | var quantity = integral
166 | }
167 | return {resistance: parseFloat(`${quantity}${metricPrefix}`)}
168 | }
169 | %}
170 |
171 | ohm -> ohm_ {% nuller %}
172 | ohm_ -> O H M (S:?) | "Ω" | "Ω"
173 |
174 |
175 | ## LEDs ##
176 |
177 | led ->
178 | led_letters ledSpecs
179 | | ledSpecs led_letters
180 | | ledSpecs led_letters ledSpecs
181 |
182 | led_letters -> L E D {% nuller %}
183 |
184 | ledSpecs -> (_ ledSpec _):+
185 |
186 | ledSpec -> packageSize | color
187 |
188 | color -> color_name {% d => ({color: d[0]}) %}
189 | color_name ->
190 | R E D {% () => 'red' %}
191 | | G R E E N {% () => 'green' %}
192 | | B L U E {% () => 'blue' %}
193 | | Y E L L O W {% () => 'yellow' %}
194 | | O R A N G E {% () => 'orange' %}
195 | | W H I T E {% () => 'white' %}
196 | | A M B E R {% () => 'amber' %}
197 | | C Y A N {% () => 'cyan' %}
198 | | P U R P L E {% () => 'purple' %}
199 | | Y E L L O W _ G R E E N {% () => 'yellow green' %}
200 |
201 |
202 | ## Metric Prefixes ##
203 |
204 | powerMetricPrefix ->
205 | giga {% () => 'e9 ' %}
206 | | mega {% () => 'e6 ' %}
207 | | kilo {% () => 'e3 ' %}
208 | | milli {% () => 'e-3 ' %}
209 | | micro {% () => 'e-6 ' %}
210 | | nano {% () => 'e-9 ' %}
211 | | pico {% () => 'e-12' %}
212 | | femto {% () => 'e-15' %}
213 | | null {% () => '' %}
214 |
215 | rMetricPrefix ->
216 | giga {% () => 'e9 ' %}
217 | | mega {% () => 'e6 ' %}
218 | | kilo {% () => 'e3 ' %}
219 | | R {% () => '' %}
220 | | milli {% () => 'e-3 ' %}
221 | | micro {% () => 'e-6 ' %}
222 |
223 | cMetricPrefix ->
224 | milli {% () => 'e-3 ' %}
225 | | micro {% () => 'e-6 ' %}
226 | | nano {% () => 'e-9 ' %}
227 | | pico {% () => 'e-12' %}
228 | | null {% () => '' %}
229 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | const parse = require('./parse')
2 | const matchCPL = require('./match_cpl')
3 | module.exports = {parse, matchCPL}
4 |
--------------------------------------------------------------------------------
/src/letters.ne:
--------------------------------------------------------------------------------
1 | A -> "A" | "a"
2 | B -> "B" | "b"
3 | C -> "C" | "c"
4 | D -> "D" | "d"
5 | E -> "E" | "e"
6 | F -> "F" | "f"
7 | G -> "G" | "g"
8 | H -> "H" | "h"
9 | I -> "I" | "i"
10 | J -> "J" | "j"
11 | K -> "K" | "k"
12 | L -> "L" | "l"
13 | M -> "M" | "m"
14 | N -> "N" | "n"
15 | O -> "O" | "o"
16 | P -> "P" | "p"
17 | Q -> "Q" | "q"
18 | R -> "R" | "r"
19 | S -> "S" | "s"
20 | T -> "T" | "t"
21 | U -> "U" | "u"
22 | V -> "V" | "v"
23 | W -> "W" | "w"
24 | X -> "X" | "x"
25 | Y -> "Y" | "y"
26 | Z -> "Z" | "z"
27 |
--------------------------------------------------------------------------------
/src/match_cpl.js:
--------------------------------------------------------------------------------
1 | const resistors = require('./cpl_resistors')
2 | const capacitors = require('./cpl_capacitors')
3 | const leds = require('./cpl_leds')
4 |
5 | function matchCPL(component) {
6 | component = component || {}
7 | switch (component.type) {
8 | case 'capacitor':
9 | return matchCapacitor(component)
10 | case 'resistor':
11 | return matchResistor(component)
12 | case 'led':
13 | return matchLED(component)
14 | }
15 | return []
16 | }
17 |
18 | function matchResistor(c) {
19 | return resistors.reduce((prev, cpl) => {
20 | const resistance = cpl.resistance === c.resistance
21 | const size = c.size == null || cpl.size === c.size
22 | const tolerance = c.tolerance == null || cpl.tolerance <= c.tolerance
23 | const power_rating = c.power_rating == null
24 | || cpl.power_rating >= c.power_rating
25 | if (resistance && size && tolerance && power_rating) {
26 | return prev.concat([cpl.cplid])
27 | }
28 | return prev
29 | }, [])
30 | }
31 |
32 | function matchCapacitor(c) {
33 | return capacitors.reduce((prev, cpl) => {
34 | const capacitance = cpl.capacitance === c.capacitance
35 | const size = c.size == null || cpl.size === c.size
36 | const characteristic = c.characteristic == null
37 | || cpl.characteristic === c.characteristic
38 | const tolerance = c.tolerance == null || cpl.tolerance <= c.tolerance
39 | const voltage_rating = c.voltage_rating == null
40 | || cpl.voltage_rating >= c.voltage_rating
41 | if (capacitance && size && characteristic && tolerance && voltage_rating) {
42 | return prev.concat([cpl.cplid])
43 | }
44 | return prev
45 | }, [])
46 | }
47 |
48 | function matchLED(c) {
49 | return leds.reduce((prev, cpl) => {
50 | const color = c.color == null || cpl.color === c.color
51 | const size = c.size == null || cpl.size === c.size
52 | if (color && size) {
53 | return prev.concat([cpl.cplid])
54 | }
55 | return prev
56 | }, [])
57 | }
58 |
59 | module.exports = matchCPL
60 |
--------------------------------------------------------------------------------
/src/metric_prefix.ne:
--------------------------------------------------------------------------------
1 | @include "letters.ne"
2 |
3 | exa -> "E" | E X A
4 | peta -> "P" | P E T A
5 | tera -> "T" | T E R A
6 | giga -> "G" | G I G | G I G A
7 | mega -> "M" | M E G | M E G A
8 | kilo -> K | K I L O
9 | hecto -> "h" | H E C T O
10 | deci -> "d" | D E C I
11 | centi -> "c" | C E N T I
12 | milli -> "m" | M I L L I
13 | micro ->
14 | U
15 | | [\u03BC]
16 | | [\u00B5]
17 | | [\uD835] [\uDECD]
18 | | [\uD835] [\uDF07]
19 | | [\uD835] [\uDF41]
20 | | [\uD835] [\uDF7B]
21 | | [\uD835] [\uDFB5]
22 | | M I C R O
23 | nano -> N | N A N | N A N O
24 | pico -> P | P I C O
25 | femto -> "f" | F E M T O
26 | atto -> "a" | A T T O
27 |
--------------------------------------------------------------------------------
/src/package_size.ne:
--------------------------------------------------------------------------------
1 | packageSize -> _packageSize {% d => ({size: filter(flatten(d))[0]}) %}
2 | _packageSize -> _imperialSize | _metricSize
3 | _imperialSize ->
4 | "01005"
5 | | "0201"
6 | | "0402"
7 | | "0603"
8 | | "0805"
9 | | "1008"
10 | | "1206"
11 | | "1210"
12 | | "1806"
13 | | "2010"
14 | | "2512"
15 |
16 | _metricSize ->
17 | __metricSize [\s]:* M E T R I C {% d => toImperial[d[0]] %}
18 | | M E T R I C [\s]:* __metricSize {% d => toImperial[d[7]] %}
19 | | unambigiousMetricSize {% d => toImperial[d[0]] %}
20 | @{%
21 | const toImperial = {
22 | '0402': '01005',
23 | '0603': '0201',
24 | '1005': '0402',
25 | '1608': '0603',
26 | '2012': '0805',
27 | '2520': '1008',
28 | '3216': '1206',
29 | '3225': '1210',
30 | '4516': '1806',
31 | '4532': '1812',
32 | '5025': '2010',
33 | '6332': '2512',
34 | }
35 | %}
36 |
37 | unambigiousMetricSize ->
38 | "1005"
39 | | "1608"
40 | | "2012"
41 | | "2520"
42 | | "3216"
43 | | "3225"
44 | | "4516"
45 | | "5025"
46 | | "6332"
47 |
48 | __metricSize ->
49 | unambigiousMetricSize
50 | | "0402"
51 | | "0603"
52 |
53 | M -> "M" | "m"
54 | E -> "E" | "e"
55 | T -> "T" | "t"
56 | R -> "R" | "r"
57 | I -> "I" | "i"
58 | C -> "C" | "c"
59 |
--------------------------------------------------------------------------------
/src/parse.js:
--------------------------------------------------------------------------------
1 | const nearley = require('nearley')
2 | const grammar = require('./grammar')
3 |
4 | function parse(str) {
5 | const parser = new nearley.Parser(
6 | grammar.ParserRules,
7 | grammar.ParserStart,
8 | {keepHistory: true}
9 | )
10 | const words = str.split(' ')
11 | let info = parser.save()
12 | return words.reduce((prev, word) => {
13 | word = word.replace(/,|;/, '') + ' '
14 | //if it fails, roll it back
15 | try {
16 | parser.feed(word)
17 | } catch(e) {
18 | parser.restore(info)
19 | }
20 | info = parser.save()
21 | //return the latest valid result
22 | return parser.results[0] || prev
23 | }, {})
24 | }
25 |
26 | module.exports = parse
27 |
--------------------------------------------------------------------------------
/src/util.ne:
--------------------------------------------------------------------------------
1 | #whitespace
2 | _ -> [\s]:* {% () => null %}
3 | __ -> [\s]:+ {% () => null %}
4 |
5 | @{%
6 | const flatten = require('./flatten')
7 |
8 | const filter = d => d.filter(t => t !== null)
9 |
10 | const assignAll = objs => objs.reduce((prev, obj) => Object.assign(prev, obj))
11 |
12 | const nuller = () => null
13 | %}
14 |
--------------------------------------------------------------------------------
/test/test_grammar.js:
--------------------------------------------------------------------------------
1 | const nearley = require('nearley')
2 | const assert = require('better-assert')
3 |
4 | const grammar = require('../lib/grammar')
5 |
6 | describe('grammar', () => {
7 | let p
8 | beforeEach(() => {
9 | p = new nearley.Parser(grammar.ParserRules, grammar.ParserStart)
10 | })
11 |
12 | it('parses', () => {
13 | p.feed('1uF 0603')
14 | assert(p.results.length > 0, 'has no result')
15 | })
16 |
17 | it('parses tolerance', () => {
18 | p.feed('1uF 0603 25%')
19 | assert(p.results.length > 0, 'has no result')
20 | })
21 |
22 | it('parses tolerance 2', () => {
23 | p.feed('1uF 0603 +/-30%')
24 | assert(p.results.length > 0, 'has no result')
25 | })
26 |
27 | it('parses tolerance 3', () => {
28 | p.feed('1uF 0603 ±10%')
29 | assert(p.results.length > 0, 'has no result')
30 | })
31 |
32 | it('can have things in any order', () => {
33 | p.feed('25% 0603 1uF')
34 | assert(p.results.length > 0, 'has no result')
35 | })
36 |
37 | it('can have things in any order 2', () => {
38 | p.feed('25% 1uF 0603')
39 | assert(p.results.length > 0, 'has no result')
40 | })
41 |
42 | it('can have things in any order 3', () => {
43 | p.feed('1uF 25% 0603')
44 | assert(p.results.length > 0, 'has no result')
45 | })
46 |
47 | it('rejects multiple decimal points', () => {
48 | try {
49 | p.feed('1.2.3uF 25% 0603')
50 | } catch (e) {
51 | assert(e.message.match(/Unexpected/), 'got a different error message')
52 | }
53 | assert(p.results == null, 'got a result')
54 | })
55 |
56 | it('parses voltage rating', () => {
57 | p.feed('1uF 25V')
58 | assert(p.results.length > 0, 'has no result')
59 | })
60 |
61 | it("doesn't match a random number to a resistor", () => {
62 | p.feed('0603 5')
63 | assert(p.results.length === 0, 'has a result')
64 | })
65 |
66 | })
67 |
--------------------------------------------------------------------------------
/test/test_match_cpl.js:
--------------------------------------------------------------------------------
1 | const assert = require('better-assert')
2 |
3 | const {parse, matchCPL} = require('../lib/index')
4 |
5 | describe('match CPL', () => {
6 | it('matches a capacitor', () => {
7 | const c = parse('0.1uF 0805 X7R')
8 | const cpl_ids = matchCPL(c)
9 | assert(cpl_ids.length > 0)
10 | })
11 | it('matches a resistor', () => {
12 | const c = parse('10k 0805')
13 | const cpl_ids = matchCPL(c)
14 | assert(cpl_ids.length > 0)
15 | })
16 | it("doesn't match a redonculous power resistor", () => {
17 | const c = parse('10k 0805 10000W')
18 | const cpl_ids = matchCPL(c)
19 | assert(cpl_ids.length === 0)
20 | })
21 | it("matches an 0603 red LED", () => {
22 | const c = parse('LED red 0603')
23 | const cpl_ids = matchCPL(c)
24 | assert(cpl_ids.length > 0)
25 | })
26 | it('returns [] on invalid input', () => {
27 | assert(matchCPL().length === 0)
28 | assert(matchCPL(null).length === 0)
29 | assert(matchCPL(undefined).length === 0)
30 | assert(matchCPL({}).length === 0)
31 | assert(matchCPL({whatever:1}).length === 0)
32 | assert(matchCPL(['whatever', 2]).length === 0)
33 | })
34 | })
35 |
--------------------------------------------------------------------------------
/test/test_parse.js:
--------------------------------------------------------------------------------
1 | const assert = require('better-assert')
2 |
3 | const {parse} = require('../lib/index')
4 |
5 | describe('parsing', () => {
6 | it("doesn't parse nonsense", () => {
7 | const c = parse('this is total rubbish')
8 | assert(c.type == null)
9 | })
10 | it('returns empty object on empty', () => {
11 | assert(parse('').type == null)
12 | })
13 | })
14 |
15 | describe('SMD Capacitors', () => {
16 | it('parses a capacitor', () => {
17 | const c = parse('2uF 0603')
18 | assert(c.type === 'capacitor')
19 | assert(c.capacitance === 2e-6, 'capacitance value is wrong')
20 | assert(c.size === '0603', 'size is wrong')
21 | })
22 | it("doesn't parse nonsense", () => {
23 | const c = parse('this is total rubbish')
24 | assert(c.type == null)
25 | })
26 | it('parses tolerance', () => {
27 | const c = parse('2uF 0603 30%')
28 | assert(c.type === 'capacitor')
29 | assert(c.capacitance === 2e-6, 'capacitance value is wrong')
30 | assert(c.size === '0603', 'size is wrong')
31 | assert(c.tolerance === 30, 'tolerance is wrong')
32 | })
33 | it('parses +/- in tolerance', () => {
34 | const c = parse('2uF 0603 +/-30%')
35 | assert(c.type === 'capacitor')
36 | assert(c.capacitance === 2e-6, 'capacitance value is wrong')
37 | assert(c.size === '0603', 'size is wrong')
38 | assert(c.tolerance === 30, 'tolerance is wrong')
39 | })
40 | it('parses ± in tolerance', () => {
41 | const c = parse('2uF 0603 ±30%')
42 | assert(c.type === 'capacitor')
43 | assert(c.capacitance === 2e-6, 'capacitance value is wrong')
44 | assert(c.size === '0603', 'size is wrong')
45 | assert(c.tolerance === 30, 'tolerance is wrong')
46 | })
47 | it('parses +- in tolerance', () => {
48 | const c = parse('2uF 0603 +-30%')
49 | assert(c.type === 'capacitor')
50 | assert(c.capacitance === 2e-6, 'capacitance value is wrong')
51 | assert(c.size === '0603', 'size is wrong')
52 | assert(c.tolerance === 30, 'tolerance is wrong')
53 | })
54 | it('parses all the various ways of saying micro', () => {
55 | const descriptions = [
56 | '10uF 0402',
57 | '10 micro Farad 0402',
58 | '10𝛍F 0402',
59 | '10𝜇F 0402',
60 | '10𝝁 F 0402',
61 | '10 𝝻F 0402',
62 | '10𝞵F 0402',
63 | ]
64 | descriptions.forEach(d => {
65 | const c = parse(d)
66 | assert(c.type === 'capacitor')
67 | assert(c.capacitance === 10e-6, 'capacitance is wrong')
68 | assert(c.size === '0402', 'size is wrong')
69 | })
70 | })
71 | it('ignores extra words', () => {
72 | const c = parse('100nF 0603 kajdlkja alkdjlkajd')
73 | assert(c.type === 'capacitor')
74 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
75 | assert(c.size === '0603', 'size is wrong')
76 | })
77 | it('ignores extra words 2', () => {
78 | const c = parse('adjalkjd 100nF akjdlkjda 0603 kajdlkja alkdjlkajd')
79 | assert(c.type === 'capacitor')
80 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
81 | assert(c.size === '0603', 'size is wrong')
82 | })
83 | it('ignores extra words 3', () => {
84 | const c = parse('capacitor 100nF 0603, warehouse 5')
85 | assert(c.type === 'capacitor')
86 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
87 | assert(c.size === '0603', 'size is wrong')
88 | })
89 | it('ignores extra words 4', () => {
90 | const c = parse('adjalkjd 0603 akjdlkjda 100nF kajdlkja alkdjlkajd')
91 | assert(c.type === 'capacitor')
92 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
93 | assert(c.size === '0603', 'size is wrong')
94 | })
95 | it('parses 1n5F', () => {
96 | const c = parse('1n5F 0603 X7R')
97 | assert(c.type === 'capacitor')
98 | assert(c.capacitance === 1.5e-9, 'capacitance is wrong')
99 | assert(c.size === '0603', 'size is wrong')
100 | assert(c.characteristic === 'X7R', 'characteristic is wrong')
101 | })
102 | it('parses 100NF', () => {
103 | const c = parse('100NF 0603 X7R')
104 | assert(c.type === 'capacitor')
105 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
106 | assert(c.size === '0603', 'size is wrong')
107 | assert(c.characteristic === 'X7R', 'characteristic is wrong')
108 | })
109 | it('parses 100UF', () => {
110 | const c = parse('100UF 0603 X7R')
111 | assert(c.type === 'capacitor')
112 | assert(c.capacitance === 100e-6, 'capacitance is wrong')
113 | assert(c.size === '0603', 'size is wrong')
114 | assert(c.characteristic === 'X7R', 'characteristic is wrong')
115 | })
116 | it('parses characteristic X7R', () => {
117 | const c = parse('100nF 0603 X7R')
118 | assert(c.type === 'capacitor')
119 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
120 | assert(c.size === '0603', 'size is wrong')
121 | assert(c.characteristic === 'X7R', 'characteristic is wrong')
122 | })
123 | it('parses characteristic x7r', () => {
124 | const c = parse('100nF 0603 x7r')
125 | assert(c.type === 'capacitor')
126 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
127 | assert(c.size === '0603', 'size is wrong')
128 | assert(c.characteristic === 'X7R', 'characteristic is wrong')
129 | })
130 | it('parses characteristic Z5U', () => {
131 | const c = parse('100nF 0603 Z5U')
132 | assert(c.type === 'capacitor')
133 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
134 | assert(c.size === '0603', 'size is wrong')
135 | assert(c.characteristic === 'Z5U', 'characteristic is wrong')
136 | })
137 | it('parses characteristic Y5V', () => {
138 | const c = parse('100nF 0603 Y5V')
139 | assert(c.type === 'capacitor')
140 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
141 | assert(c.size === '0603', 'size is wrong')
142 | assert(c.characteristic === 'Y5V', 'characteristic is wrong')
143 | })
144 | it('parses characteristic C0G', () => {
145 | const c = parse('100nF 0603 C0G')
146 | assert(c.type === 'capacitor')
147 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
148 | assert(c.size === '0603', 'size is wrong')
149 | assert(c.characteristic === 'C0G', 'characteristic is wrong')
150 | })
151 | it('parses characteristic NPO', () => {
152 | const c = parse('100nF 0603 NP0')
153 | assert(c.type === 'capacitor')
154 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
155 | assert(c.size === '0603', 'size is wrong')
156 | assert(c.characteristic === 'C0G', 'characteristic is wrong')
157 | })
158 | it('parses characteristic np0', () => {
159 | const c = parse('100nF 0603 NP0')
160 | assert(c.type === 'capacitor')
161 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
162 | assert(c.size === '0603', 'size is wrong')
163 | assert(c.characteristic === 'C0G', 'characteristic is wrong')
164 | })
165 | it('parses characteristic c0g', () => {
166 | const c = parse('100nF 0603 c0g')
167 | assert(c.type === 'capacitor')
168 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
169 | assert(c.size === '0603', 'size is wrong')
170 | assert(c.characteristic === 'C0G', 'characteristic is wrong')
171 | })
172 | it('parses characteristic cog', () => {
173 | const c = parse('100nF 0603 cog')
174 | assert(c.type === 'capacitor')
175 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
176 | assert(c.size === '0603', 'size is wrong')
177 | assert(c.characteristic === 'C0G', 'characteristic is wrong')
178 | })
179 | it('parses characteristic npO', () => {
180 | const c = parse('100nF 0603 npO')
181 | assert(c.type === 'capacitor')
182 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
183 | assert(c.size === '0603', 'size is wrong')
184 | assert(c.characteristic === 'C0G', 'characteristic is wrong')
185 | })
186 | it('parses characteristic COG', () => {
187 | const c = parse('100nF 0603 COG')
188 | assert(c.type === 'capacitor')
189 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
190 | assert(c.size === '0603', 'size is wrong')
191 | assert(c.characteristic === 'C0G', 'characteristic is wrong')
192 | })
193 | it('parses characteristic C0G/NP0', () => {
194 | const c = parse('100nF 0603 C0G/NP0')
195 | assert(c.type === 'capacitor')
196 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
197 | assert(c.size === '0603', 'size is wrong')
198 | assert(c.characteristic === 'C0G', 'characteristic is wrong')
199 | })
200 | it('parses without metric prefix', () => {
201 | const c = parse('1F 0603 25V')
202 | assert(c.type === 'capacitor')
203 | assert(c.capacitance === 1, 'capacitance is wrong')
204 | assert(c.size === '0603', 'size is wrong')
205 | assert(c.voltage_rating === 25, 'rating is wrong')
206 | })
207 | it('parses lower case f as farad', () => {
208 | const c = parse('1f 0603 25V')
209 | assert(c.type === 'capacitor')
210 | assert(c.capacitance === 1, 'capacitance is wrong')
211 | })
212 | it('parses "Farad" as farad', () => {
213 | const c = parse('1 Farad 0603 25V')
214 | assert(c.type === 'capacitor')
215 | assert(c.capacitance === 1, 'capacitance is wrong')
216 | })
217 | it('parses voltage rating', () => {
218 | const c = parse('100nF 0603 25V')
219 | assert(c.type === 'capacitor')
220 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
221 | assert(c.size === '0603', 'size is wrong')
222 | assert(c.voltage_rating === 25, 'rating is wrong')
223 | })
224 | it('parses 6v3', () => {
225 | const c = parse('100nF 0603 6v3')
226 | assert(c.type === 'capacitor')
227 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
228 | assert(c.size === '0603', 'size is wrong')
229 | assert(c.voltage_rating === 6.3, 'rating is wrong')
230 | })
231 | it('parses 6V3', () => {
232 | const c = parse('100nF 0603 6V3')
233 | assert(c.type === 'capacitor')
234 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
235 | assert(c.size === '0603', 'size is wrong')
236 | assert(c.voltage_rating === 6.3, 'rating is wrong')
237 | })
238 | it('parses 6.3V', () => {
239 | const c = parse('100nF 0603 6.3V')
240 | assert(c.type === 'capacitor')
241 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
242 | assert(c.size === '0603', 'size is wrong')
243 | assert(c.voltage_rating === 6.3, 'rating is wrong')
244 | })
245 | it('parses 6.3v', () => {
246 | const c = parse('100nF 0603 6.3v')
247 | assert(c.type === 'capacitor')
248 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
249 | assert(c.size === '0603', 'size is wrong')
250 | assert(c.voltage_rating === 6.3, 'rating is wrong')
251 | })
252 | it('parses voltage rating with small v and space', () => {
253 | const c = parse('100nF 0603 25 v')
254 | assert(c.type === 'capacitor')
255 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
256 | assert(c.size === '0603', 'size is wrong')
257 | assert(c.voltage_rating === 25, 'rating is wrong')
258 | })
259 | it('takes a hint', () => {
260 | const c = parse('C 100n 0603')
261 | assert(c.type === 'capacitor')
262 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
263 | assert(c.size === '0603', 'size is wrong')
264 | })
265 | it('takes a hint 2', () => {
266 | const c = parse('Capacitor 100n 0603')
267 | assert(c.type === 'capacitor')
268 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
269 | assert(c.size === '0603', 'size is wrong')
270 | })
271 | it('takes a hint 3', () => {
272 | const c = parse('cap 100n 0603')
273 | assert(c.type === 'capacitor')
274 | assert(c.capacitance === 100e-9, 'capacitance is wrong')
275 | assert(c.size === '0603', 'size is wrong')
276 | })
277 | it('parses 0.0001F', () => {
278 | const c = parse('0603 0.0001F')
279 | assert(c.type === 'capacitor')
280 | assert(c.capacitance === 0.0001, 'capacitance is wrong')
281 | assert(c.size === '0603', 'size is wrong')
282 | })
283 | it('parses 0.0001 F', () => {
284 | const c = parse('0603 0.0001 F')
285 | assert(c.type === 'capacitor')
286 | assert(c.capacitance === 0.0001, 'capacitance is wrong')
287 | assert(c.size === '0603', 'size is wrong')
288 | })
289 | it('parses 0.1mF', () => {
290 | const c = parse('0603 0.1mF')
291 | assert(c.type === 'capacitor')
292 | assert(c.capacitance === 0.0001, 'capacitance is wrong')
293 | assert(c.size === '0603', 'size is wrong')
294 | })
295 | it("doesn't accidentally parse 01005 as value", () => {
296 | const c = parse('capacitor 01005')
297 | assert(c.type === 'capacitor')
298 | assert(c.resistance == null, 'resistance value is wrong')
299 | assert(c.size === '01005', 'size is wrong')
300 | })
301 | it("doesn't accidentally parse 0201 as value", () => {
302 | const c = parse('capacitor 0201')
303 | assert(c.type === 'capacitor')
304 | assert(c.resistance == null, 'resistance value is wrong')
305 | assert(c.size === '0201', 'size is wrong')
306 | })
307 | it("doesn't accidentally parse 0402 as value", () => {
308 | const c = parse('capacitor 0402')
309 | assert(c.type === 'capacitor')
310 | assert(c.resistance == null, 'resistance value is wrong')
311 | assert(c.size === '0402', 'size is wrong')
312 | })
313 | it("doesn't accidentally parse 0603 as value", () => {
314 | const c = parse('capacitor 0603')
315 | assert(c.type === 'capacitor')
316 | assert(c.resistance == null, 'resistance value is wrong')
317 | assert(c.size === '0603', 'size is wrong')
318 | })
319 | it("doesn't accidentally parse 0805 as value", () => {
320 | const c = parse('capacitor 0805')
321 | assert(c.type === 'capacitor')
322 | assert(c.resistance == null, 'resistance value is wrong')
323 | assert(c.size === '0805', 'size is wrong')
324 | })
325 | it("doesn't accidentally parse 1206 as value", () => {
326 | const c = parse('capacitor 1206')
327 | assert(c.type === 'capacitor')
328 | assert(c.resistance == null, 'resistance value is wrong')
329 | assert(c.size === '1206', 'size is wrong')
330 | })
331 | })
332 |
333 | describe('SMD Resistors', () => {
334 | it('parses a resistor', () => {
335 | const c = parse('1k 0603')
336 | assert(c.type === 'resistor')
337 | assert(c.resistance === 1000, 'resistance value is wrong')
338 | assert(c.size === '0603', 'size is wrong')
339 | })
340 | it('takes a hint', () => {
341 | const c = parse('resistor 100')
342 | assert(c.type === 'resistor')
343 | assert(c.resistance === 100, 'resistance value is wrong')
344 | })
345 | it('takes a hint 2', () => {
346 | const c = parse('r 10000 0805')
347 | assert(c.type === 'resistor')
348 | assert(c.resistance === 10000, 'resistance value is wrong')
349 | })
350 | it('takes a hint 3', () => {
351 | const c = parse('res or whatever 1')
352 | assert(c.type === 'resistor')
353 | assert(c.resistance === 1, 'resistance value is wrong')
354 | })
355 | it('parses "1k ohm"', () => {
356 | const c = parse('1k ohm 0603')
357 | assert(c.type === 'resistor')
358 | assert(c.resistance === 1000, 'resistance value is wrong')
359 | assert(c.size === '0603', 'size is wrong')
360 | })
361 | it('parses "1 ohm"', () => {
362 | const c = parse('1 ohm 0402')
363 | assert(c.type === 'resistor')
364 | assert(c.resistance === 1, 'resistance value is wrong')
365 | assert(c.size === '0402', 'size is wrong')
366 | })
367 | it('parses "1k ohms"', () => {
368 | const c = parse('1k ohms 0603')
369 | assert(c.type === 'resistor')
370 | assert(c.resistance === 1000, 'resistance value is wrong')
371 | assert(c.size === '0603', 'size is wrong')
372 | })
373 | it('parses "1MEG"', () => {
374 | const c = parse('1MEG 0603')
375 | assert(c.type === 'resistor')
376 | assert(c.resistance === 1000000, 'resistance value is wrong')
377 | assert(c.size === '0603', 'size is wrong')
378 | })
379 | it('parses "1M"', () => {
380 | const c = parse('1M 0603')
381 | assert(c.type === 'resistor')
382 | assert(c.resistance === 1000000, 'resistance value is wrong')
383 | assert(c.size === '0603', 'size is wrong')
384 | })
385 | it('parses "1K ohms"', () => {
386 | const c = parse('1K ohms 0603')
387 | assert(c.type === 'resistor')
388 | assert(c.resistance === 1000, 'resistance value is wrong')
389 | assert(c.size === '0603', 'size is wrong')
390 | })
391 | it('parses "1M1 ohms"', () => {
392 | const c = parse('1M1 ohms 0603')
393 | assert(c.type === 'resistor')
394 | assert(c.resistance === 1100000, 'resistance value is wrong')
395 | assert(c.size === '0603', 'size is wrong')
396 | })
397 | it('parses "1k5"', () => {
398 | const c = parse('1k5 0402')
399 | assert(c.type === 'resistor')
400 | assert(c.resistance === 1500, 'resistance value is wrong')
401 | assert(c.size === '0402', 'size is wrong')
402 | })
403 | it('parses "2r7"', () => {
404 | const c = parse('2r7 0402')
405 | assert(c.type === 'resistor')
406 | assert(c.resistance === 2.7, 'resistance value is wrong')
407 | assert(c.size === '0402', 'size is wrong')
408 | })
409 | it('parses "2R7"', () => {
410 | const c = parse('2R7 0402')
411 | assert(c.type === 'resistor')
412 | assert(c.resistance === 2.7, 'resistance value is wrong')
413 | assert(c.size === '0402', 'size is wrong')
414 | })
415 | it('parses "1.5k"', () => {
416 | const c = parse('1.5k 0402')
417 | assert(c.type === 'resistor')
418 | assert(c.resistance === 1500, 'resistance value is wrong')
419 | assert(c.size === '0402', 'size is wrong')
420 | })
421 | it('parses "1Ω"', () => {
422 | const c = parse('1Ω 0805')
423 | assert(c.type === 'resistor')
424 | assert(c.resistance === 1, 'resistance value is wrong')
425 | assert(c.size === '0805', 'size is wrong')
426 | })
427 | it('parses "1 Ω"', () => {
428 | const c = parse('1Ω 0805')
429 | assert(c.type === 'resistor')
430 | assert(c.resistance === 1, 'resistance value is wrong')
431 | assert(c.size === '0805', 'size is wrong')
432 | })
433 | it('parses "100R"', () => {
434 | const c = parse('100R')
435 | assert(c.type === 'resistor')
436 | assert(c.resistance === 100, 'resistance value is wrong')
437 | })
438 | it('parses "100 R"', () => {
439 | const c = parse('100 R')
440 | assert(c.type === 'resistor')
441 | assert(c.resistance === 100, 'resistance value is wrong')
442 | })
443 | it('parses "1 mOhm"', () => {
444 | const c = parse('1 mOhm')
445 | assert(c.type === 'resistor')
446 | assert(c.resistance === 0.001, 'resistance value is wrong')
447 | })
448 | it('parses "1 MOhm"', () => {
449 | const c = parse('1 MOhm')
450 | assert(c.type === 'resistor')
451 | assert(c.resistance === 1000000, 'resistance value is wrong')
452 | })
453 | it('parses "100 uΩ"', () => {
454 | const c = parse('100 uΩ')
455 | assert(c.type === 'resistor')
456 | assert(c.resistance === 0.0001, 'resistance value is wrong')
457 | })
458 | it('parses tolerance', () => {
459 | const c = parse('1k 0805 5%')
460 | assert(c.type === 'resistor')
461 | assert(c.resistance === 1000, 'resistance value is wrong')
462 | assert(c.tolerance === 5, 'tolerance value is wrong')
463 | assert(c.size === '0805', 'size is wrong')
464 | })
465 | it('parses power rating', () => {
466 | const c = parse('1k 0805 5% 100mW')
467 | assert(c.type === 'resistor')
468 | assert(c.resistance === 1000, 'resistance value is wrong')
469 | assert(c.tolerance === 5, 'tolerance value is wrong')
470 | assert(c.size === '0805', 'size is wrong')
471 | assert(c.power_rating === 0.100, 'power rating is wrong')
472 | })
473 | it('parses power rating 2', () => {
474 | const c = parse('0 ohm 0201 0.125W')
475 | assert(c.type === 'resistor')
476 | assert(c.resistance === 0, 'resistance value is wrong')
477 | assert(c.size === '0201', 'size is wrong')
478 | assert(c.power_rating === 0.125, 'power rating is wrong')
479 | })
480 | it('parses fractional power rating', () => {
481 | const c = parse('0 ohm 0201 1/8W')
482 | assert(c.type === 'resistor')
483 | assert(c.resistance === 0, 'resistance value is wrong')
484 | assert(c.size === '0201', 'size is wrong')
485 | assert(c.power_rating === 0.125, 'power rating is wrong')
486 | })
487 | it('parses fractional power rating 2', () => {
488 | const c = parse('resistor 1k 0201 1/2 watts')
489 | assert(c.type === 'resistor')
490 | assert(c.resistance === 1000, 'resistance value is wrong')
491 | assert(c.size === '0201', 'size is wrong')
492 | assert(c.power_rating === 0.5, 'power rating is wrong')
493 | })
494 | it("doesn't accidentally parse 01005 as value", () => {
495 | const c = parse('resistor 01005')
496 | assert(c.type === 'resistor')
497 | assert(c.resistance == null, 'resistance value is wrong')
498 | assert(c.size === '01005', 'size is wrong')
499 | })
500 | it("doesn't accidentally parse 0201 as value", () => {
501 | const c = parse('resistor 0201')
502 | assert(c.type === 'resistor')
503 | assert(c.resistance == null, 'resistance value is wrong')
504 | assert(c.size === '0201', 'size is wrong')
505 | })
506 | it("doesn't accidentally parse 0402 as value", () => {
507 | const c = parse('resistor 0402')
508 | assert(c.type === 'resistor')
509 | assert(c.resistance == null, 'resistance value is wrong')
510 | assert(c.size === '0402', 'size is wrong')
511 | })
512 | it("doesn't accidentally parse 0603 as value", () => {
513 | const c = parse('resistor 0603')
514 | assert(c.type === 'resistor')
515 | assert(c.resistance == null, 'resistance value is wrong')
516 | assert(c.size === '0603', 'size is wrong')
517 | })
518 | it("doesn't accidentally parse 0805 as value", () => {
519 | const c = parse('resistor 0805')
520 | assert(c.type === 'resistor')
521 | assert(c.resistance == null, 'resistance value is wrong')
522 | assert(c.size === '0805', 'size is wrong')
523 | })
524 | it("doesn't accidentally parse 1206 as value", () => {
525 | const c = parse('resistor 1206')
526 | assert(c.type === 'resistor')
527 | assert(c.resistance == null, 'resistance value is wrong')
528 | assert(c.size === '1206', 'size is wrong')
529 | })
530 | })
531 |
532 | describe('SMD LEDs', () => {
533 | it('parses red LED' , () => {
534 | const c = parse('led red 0603')
535 | assert(c.type === 'led')
536 | assert(c.color === 'red')
537 | assert(c.size === '0603', 'size is wrong')
538 | })
539 | it('parses green LED' , () => {
540 | const c = parse('SMD LED GREEN 0805')
541 | assert(c.type === 'led')
542 | assert(c.color === 'green')
543 | assert(c.size === '0805', 'size is wrong')
544 | })
545 | })
546 |
--------------------------------------------------------------------------------