postgres-interval 4.0.1 → 4.0.2

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.
Files changed (2) hide show
  1. package/index.js +17 -24
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -157,34 +157,27 @@ function readNextNum (interval) {
157
157
  }
158
158
 
159
159
  function parseMillisecond (interval) {
160
+ const previousPosition = position.value
160
161
  const currentValue = readNextNum(interval)
161
-
162
- if (currentValue < 10) {
163
- return currentValue * 100
164
- }
165
-
166
- if (currentValue < 100) {
167
- return currentValue * 10
168
- }
169
-
170
- if (currentValue < 1000) {
171
- return currentValue
172
- }
173
-
174
- if (currentValue < 10000) {
175
- return currentValue / 10
176
- }
177
-
178
- if (currentValue < 100000) {
179
- return currentValue / 100
180
- }
181
-
182
- if (currentValue < 1000000) {
183
- return currentValue / 1000
162
+ const valueStringLength = position.value - previousPosition
163
+
164
+ switch (valueStringLength) {
165
+ case 1:
166
+ return currentValue * 100
167
+ case 2:
168
+ return currentValue * 10
169
+ case 3:
170
+ return currentValue
171
+ case 4:
172
+ return currentValue / 10
173
+ case 5:
174
+ return currentValue / 100
175
+ case 6:
176
+ return currentValue / 1000
184
177
  }
185
178
 
186
179
  // slow path
187
- const remainder = currentValue.toString().length - 3
180
+ const remainder = valueStringLength - 3
188
181
  return currentValue / Math.pow(10, remainder)
189
182
  }
190
183
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "postgres-interval",
3
3
  "main": "index.js",
4
- "version": "4.0.1",
4
+ "version": "4.0.2",
5
5
  "description": "Parse Postgres interval columns",
6
6
  "license": "MIT",
7
7
  "repository": "bendrucker/postgres-interval",