@quoll/lib
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -6,2 +6,9 @@ # Change Log | ||
# [0.3.0](https://github.com/mzogheib/quoll/compare/@quoll/lib@0.2.0...@quoll/lib@0.3.0) (2024-02-10) | ||
### Features | ||
- add some new modules to lib and refactor unix timestamp function ([b9f72e6](https://github.com/mzogheib/quoll/commit/b9f72e6ea84cee0588c5e84de198f8eac6d199e4)) | ||
- **lib:** add toshl entries adapter ([7bb45da](https://github.com/mzogheib/quoll/commit/7bb45dac1200b418e0dd078ec2727c01d5dc61dc)) | ||
# 0.2.0 (2024-02-10) | ||
@@ -8,0 +15,0 @@ |
/** | ||
* A date string formatted as `YYYY-MM-DD`. | ||
* | ||
* @remarks the purpose of this type is to add meaning to date variables that | ||
* need to take this format. It could be enhanced to enforce the string | ||
* The purpose of these types is to add meaning to date & time variables that | ||
* need to take this format. They could be enhanced to enforce the string | ||
* structure but that becomes overly complicated | ||
*/ | ||
/** | ||
* A date string formatted as `YYYY-MM-DD`. | ||
*/ | ||
export type ISO8601Date = string; | ||
/** | ||
* A date string formatted as `YYYY-MM-DDTHH:MM:SSZ`. | ||
* | ||
* @remarks the purpose of this type is to add meaning to date variables that | ||
* need to take this format. It could be enhanced to enforce the string | ||
* structure but that becomes overly complicated | ||
* A time string formatted as `HH:MM:SS`. | ||
*/ | ||
export type ISO8601Time = string; | ||
/** | ||
* A date & time string formatted as `YYYY-MM-DDTHH:MM:SSZ`. | ||
*/ | ||
export type ISO8601DateAndTime = string; |
"use strict"; | ||
/** | ||
* The purpose of these types is to add meaning to date & time variables that | ||
* need to take this format. They could be enhanced to enforce the string | ||
* structure but that becomes overly complicated | ||
*/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,2 +0,2 @@ | ||
import { ISO8601Date, ISO8601DateAndTime } from "./types"; | ||
import { ISO8601Date, ISO8601Time } from "./types"; | ||
/** | ||
@@ -38,2 +38,18 @@ * Offsets a date by the input number of days. | ||
*/ | ||
export declare const getUnixTimestamp: (date: ISO8601DateAndTime) => number; | ||
export declare const getUnixTimestamp: (date: Date) => number; | ||
/** | ||
* Finds and returns an ISO 8601 time, i.e. `HH:MM:SS`, in a string. | ||
* | ||
* @param input the input string | ||
* @returns the matched time if found or `null` if not. | ||
* | ||
* @remarks returns the first match only | ||
*/ | ||
export declare const extractISO8601Time: (input: string) => ISO8601Time | null; | ||
/** | ||
* Checks if an input string begins with an ISO 8601 time. | ||
* | ||
* @param input the input to check | ||
* @returns `true` if | ||
*/ | ||
export declare const startsWithISO8601Time: (input: string) => boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getUnixTimestamp = exports.makeISO8601Date = exports.getStartOfDay = exports.getEndOfDay = exports.getOffsetDate = void 0; | ||
exports.startsWithISO8601Time = exports.extractISO8601Time = exports.getUnixTimestamp = exports.makeISO8601Date = exports.getStartOfDay = exports.getEndOfDay = exports.getOffsetDate = void 0; | ||
/** | ||
@@ -60,3 +60,40 @@ * Offsets a date by the input number of days. | ||
*/ | ||
const getUnixTimestamp = (date) => Math.floor(new Date(date).getTime() / 1000); | ||
const getUnixTimestamp = (date) => Math.floor(date.getTime() / 1000); | ||
exports.getUnixTimestamp = getUnixTimestamp; | ||
const ISO8601_TIME_REGEX = /[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/; | ||
/** | ||
* Finds and returns an ISO 8601 time, i.e. `HH:MM:SS`, in a string. | ||
* | ||
* @param input the input string | ||
* @returns the matched time if found or `null` if not. | ||
* | ||
* @remarks returns the first match only | ||
*/ | ||
const extractISO8601Time = (input) => { | ||
const match = input.match(ISO8601_TIME_REGEX); | ||
if (match && match.length > 0) { | ||
const timeElements = match[0].split(":"); | ||
const hour = parseInt(timeElements[0], 10); | ||
const minute = parseInt(timeElements[1], 10); | ||
const second = parseInt(timeElements[2], 10); | ||
const isValid = hour >= 0 && | ||
hour < 24 && | ||
minute >= 0 && | ||
minute < 60 && | ||
second >= 0 && | ||
second < 60; | ||
return isValid ? match[0] : null; | ||
} | ||
return null; | ||
}; | ||
exports.extractISO8601Time = extractISO8601Time; | ||
/** | ||
* Checks if an input string begins with an ISO 8601 time. | ||
* | ||
* @param input the input to check | ||
* @returns `true` if | ||
*/ | ||
const startsWithISO8601Time = (input) => { | ||
return ISO8601_TIME_REGEX.test(input.substr(0, 8)); | ||
}; | ||
exports.startsWithISO8601Time = startsWithISO8601Time; |
export * from "./strava"; | ||
export * from "./toshl"; |
@@ -18,1 +18,2 @@ "use strict"; | ||
__exportStar(require("./strava"), exports); | ||
__exportStar(require("./toshl"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stravaSummaryActivitiesAdapter = void 0; | ||
const utils_1 = require("../../../date/utils"); | ||
const utils_2 = require("../../../misc/distance/utils"); | ||
const utils_3 = require("../../../misc/randomString/utils"); | ||
const date_1 = require("../../../date"); | ||
const distance_1 = require("../../../misc/distance"); | ||
const randomString_1 = require("../../../misc/randomString"); | ||
const types_1 = require("./types"); | ||
@@ -28,4 +28,4 @@ const ActivityConfigMap = { | ||
const title = (_b = activityConfig === null || activityConfig === void 0 ? void 0 : activityConfig.label) !== null && _b !== void 0 ? _b : "Unknown"; | ||
const _distance = (0, utils_2.formatDistance)(distance); | ||
const timeStart = (0, utils_1.getUnixTimestamp)(start_date); | ||
const _distance = (0, distance_1.formatDistance)(distance); | ||
const timeStart = (0, date_1.getUnixTimestamp)(new Date(start_date)); | ||
const timeEnd = timeStart + elapsed_time * 1000; | ||
@@ -41,3 +41,3 @@ const locationStart = (0, types_1.isStravaLatLng)(start_latlng) | ||
feed: "strava", | ||
id: (0, utils_3.generateRandomString)(32), | ||
id: (0, randomString_1.generateRandomString)(32), | ||
type, | ||
@@ -44,0 +44,0 @@ timeStart, |
import { FeedName } from "../feeds/types"; | ||
export type TimelineEntryType = "bike" | "bus" | "car" | "e-bike" | "expense" | "ferry" | "flight" | "hike" | "home" | "motorcycle" | "photo" | "place" | "run" | "train" | "tram" | "transport" | "unknown" | "velomobile" | "video" | "walk" | "work" | "yoga"; | ||
export type TimelineEntryType = "bike" | "bus" | "car" | "e-bike" | "expense" | "ferry" | "flight" | "hike" | "income" | "home" | "motorcycle" | "photo" | "place" | "run" | "train" | "tram" | "transport" | "unknown" | "velomobile" | "video" | "walk" | "work" | "yoga"; | ||
export interface TimelineEntryLocation { | ||
@@ -4,0 +4,0 @@ latitude: number; |
{ | ||
"name": "@quoll/lib", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Shared code for client and server side packages", | ||
@@ -21,3 +21,3 @@ "repository": "https://github.com/mzogheib/quoll", | ||
}, | ||
"gitHead": "221cd0f9b85f1b1c72b22c4de072af6fea89a590" | ||
"gitHead": "5e4a3cd4a36062657a7fd21394671a2d206a0878" | ||
} |
/** | ||
* A date string formatted as `YYYY-MM-DD`. | ||
* | ||
* @remarks the purpose of this type is to add meaning to date variables that | ||
* need to take this format. It could be enhanced to enforce the string | ||
* The purpose of these types is to add meaning to date & time variables that | ||
* need to take this format. They could be enhanced to enforce the string | ||
* structure but that becomes overly complicated | ||
*/ | ||
/** | ||
* A date string formatted as `YYYY-MM-DD`. | ||
*/ | ||
export type ISO8601Date = string; | ||
/** | ||
* A date string formatted as `YYYY-MM-DDTHH:MM:SSZ`. | ||
* | ||
* @remarks the purpose of this type is to add meaning to date variables that | ||
* need to take this format. It could be enhanced to enforce the string | ||
* structure but that becomes overly complicated | ||
* A time string formatted as `HH:MM:SS`. | ||
*/ | ||
export type ISO8601Time = string; | ||
/** | ||
* A date & time string formatted as `YYYY-MM-DDTHH:MM:SSZ`. | ||
*/ | ||
export type ISO8601DateAndTime = string; |
@@ -1,2 +0,2 @@ | ||
import { ISO8601Date, ISO8601DateAndTime } from "./types"; | ||
import { ISO8601Date, ISO8601Time } from "./types"; | ||
@@ -60,3 +60,45 @@ /** | ||
*/ | ||
export const getUnixTimestamp = (date: ISO8601DateAndTime) => | ||
Math.floor(new Date(date).getTime() / 1000); | ||
export const getUnixTimestamp = (date: Date) => | ||
Math.floor(date.getTime() / 1000); | ||
const ISO8601_TIME_REGEX = /[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/; | ||
/** | ||
* Finds and returns an ISO 8601 time, i.e. `HH:MM:SS`, in a string. | ||
* | ||
* @param input the input string | ||
* @returns the matched time if found or `null` if not. | ||
* | ||
* @remarks returns the first match only | ||
*/ | ||
export const extractISO8601Time = (input: string): ISO8601Time | null => { | ||
const match = input.match(ISO8601_TIME_REGEX); | ||
if (match && match.length > 0) { | ||
const timeElements = match[0].split(":"); | ||
const hour = parseInt(timeElements[0], 10); | ||
const minute = parseInt(timeElements[1], 10); | ||
const second = parseInt(timeElements[2], 10); | ||
const isValid = | ||
hour >= 0 && | ||
hour < 24 && | ||
minute >= 0 && | ||
minute < 60 && | ||
second >= 0 && | ||
second < 60; | ||
return isValid ? match[0] : null; | ||
} | ||
return null; | ||
}; | ||
/** | ||
* Checks if an input string begins with an ISO 8601 time. | ||
* | ||
* @param input the input to check | ||
* @returns `true` if | ||
*/ | ||
export const startsWithISO8601Time = (input: string) => { | ||
return ISO8601_TIME_REGEX.test(input.substr(0, 8)); | ||
}; |
export * from "./strava"; | ||
export * from "./toshl"; |
@@ -1,4 +0,4 @@ | ||
import { getUnixTimestamp } from "../../../date/utils"; | ||
import { formatDistance } from "../../../misc/distance/utils"; | ||
import { generateRandomString } from "../../../misc/randomString/utils"; | ||
import { getUnixTimestamp } from "../../../date"; | ||
import { formatDistance } from "../../../misc/distance"; | ||
import { generateRandomString } from "../../../misc/randomString"; | ||
import { | ||
@@ -59,3 +59,3 @@ TimelineEntry, | ||
const _distance = formatDistance(distance); | ||
const timeStart = getUnixTimestamp(start_date); | ||
const timeStart = getUnixTimestamp(new Date(start_date)); | ||
const timeEnd = timeStart + elapsed_time * 1000; | ||
@@ -62,0 +62,0 @@ const locationStart = isStravaLatLng(start_latlng) |
@@ -12,2 +12,3 @@ import { FeedName } from "../feeds/types"; | ||
| "hike" | ||
| "income" | ||
| "home" | ||
@@ -14,0 +15,0 @@ | "motorcycle" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38064
67
1103