Skip to content

Commit d20a0f7

Browse files
committed
style: 💄 format README
1 parent 641adc6 commit d20a0f7

File tree

1 file changed

+65
-73
lines changed

1 file changed

+65
-73
lines changed

README.md

Lines changed: 65 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
<center>
44
ΜΕΤΡΩ ΧΡΩ
55

6-
*Use the measure*
6+
_Use the measure_
7+
78
</center>
89

910
A library for defining unit systems and performing unit-safe calculations
1011

1112
## Demo
1213

1314
```js
14-
const {createUnitSystem, conversion} = require('unit-system');
15+
const { createUnitSystem, conversion } = require('unit-system');
1516

1617
const { createUnit, m, convert, add } = createUnitSystem();
1718

1819
const inch = createUnit('inch');
1920
const yard = createUnit('yard', {
20-
alias: ['yd', 'yard', 'yards'],
21+
alias: ['yd', 'yard', 'yards'],
2122
});
2223

2324
const foot = createUnit('foot', {
@@ -40,7 +41,7 @@ convert(twoYards, inch).value === 72;
4041
Most uses of `unit-system` start with `createUnitSystem()`.
4142

4243
```js
43-
const {createUnitSystem} = require('unit-system');
44+
const { createUnitSystem } = require('unit-system');
4445

4546
const { createUnit, m, convert, system } = createUnitSystem();
4647
```
@@ -53,9 +54,9 @@ Creates a new `Unit` and automatically registers it with `system` (the `UnitSyst
5354
const inch = createUnit('inch', { alias: 'inches' });
5455

5556
const foot = createUnit('foot', {
56-
convert: {
57-
from: [ inch, conversion.divideBy(12) ],
58-
},
57+
convert: {
58+
from: [inch, conversion.divideBy(12)],
59+
},
5960
});
6061
```
6162

@@ -65,19 +66,19 @@ Shorthand function for creating new `Measurement` instances. If a unit is define
6566

6667
```js
6768
// All of are equivalent to `new Measurement(12, inch)`
68-
m`12 inches`
69-
m`12 ${inch}`
70-
m`12`.inches
71-
m(12).inches
72-
m(12, inch)
69+
m`12 inches`;
70+
m`12 ${inch}`;
71+
m`12`.inches;
72+
m(12).inches;
73+
m(12, inch);
7374
```
7475

7576
#### `convert(measurement, unit)`
7677

7778
Given a `Measurement` and a `Unit`, `convert(measurement, unit)` will attempt to convert that measurement to the given unit. (see `UnitSystem#convert()` for details)
7879

7980
```js
80-
convert(m`24 inches`, foot)
81+
convert(m`24 inches`, foot);
8182
// => new Measurement(2, foot)
8283
```
8384

@@ -92,14 +93,14 @@ A collection of converter creators. A converter is an object with `forward` and
9293
Converters shouldn't be used directly. Instead, define them when creating a unit, and `UnitSystem` will be able to automatically convert for you.
9394

9495
```js
95-
const {conversion} = require('unit-system');
96+
const { conversion } = require('unit-system');
9697
```
9798

9899
#### `conversion.slopeIntercept(slope, intercept = 0)`
99100

100101
Given a `slope` and an optional `intercept`, produces a converter.
101102

102-
*Also exported as: `multiplyBy`, `times`*
103+
_Also exported as: `multiplyBy`, `times`_
103104

104105
```js
105106
const celsiusToFahrenheit = conversion.slopeIntercept(9 / 5, 32);
@@ -123,12 +124,12 @@ feetToInches.backward(12) === 1;
123124

124125
Given two example points on a line, produces a converter. Useful when a conversion can be more clearly expressed in terms of easily-understood examples.
125126

126-
*Also exported as: `fromExamples`, `byExample`*
127+
_Also exported as: `fromExamples`, `byExample`_
127128

128129
```js
129130
const freezing = [0, 32];
130131
const boiling = [100, 212];
131-
const celsiusToFahrenheit = conversion.twoPoint(freezing, boiling)
132+
const celsiusToFahrenheit = conversion.twoPoint(freezing, boiling);
132133

133134
celsiusToFahrenheit.forward(100) === 212;
134135
celsiusToFahrenheit.backward(32) === 0;
@@ -138,10 +139,10 @@ celsiusToFahrenheit.backward(32) === 0;
138139

139140
Given a constant value, produces a converter. A special case of `slopeIntercept` where `slope` is always `1`.
140141

141-
*Also exported as: `add`, `constant`*
142+
_Also exported as: `add`, `constant`_
142143

143144
```js
144-
const celsiusToKelvin = conversion.addConstant(273.15)
145+
const celsiusToKelvin = conversion.addConstant(273.15);
145146

146147
celsiusToKelvin.forward(0) === 273.15;
147148
celsiusToKelvin.backward(-272.15) === 1;
@@ -152,7 +153,7 @@ celsiusToKelvin.backward(-272.15) === 1;
152153
The base unit type.
153154

154155
```js
155-
const {Unit} = require('unit-system');
156+
const { Unit } = require('unit-system');
156157

157158
const inch = new Unit('inch');
158159

@@ -164,7 +165,7 @@ unit.name === 'inch';
164165
A value type representing a number and its unit.
165166

166167
```js
167-
const {Measurement} = require('unit-system');
168+
const { Measurement } = require('unit-system');
168169

169170
const oneInch = new Measurement(1, inch);
170171

@@ -177,16 +178,16 @@ oneInch.unit === inch;
177178
A collection of units. Internally tracks aliases for units (used by `m` to look up the corresponding unit) and converters.
178179

179180
```js
180-
const {UnitSystem} = require('unit-system');
181+
const { UnitSystem } = require('unit-system');
181182

182183
const myUnitSystem = new UnitSystem([
183-
[inch, { alias: 'inches' }],
184-
[foot, { convert: { from: [ inch, conversion.divideBy(12) ] } }],
184+
[inch, { alias: 'inches' }],
185+
[foot, { convert: { from: [inch, conversion.divideBy(12)] } }],
185186
]);
186187

187188
myUnitSystem.getUnitForAlias('inches') === inch;
188189

189-
myUnitSystem.convert(new Measurement(12, inch), foot)
190+
myUnitSystem.convert(new Measurement(12, inch), foot);
190191
// => new Measurement(1, foot)
191192
```
192193

@@ -195,19 +196,11 @@ myUnitSystem.convert(new Measurement(12, inch), foot)
195196
Takes one or more other `UnitSystem`s and copies this unit into this one.
196197

197198
```js
198-
const mySystem = new UnitSystem([
199-
[new Unit('inch'), { alias: 'inches' }]
200-
]);
199+
const mySystem = new UnitSystem([[new Unit('inch'), { alias: 'inches' }]]);
201200

202-
const systemA = new UnitSystem([
203-
[new Unit('foot')]
204-
]);
205-
const systemB = new UnitSystem([
206-
[new Unit('yard')]
207-
]);
208-
const systemC = new UnitSystem([
209-
[new Unit('mile')]
210-
]);
201+
const systemA = new UnitSystem([[new Unit('foot')]]);
202+
const systemB = new UnitSystem([[new Unit('yard')]]);
203+
const systemC = new UnitSystem([[new Unit('mile')]]);
211204

212205
mySystem.merge(systemA, systemB, systemC);
213206
```
@@ -231,11 +224,11 @@ If `convert` is provided, its properties `to` and `from` are used to register co
231224

232225
```js
233226
system.register(inch, {
234-
convert: {
235-
to: [ centimeter, multiplyBy(2.54) ],
236-
from: [ foot, divideBy(12) ],
237-
},
238-
})
227+
convert: {
228+
to: [centimeter, multiplyBy(2.54)],
229+
from: [foot, divideBy(12)],
230+
},
231+
});
239232
```
240233

241234
#### `.registerAll(units)`
@@ -270,31 +263,31 @@ Consider a `UnitSystem` that defines kilometers, meters, centimeters, inches, fe
270263
```js
271264
const kilometer = createUnit('kilometer');
272265
const meter = createUnit('meter', {
273-
convert: {
274-
from: [ kilometer, conversion.multiplyBy(1000) ],
275-
},
266+
convert: {
267+
from: [kilometer, conversion.multiplyBy(1000)],
268+
},
276269
});
277270
const centimeter = createUnit('centimeter', {
278-
convert: {
279-
from: [ meter, conversion.multiplyBy(100) ],
280-
},
271+
convert: {
272+
from: [meter, conversion.multiplyBy(100)],
273+
},
281274
});
282275

283276
const inch = createUnit('inch', {
284-
convert: {
285-
to: [ centimeter, conversion.multiplyBy(2.54) ],
286-
},
277+
convert: {
278+
to: [centimeter, conversion.multiplyBy(2.54)],
279+
},
287280
});
288281
const foot = createUnit('foot', {
289-
convert: {
290-
from: [ inch, conversion.divideBy(12) ],
291-
},
282+
convert: {
283+
from: [inch, conversion.divideBy(12)],
284+
},
292285
});
293286
const mile = createUnit('mile', {
294-
alias: 'mile',
295-
convert: {
296-
to: [ foot, conversion.multiplyBy(5280) ],
297-
},
287+
alias: 'mile',
288+
convert: {
289+
to: [foot, conversion.multiplyBy(5280)],
290+
},
298291
});
299292
```
300293

@@ -307,7 +300,6 @@ oneMileInKilometers.value === 1.609344;
307300

308301
When a multi-step converter is created, it will be cached, to save on the lookup time.
309302

310-
311303
#### `.add(...measurements)`
312304

313305
`add` will take the given measurements and attempt to add them together, converting them if needed.
@@ -317,29 +309,29 @@ Consider a `UnitSystem` that defines centimeters, inches, and feet:
317309
```js
318310
const centimeter = createUnit('centimeter');
319311
const inch = createUnit('inch', {
320-
alias: 'inches',
321-
convert: {
322-
to: [centimeter, conversion.multiplyBy(2.54)],
323-
},
312+
alias: 'inches',
313+
convert: {
314+
to: [centimeter, conversion.multiplyBy(2.54)],
315+
},
324316
});
325317
const foot = createUnit('foot', {
326-
alias: 'feet',
327-
convert: {
328-
from: [inch, conversion.divideBy(12)],
329-
},
318+
alias: 'feet',
319+
convert: {
320+
from: [inch, conversion.divideBy(12)],
321+
},
330322
});
331323
```
332324

333325
It can add up several values in each of those units, converting them to the same unit:
334326

335327
```js
336328
const eightFeet = system.add(
337-
m`2 feet`,
338-
m`18 inches`,
339-
m`2 inches`,
340-
m(15.24, centimeter),
341-
m`10 inches`,
342-
m`3 feet`
329+
m`2 feet`,
330+
m`18 inches`,
331+
m`2 inches`,
332+
m(15.24, centimeter),
333+
m`10 inches`,
334+
m`3 feet`
343335
);
344336
eightFeet.value === 8;
345337
eightFeet.unit === foot;

0 commit comments

Comments
 (0)