gcf-common-lib 0.5.6 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +38 -0
- package/index.ts +46 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -189,6 +189,44 @@ var GcfCommon = /** @class */ (function () {
|
|
|
189
189
|
});
|
|
190
190
|
});
|
|
191
191
|
};
|
|
192
|
+
//
|
|
193
|
+
GcfCommon.indexToA1 = function (idx) {
|
|
194
|
+
return this.colNumToA1(idx + 1);
|
|
195
|
+
};
|
|
196
|
+
GcfCommon.colNumToA1 = function (columnNumber) {
|
|
197
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
198
|
+
// To store result (Excel column name)
|
|
199
|
+
var charIdxArr = [];
|
|
200
|
+
while (columnNumber > 0) {
|
|
201
|
+
// Find remainder
|
|
202
|
+
var rem = columnNumber % chars.length;
|
|
203
|
+
// If remainder is 0, then a
|
|
204
|
+
// 'Z' must be there in output
|
|
205
|
+
if (rem === 0) {
|
|
206
|
+
charIdxArr.push(chars.length - 1);
|
|
207
|
+
columnNumber = Math.floor(columnNumber / chars.length) - 1;
|
|
208
|
+
}
|
|
209
|
+
else { // If remainder is non-zero
|
|
210
|
+
charIdxArr.push(rem - 1);
|
|
211
|
+
columnNumber = Math.floor(columnNumber / chars.length);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Reverse the string and print result
|
|
215
|
+
return charIdxArr.reverse().map(function (n) { return chars[n]; }).join('');
|
|
216
|
+
};
|
|
217
|
+
GcfCommon.A1ToIndex = function (value) {
|
|
218
|
+
return this.A1ToColNum(value) - 1;
|
|
219
|
+
};
|
|
220
|
+
GcfCommon.A1ToColNum = function (value) {
|
|
221
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
222
|
+
var result = 0;
|
|
223
|
+
// tslint:disable-next-line:prefer-for-of
|
|
224
|
+
for (var i = 0; i < value.length; i++) {
|
|
225
|
+
result *= chars.length;
|
|
226
|
+
result += chars.indexOf(value[i]) + 1;
|
|
227
|
+
}
|
|
228
|
+
return result;
|
|
229
|
+
};
|
|
192
230
|
return GcfCommon;
|
|
193
231
|
}());
|
|
194
232
|
exports.GcfCommon = GcfCommon;
|
package/index.ts
CHANGED
|
@@ -94,4 +94,50 @@ export class GcfCommon {
|
|
|
94
94
|
}, s * 1000);
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
//
|
|
99
|
+
|
|
100
|
+
static indexToA1(idx: number) {
|
|
101
|
+
return this.colNumToA1(idx + 1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static colNumToA1(columnNumber: number) {
|
|
105
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
106
|
+
|
|
107
|
+
// To store result (Excel column name)
|
|
108
|
+
const charIdxArr: number[] = [];
|
|
109
|
+
|
|
110
|
+
while (columnNumber > 0) {
|
|
111
|
+
// Find remainder
|
|
112
|
+
const rem = columnNumber % chars.length;
|
|
113
|
+
|
|
114
|
+
// If remainder is 0, then a
|
|
115
|
+
// 'Z' must be there in output
|
|
116
|
+
if (rem === 0) {
|
|
117
|
+
charIdxArr.push(chars.length - 1);
|
|
118
|
+
columnNumber = Math.floor(columnNumber / chars.length) - 1;
|
|
119
|
+
} else { // If remainder is non-zero
|
|
120
|
+
charIdxArr.push(rem - 1);
|
|
121
|
+
columnNumber = Math.floor(columnNumber / chars.length);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Reverse the string and print result
|
|
126
|
+
return charIdxArr.reverse().map((n) => chars[n]).join('');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static A1ToIndex(value: string) {
|
|
130
|
+
return this.A1ToColNum(value) - 1;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static A1ToColNum(value: string) {
|
|
134
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
135
|
+
let result = 0;
|
|
136
|
+
// tslint:disable-next-line:prefer-for-of
|
|
137
|
+
for (let i = 0; i < value.length; i++) {
|
|
138
|
+
result *= chars.length;
|
|
139
|
+
result += chars.indexOf(value[i]) + 1;
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
97
143
|
}
|