File lib/wrappers/DimWrapper.d.ts deleted (index daab91a..0000000) |
1 |
|
import { NumericWrapper } from "./NumericWrapper"; |
|
2 |
|
/** |
|
3 |
|
* Stores a dimension value and provides various methods for operating on it. |
|
4 |
|
* The value is stored in meters to keep the system consistent. |
|
5 |
|
* There are various outputs for this dimension. |
|
6 |
|
*/ |
|
7 |
|
export declare class DimWrapper extends NumericWrapper { |
|
8 |
|
/** Number of inches in a meter */ |
|
9 |
|
static inchInMeter: number; |
|
10 |
|
/** Number of feet in a meter */ |
|
11 |
|
static footInMeter: number; |
|
12 |
|
/** The value that is stored in meters */ |
|
13 |
|
value: number; |
|
14 |
|
/** Creates a new instance of wrapper with the given value */ |
|
15 |
|
constructor(value: number, unit: "inch" | "foot" | "meter"); |
|
16 |
|
/** |
|
17 |
|
* Wraps a dimension **IN METERS** and creates a new DimWrapper |
|
18 |
|
* This is primarily used for serialization and called on the prototype chain. |
|
19 |
|
*/ |
|
20 |
|
wrap(meter: number): DimWrapper; |
|
21 |
|
/** Unwrap the meter stored in this Wrapper */ |
|
22 |
|
unwrap(): number; |
|
23 |
|
/** |
|
24 |
|
* Converts the value to the specified unit |
|
25 |
|
* @param value Input value to convert |
|
26 |
|
* @param fromUnit Unit of input value |
|
27 |
|
* @param toUnit Unit to return |
|
28 |
|
* @return The specified number in the specified unit |
|
29 |
|
*/ |
|
30 |
|
static convert(value: number, fromUnit: "inch" | "foot" | "meter", toUnit: "inch" | "foot" | "meter"): number; |
|
31 |
|
/** Returns the stored value in inches */ |
|
32 |
|
toInches(): number; |
|
33 |
|
/** Returns the stored value in feet */ |
|
34 |
|
toFeet(): number; |
|
35 |
|
/** Returns the stored value in meters */ |
|
36 |
|
toMeters(): number; |
|
37 |
|
/** Returns the stored value in centimeters */ |
|
38 |
|
toCentimeters(): number; |
|
39 |
|
/** |
|
40 |
|
* Adds the value to the stored dimension |
|
41 |
|
* @param value Value to add |
|
42 |
|
* @param unit Unit of this value |
|
43 |
|
*/ |
|
44 |
|
addValue(value: number, unit: "inch" | "foot" | "meter"): void; |
|
45 |
|
/** |
|
46 |
|
* Returns this value as a foot inch fraction string |
|
47 |
|
* @param denom=16 Denominator for fraction (defaults to 16). |
|
48 |
|
* Values that are not whole or greater than 1 default to 16 |
|
49 |
|
* @param simplifyFraction=true Whether or not to simplify the fraction (defaults to true) |
|
50 |
|
* @return `${foot}'-${inch} ${fract}/${denom}` |
|
51 |
|
*/ |
|
52 |
|
toFootInchFract(denom?: number, simplifyFraction?: boolean): string; |
|
53 |
|
} |
|
File lib/wrappers/DimWrapper.js deleted (index 9b7a2c7..0000000) |
1 |
|
import { NumericWrapper } from "./NumericWrapper"; |
|
2 |
|
/** |
|
3 |
|
* Stores a dimension value and provides various methods for operating on it. |
|
4 |
|
* The value is stored in meters to keep the system consistent. |
|
5 |
|
* There are various outputs for this dimension. |
|
6 |
|
*/ |
|
7 |
|
export class DimWrapper extends NumericWrapper { |
|
8 |
|
/** Creates a new instance of wrapper with the given value */ |
|
9 |
|
constructor(value, unit) { |
|
10 |
|
//Convert the value to meters |
|
11 |
|
super(DimWrapper.convert(value, unit, "meter")); |
|
12 |
|
/** The value that is stored in meters */ |
|
13 |
|
this.value = 0; |
|
14 |
|
} |
|
15 |
|
/** |
|
16 |
|
* Wraps a dimension **IN METERS** and creates a new DimWrapper |
|
17 |
|
* This is primarily used for serialization and called on the prototype chain. |
|
18 |
|
*/ |
|
19 |
|
wrap(meter) { |
|
20 |
|
return new DimWrapper(meter, "meter"); |
|
21 |
|
} |
|
22 |
|
/** Unwrap the meter stored in this Wrapper */ |
|
23 |
|
unwrap() { |
|
24 |
|
return this.value; |
|
25 |
|
} |
|
26 |
|
/** |
|
27 |
|
* Converts the value to the specified unit |
|
28 |
|
* @param value Input value to convert |
|
29 |
|
* @param fromUnit Unit of input value |
|
30 |
|
* @param toUnit Unit to return |
|
31 |
|
* @return The specified number in the specified unit |
|
32 |
|
*/ |
|
33 |
|
static convert(value, fromUnit, toUnit) { |
|
34 |
|
/** The value in meters */ |
|
35 |
|
let inMeter = value; |
|
36 |
|
//convert the value to meters |
|
37 |
|
switch (fromUnit) { |
|
38 |
|
case ("inch"): |
|
39 |
|
inMeter = value * this.inchInMeter; |
|
40 |
|
break; |
|
41 |
|
case ("foot"): |
|
42 |
|
inMeter = value * this.footInMeter; |
|
43 |
|
break; |
|
44 |
|
} |
|
45 |
|
//Now, we convert the output value |
|
46 |
|
switch (toUnit) { |
|
47 |
|
case ("inch"): |
|
48 |
|
return inMeter / this.inchInMeter; |
|
49 |
|
case ("foot"): |
|
50 |
|
return inMeter / this.footInMeter; |
|
51 |
|
case ("meter"): |
|
52 |
|
return inMeter; |
|
53 |
|
} |
|
54 |
|
} |
|
55 |
|
/** Returns the stored value in inches */ |
|
56 |
|
toInches() { |
|
57 |
|
return this.value / DimWrapper.inchInMeter; |
|
58 |
|
} |
|
59 |
|
/** Returns the stored value in feet */ |
|
60 |
|
toFeet() { |
|
61 |
|
return this.value / DimWrapper.footInMeter; |
|
62 |
|
} |
|
63 |
|
/** Returns the stored value in meters */ |
|
64 |
|
toMeters() { |
|
65 |
|
return this.value; |
|
66 |
|
} |
|
67 |
|
/** Returns the stored value in centimeters */ |
|
68 |
|
toCentimeters() { |
|
69 |
|
return this.value * 100; |
|
70 |
|
} |
|
71 |
|
/** |
|
72 |
|
* Adds the value to the stored dimension |
|
73 |
|
* @param value Value to add |
|
74 |
|
* @param unit Unit of this value |
|
75 |
|
*/ |
|
76 |
|
addValue(value, unit) { |
|
77 |
|
this.value += DimWrapper.convert(value, unit, "meter"); |
|
78 |
|
} |
|
79 |
|
/** |
|
80 |
|
* Returns this value as a foot inch fraction string |
|
81 |
|
* @param denom=16 Denominator for fraction (defaults to 16). |
|
82 |
|
* Values that are not whole or greater than 1 default to 16 |
|
83 |
|
* @param simplifyFraction=true Whether or not to simplify the fraction (defaults to true) |
|
84 |
|
* @return `${foot}'-${inch} ${fract}/${denom}` |
|
85 |
|
*/ |
|
86 |
|
toFootInchFract(denom = 16, simplifyFraction = true) { |
|
87 |
|
//The fraction denominator must be greater than 1 and a whole number |
|
88 |
|
denom = (denom > 1 && (denom % 2 == 0 || denom % 2 == 1)) ? denom : 16; |
|
89 |
|
/** Inch value in decimals */ |
|
90 |
|
const inchDecimal = this.toInches(); |
|
91 |
|
/** Foot value without inches */ |
|
92 |
|
const foot = Math.floor(inchDecimal / 12); |
|
93 |
|
/** Inch value without feet or fraction */ |
|
94 |
|
const inch = Math.floor(inchDecimal % 12); |
|
95 |
|
/** Fraction value without feet or inches */ |
|
96 |
|
let fract = Math.round((inchDecimal - inch) * denom); |
|
97 |
|
//Now, we simplify fract and denom (if possible) |
|
98 |
|
//Standard in the english system, we only do this by 2 |
|
99 |
|
if (simplifyFraction) |
|
100 |
|
while (denom > 2 && denom % 2 == 0 && fract % 2 == 0) { |
|
101 |
|
denom /= 2; |
|
102 |
|
fract /= 2; |
|
103 |
|
} |
|
104 |
|
/** We do not include the fraction string if the value is 0 (and simplify fractions is true)*/ |
|
105 |
|
const fractString = (simplifyFraction && fract == 0) ? "" : ` ${fract}/${denom}`; |
|
106 |
|
//Finally, construct the value and return |
|
107 |
|
return `${foot}'-${inch}${fractString}"`; |
|
108 |
|
} |
|
109 |
|
} |
|
110 |
|
/** Number of inches in a meter */ |
|
111 |
|
DimWrapper.inchInMeter = 39.37008; |
|
112 |
|
/** Number of feet in a meter */ |
|
113 |
|
DimWrapper.footInMeter = 3.28084; |
|
File lib/wrappers/NumericWrapper.d.ts deleted (index 3ca76ec..0000000) |
1 |
|
import { Wrapper } from "./Wrapper"; |
|
2 |
|
/** |
|
3 |
|
* Stores numeric information in a wrapper, and provides ways to modify the value |
|
4 |
|
*/ |
|
5 |
|
export declare class NumericWrapper extends Wrapper { |
|
6 |
|
/** Numeric value that is saved*/ |
|
7 |
|
value: number; |
|
8 |
|
/** Creates a new instance of wrapper with the given value */ |
|
9 |
|
constructor(value: any); |
|
10 |
|
/** Add the other Wrapper to this one */ |
|
11 |
|
addOther(other: NumericWrapper): void; |
|
12 |
|
/** Subtract the other Wrapper from this one */ |
|
13 |
|
subtractOther(other: NumericWrapper): void; |
|
14 |
|
/** Multiplies this value by the specified amount */ |
|
15 |
|
multiplyBy(value: number): void; |
|
16 |
|
/** Divides this value by the specified amount */ |
|
17 |
|
divideBy(value: number): void; |
|
18 |
|
/** Applies the exponent */ |
|
19 |
|
applyExponent(value: number): void; |
|
20 |
|
} |
|
File package.json changed (mode: 100644) (index d221a30..de7feb8) |
2 |
2 |
"name": "js-value-wrappers", |
"name": "js-value-wrappers", |
3 |
3 |
"version": "0.1.1", |
"version": "0.1.1", |
4 |
4 |
"description": "Wrappers for various values; contains methods to operate on said values.", |
"description": "Wrappers for various values; contains methods to operate on said values.", |
5 |
|
"main": "/lib/index.js", |
|
6 |
|
"types": "/lib/index.d.ts", |
|
|
5 |
|
"main": "./lib/index.js", |
|
6 |
|
"types": "./lib/index.d.ts", |
7 |
7 |
"directories": { |
"directories": { |
8 |
8 |
"lib": "lib" |
"lib": "lib" |
9 |
9 |
}, |
}, |
10 |
10 |
"scripts": { |
"scripts": { |
11 |
|
"test": "echo \"Error: no test specified\" && exit 1" |
|
|
11 |
|
"test": "echo \"Error: no test specified\" && exit 1", |
|
12 |
|
"postinstall": "tsc" |
12 |
13 |
}, |
}, |
13 |
14 |
"repository": { |
"repository": { |
14 |
15 |
"type": "git", |
"type": "git", |
|
18 |
19 |
"wrapper" |
"wrapper" |
19 |
20 |
], |
], |
20 |
21 |
"author": "CarrollCloud", |
"author": "CarrollCloud", |
21 |
|
"license": "GPL-3.0" |
|
|
22 |
|
"license": "GPL-3.0", |
|
23 |
|
"dependencies": { |
|
24 |
|
"typescript": "^2.9.2" |
|
25 |
|
} |
22 |
26 |
} |
} |