CarrollCloud / js-value-wrappers (public) (License: GPLv3) (since 2018-06-24) (hash sha1)
Wrappers are classes that contain a specific value, and have methods to work on said value.
Example: Dimension to store length values, contains methods to convert and display the dimension in various ways.
List of commits:
Subject Hash Author Date (UTC)
Stop tracking "lib" 33b2fbd9fb1ebf04adb5e1200301d38d86bd48d3 William 2018-07-17 01:21:03
Updated Typescript info c0f60d7791019fc6c34f3919ef52f3f837715349 Carroll 2018-06-30 20:43:24
Updated to es2017 for output and es2015 modules. 0da36b29ab4a0c98291c041a43ba968a4c7626e6 Carroll 2018-06-30 20:14:54
Index is simply for the npm entrypoint. 0028d75bb694d64078f0208160944b09870db975 Carroll 2018-06-24 02:12:00
DimWrapper is to hold a dimension. 46e9f9f9123b270f2ce4d3cc84d73f55c4cdf8ba Carroll 2018-06-24 02:11:47
NumericWrapper is to hold a number. Go figure. 2daf55f2e94126859ed26bdc9cb9e4e3f33541eb Carroll 2018-06-24 02:05:19
Wrapper is the base class for this package. 552caf51d2c7e4400dafe788e632972cd860b97e Carroll 2018-06-24 02:03:47
Uploading metadata 6ec5ca0bf2000ad865e4f64ddc26e2e64a0d6a99 Carroll 2018-06-24 02:02:09
Commit 33b2fbd9fb1ebf04adb5e1200301d38d86bd48d3 - Stop tracking "lib"
Added typescript for a requirement.
Also added a postinstall script that will compile this package.
Author: William
Author date (UTC): 2018-07-17 01:21
Committer name: William
Committer date (UTC): 2018-07-17 01:21
Parent(s): c0f60d7791019fc6c34f3919ef52f3f837715349
Signing key:
Tree: 4249583a4392770307be92cab559aa205b5553e2
File Lines added Lines deleted
.gitignore 5 1
lib/index.d.ts 0 3
lib/index.js 0 4
lib/wrappers/DimWrapper.d.ts 0 53
lib/wrappers/DimWrapper.js 0 113
lib/wrappers/NumericWrapper.d.ts 0 20
lib/wrappers/NumericWrapper.js 0 32
lib/wrappers/Wrapper.d.ts 0 15
lib/wrappers/Wrapper.js 0 19
package-lock.json 13 0
package.json 8 4
File .gitignore changed (mode: 100644) (index 9bea433..3453fa5)
1
1 #Ignore library
2 lib/
3 #Mac likes to make this
2 4 .DS_Store .DS_Store
5 #Node modules do not need tracking (package.json handles this)
6 node_modules/
File lib/index.d.ts deleted (index 4f531e5..0000000)
1 export { Wrapper } from "./wrappers/Wrapper";
2 export { NumericWrapper } from "./wrappers/NumericWrapper";
3 export { DimWrapper } from "./wrappers/DimWrapper";
File lib/index.js deleted (index 23f40c6..0000000)
1 /* Export all front-facing classes */
2 export { Wrapper } from "./wrappers/Wrapper";
3 export { NumericWrapper } from "./wrappers/NumericWrapper";
4 export { DimWrapper } from "./wrappers/DimWrapper";
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 lib/wrappers/NumericWrapper.js deleted (index 2ece57b..0000000)
1 import { Wrapper } from "./Wrapper";
2 /**
3 * Stores numeric information in a wrapper, and provides ways to modify the value
4 */
5 export class NumericWrapper extends Wrapper {
6 /** Creates a new instance of wrapper with the given value */
7 constructor(value) {
8 super(value);
9 /** Numeric value that is saved*/
10 this.value = 0;
11 }
12 /** Add the other Wrapper to this one */
13 addOther(other) {
14 this.value += other.value;
15 }
16 /** Subtract the other Wrapper from this one */
17 subtractOther(other) {
18 this.value -= other.value;
19 }
20 /** Multiplies this value by the specified amount */
21 multiplyBy(value) {
22 this.value *= value;
23 }
24 /** Divides this value by the specified amount */
25 divideBy(value) {
26 this.value /= value;
27 }
28 /** Applies the exponent */
29 applyExponent(value) {
30 this.value **= value;
31 }
32 }
File lib/wrappers/Wrapper.d.ts deleted (index 94ab0c3..0000000)
1 /**
2 * Base Wrapper object
3 * A wrapper is to store base values and contains methods to operate on them.
4 * Using CarrollCloud database, these will be wrapped and unwrapped during serializaiton of classed objects
5 */
6 export declare class Wrapper {
7 /** The value that is to be wrapped */
8 value: any;
9 /** Creates a new instance of wrapper with the given value */
10 constructor(value: any);
11 /** Wrap a value and return a new Wrapper */
12 wrap(value: any): Wrapper;
13 /** Unwrap the value stored in this Wrapper */
14 unwrap(): any;
15 }
File lib/wrappers/Wrapper.js deleted (index 6205755..0000000)
1 /**
2 * Base Wrapper object
3 * A wrapper is to store base values and contains methods to operate on them.
4 * Using CarrollCloud database, these will be wrapped and unwrapped during serializaiton of classed objects
5 */
6 export class Wrapper {
7 /** Creates a new instance of wrapper with the given value */
8 constructor(value) {
9 this.value = value;
10 }
11 /** Wrap a value and return a new Wrapper */
12 wrap(value) {
13 return new Wrapper(value);
14 }
15 /** Unwrap the value stored in this Wrapper */
16 unwrap() {
17 return this.value;
18 }
19 }
File package-lock.json added (mode: 100644) (index 0000000..e8abffa)
1 {
2 "name": "js-value-wrappers",
3 "version": "0.1.1",
4 "lockfileVersion": 1,
5 "requires": true,
6 "dependencies": {
7 "typescript": {
8 "version": "2.9.2",
9 "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
10 "integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w=="
11 }
12 }
13 }
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 } }
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/CarrollCloud/js-value-wrappers

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/CarrollCloud/js-value-wrappers

Clone this repository using git:
git clone git://git.rocketgit.com/user/CarrollCloud/js-value-wrappers

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main