@augment-vir/common 19.0.0 → 19.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.
@@ -4,7 +4,7 @@ exports.joinUrlParts = void 0;
4
4
  const protocolSplit = '://';
5
5
  /**
6
6
  * Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
7
- * removes consecutive slashes in the path. This also encodes each URL part.
7
+ * removes consecutive slashes in the path.
8
8
  *
9
9
  * @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
10
10
  */
@@ -27,7 +27,7 @@ function joinUrlParts(...urlParts) {
27
27
  return part;
28
28
  }
29
29
  else {
30
- return encodeURIComponent(part);
30
+ return part;
31
31
  }
32
32
  })
33
33
  .reduce((fillingUpArray, currentEntry, currentIndex, inputArray) => {
@@ -1,7 +1,7 @@
1
1
  const protocolSplit = '://';
2
2
  /**
3
3
  * Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
4
- * removes consecutive slashes in the path. This also encodes each URL part.
4
+ * removes consecutive slashes in the path.
5
5
  *
6
6
  * @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
7
7
  */
@@ -24,7 +24,7 @@ export function joinUrlParts(...urlParts) {
24
24
  return part;
25
25
  }
26
26
  else {
27
- return encodeURIComponent(part);
27
+ return part;
28
28
  }
29
29
  })
30
30
  .reduce((fillingUpArray, currentEntry, currentIndex, inputArray) => {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
3
- * removes consecutive slashes in the path. This also encodes each URL part.
3
+ * removes consecutive slashes in the path.
4
4
  *
5
5
  * @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
6
6
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "19.0.0",
3
+ "version": "19.0.2",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"
@@ -18,13 +18,13 @@
18
18
  "module": "dist/esm/index.js",
19
19
  "types": "dist/types/index.d.ts",
20
20
  "scripts": {
21
- "compile": "tsc --project tsconfig.json && tsc --project tsconfig.cjs.json",
21
+ "compile": "rm -rf dist && tsc --project tsconfig.json && tsc --project tsconfig.cjs.json",
22
22
  "test": "echo \"use common-test to run tests\" && exit 0",
23
23
  "test:coverage": "npm test",
24
24
  "test:types": "tsc --noEmit"
25
25
  },
26
26
  "dependencies": {
27
- "type-fest": "^4.3.1"
27
+ "type-fest": "^4.3.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "typescript": "^5.2.2"
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDateFromUtcIsoFormat = exports.createDateFromNamedCommaFormat = exports.createDateFromSlashFormat = exports.InvalidDateError = exports.englishShortMonthNames = exports.englishFullMonthNames = void 0;
4
- exports.englishFullMonthNames = [
5
- 'january',
6
- 'february',
7
- 'march',
8
- 'april',
9
- 'may',
10
- 'june',
11
- 'july',
12
- 'august',
13
- 'september',
14
- 'october',
15
- 'november',
16
- 'december',
17
- ];
18
- exports.englishShortMonthNames = exports.englishFullMonthNames.map((longMonthName) => longMonthName.slice(0, 3));
19
- class InvalidDateError extends Error {
20
- constructor() {
21
- super(...arguments);
22
- this.name = 'InvalidDateError';
23
- }
24
- }
25
- exports.InvalidDateError = InvalidDateError;
26
- /**
27
- * @param slashFormatString String that should be of format "MM/DD/YY", "MM/DD/YYYY". When the year
28
- * portion only contains 2 numbers ("MM/DD/YY") the century must be provided in the form of the
29
- * yearPrefix input.
30
- * @param yearPrefix String or number that is used to prefix slash format strings that only contain
31
- * 2 digits ("MM/DD/YY"). If the year is entirely missing form the given slash format string, the
32
- * year will default to year 00 of the given century. See test file for examples.
33
- */
34
- function createDateFromSlashFormat(slashFormatString, yearPrefix = '') {
35
- const [month, day, rawYearEnding = '',] = slashFormatString.split('/');
36
- if (!month || !day) {
37
- throw new Error(`Unable to extract month or day from "${slashFormatString}"`);
38
- }
39
- const yearEnding = rawYearEnding.length < 4 ? `${yearPrefix}${rawYearEnding.padStart(2, '0')}` : rawYearEnding;
40
- const returnDate = createDateFromUtcIsoFormat(`${yearEnding.padStart(4, '0')}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`);
41
- return returnDate;
42
- }
43
- exports.createDateFromSlashFormat = createDateFromSlashFormat;
44
- /**
45
- * @param commaFormatString Should be at string of the form "monthName dayNumber, fullYear" Example:
46
- * "May 19, 2005"
47
- * @param ignoreInvalidMonth Set to true to ignore invalid months and just use the current UTC month
48
- */
49
- function createDateFromNamedCommaFormat(commaFormatString, ignoreInvalidMonth = false) {
50
- const [monthName, dayNumber, fullYear,] = commaFormatString.replace(',', '').split(' ');
51
- if (!monthName || !dayNumber || !fullYear) {
52
- throw new InvalidDateError(`Invalid ${createDateFromNamedCommaFormat.name} input: ${commaFormatString}`);
53
- }
54
- const longMonthIndex = exports.englishFullMonthNames.indexOf(monthName.toLowerCase());
55
- const shortMonthIndex = exports.englishShortMonthNames.indexOf(monthName.toLowerCase());
56
- let monthIndex = longMonthIndex === -1 ? shortMonthIndex : longMonthIndex;
57
- if (monthIndex === -1) {
58
- if (ignoreInvalidMonth) {
59
- monthIndex = new Date().getUTCMonth();
60
- }
61
- else {
62
- throw new InvalidDateError(`Month name ${monthName} was not found.`);
63
- }
64
- }
65
- const returnDate = createDateFromUtcIsoFormat(`${fullYear.padStart(4, '0')}-${String(monthIndex + 1).padStart(2, '0')}-${dayNumber.padStart(2, '0')}`);
66
- return returnDate;
67
- }
68
- exports.createDateFromNamedCommaFormat = createDateFromNamedCommaFormat;
69
- /**
70
- * Converts an iso-formatted string to a UTC date object. The time is nulled out to all zeros.
71
- *
72
- * @param isoFormatString Should be a date in the format YYYY-MM-DD.
73
- */
74
- function createDateFromUtcIsoFormat(isoFormatString) {
75
- const utcDate = new Date(isoFormatString + 'T00:00:00.000Z');
76
- if (isNaN(Number(utcDate))) {
77
- throw new InvalidDateError(`Invalid utc date formed from input "${isoFormatString}"`);
78
- }
79
- return utcDate;
80
- }
81
- exports.createDateFromUtcIsoFormat = createDateFromUtcIsoFormat;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateRelativeDate = void 0;
4
- const __1 = require("../..");
5
- /**
6
- * For the properties that don't have setters and getters named directly after them. For example, to
7
- * modify "milliseconds", we can just use that string directly: getUTCMilliseconds. However, for
8
- * "Months", we have to use getUTCMonth.
9
- */
10
- const differentlyNamedDateSettersAndGetterKeys = {
11
- days: {
12
- getKey: 'getUTCDate',
13
- setKey: 'setUTCDate',
14
- },
15
- months: {
16
- getKey: 'getUTCMonth',
17
- setKey: 'setUTCMonth',
18
- },
19
- years: {
20
- getKey: 'getUTCFullYear',
21
- setKey: 'setUTCFullYear',
22
- },
23
- };
24
- function calculateRelativeDate(startingDate, calculations) {
25
- if (!(startingDate instanceof Date)) {
26
- startingDate = new Date(startingDate);
27
- }
28
- let returnDate = new Date(startingDate);
29
- (0, __1.getObjectTypedKeys)(calculations).forEach((calculationKey) => {
30
- const calculationValue = calculations[calculationKey];
31
- if (!calculationValue) {
32
- return;
33
- }
34
- const { getKey, setKey } = (0, __1.hasKey)(differentlyNamedDateSettersAndGetterKeys, calculationKey)
35
- ? differentlyNamedDateSettersAndGetterKeys[calculationKey]
36
- : {
37
- getKey: `getUTC${(0, __1.capitalizeFirstLetter)(calculationKey)}`,
38
- setKey: `setUTC${(0, __1.capitalizeFirstLetter)(calculationKey)}`,
39
- };
40
- const currentValue = returnDate[getKey]();
41
- returnDate[setKey](currentValue + calculationValue);
42
- });
43
- return returnDate;
44
- }
45
- exports.calculateRelativeDate = calculateRelativeDate;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removePx = exports.addPx = void 0;
4
- function addPx(input) {
5
- if (String(input).endsWith('px')) {
6
- return String(input);
7
- }
8
- else {
9
- return `${input}px`;
10
- }
11
- }
12
- exports.addPx = addPx;
13
- function removePx(input) {
14
- return Number(input.replace(/px$/, ''));
15
- }
16
- exports.removePx = removePx;
@@ -1,74 +0,0 @@
1
- export const englishFullMonthNames = [
2
- 'january',
3
- 'february',
4
- 'march',
5
- 'april',
6
- 'may',
7
- 'june',
8
- 'july',
9
- 'august',
10
- 'september',
11
- 'october',
12
- 'november',
13
- 'december',
14
- ];
15
- export const englishShortMonthNames = englishFullMonthNames.map((longMonthName) => longMonthName.slice(0, 3));
16
- export class InvalidDateError extends Error {
17
- constructor() {
18
- super(...arguments);
19
- this.name = 'InvalidDateError';
20
- }
21
- }
22
- /**
23
- * @param slashFormatString String that should be of format "MM/DD/YY", "MM/DD/YYYY". When the year
24
- * portion only contains 2 numbers ("MM/DD/YY") the century must be provided in the form of the
25
- * yearPrefix input.
26
- * @param yearPrefix String or number that is used to prefix slash format strings that only contain
27
- * 2 digits ("MM/DD/YY"). If the year is entirely missing form the given slash format string, the
28
- * year will default to year 00 of the given century. See test file for examples.
29
- */
30
- export function createDateFromSlashFormat(slashFormatString, yearPrefix = '') {
31
- const [month, day, rawYearEnding = '',] = slashFormatString.split('/');
32
- if (!month || !day) {
33
- throw new Error(`Unable to extract month or day from "${slashFormatString}"`);
34
- }
35
- const yearEnding = rawYearEnding.length < 4 ? `${yearPrefix}${rawYearEnding.padStart(2, '0')}` : rawYearEnding;
36
- const returnDate = createDateFromUtcIsoFormat(`${yearEnding.padStart(4, '0')}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`);
37
- return returnDate;
38
- }
39
- /**
40
- * @param commaFormatString Should be at string of the form "monthName dayNumber, fullYear" Example:
41
- * "May 19, 2005"
42
- * @param ignoreInvalidMonth Set to true to ignore invalid months and just use the current UTC month
43
- */
44
- export function createDateFromNamedCommaFormat(commaFormatString, ignoreInvalidMonth = false) {
45
- const [monthName, dayNumber, fullYear,] = commaFormatString.replace(',', '').split(' ');
46
- if (!monthName || !dayNumber || !fullYear) {
47
- throw new InvalidDateError(`Invalid ${createDateFromNamedCommaFormat.name} input: ${commaFormatString}`);
48
- }
49
- const longMonthIndex = englishFullMonthNames.indexOf(monthName.toLowerCase());
50
- const shortMonthIndex = englishShortMonthNames.indexOf(monthName.toLowerCase());
51
- let monthIndex = longMonthIndex === -1 ? shortMonthIndex : longMonthIndex;
52
- if (monthIndex === -1) {
53
- if (ignoreInvalidMonth) {
54
- monthIndex = new Date().getUTCMonth();
55
- }
56
- else {
57
- throw new InvalidDateError(`Month name ${monthName} was not found.`);
58
- }
59
- }
60
- const returnDate = createDateFromUtcIsoFormat(`${fullYear.padStart(4, '0')}-${String(monthIndex + 1).padStart(2, '0')}-${dayNumber.padStart(2, '0')}`);
61
- return returnDate;
62
- }
63
- /**
64
- * Converts an iso-formatted string to a UTC date object. The time is nulled out to all zeros.
65
- *
66
- * @param isoFormatString Should be a date in the format YYYY-MM-DD.
67
- */
68
- export function createDateFromUtcIsoFormat(isoFormatString) {
69
- const utcDate = new Date(isoFormatString + 'T00:00:00.000Z');
70
- if (isNaN(Number(utcDate))) {
71
- throw new InvalidDateError(`Invalid utc date formed from input "${isoFormatString}"`);
72
- }
73
- return utcDate;
74
- }
@@ -1,41 +0,0 @@
1
- import { capitalizeFirstLetter, getObjectTypedKeys, hasKey } from '../..';
2
- /**
3
- * For the properties that don't have setters and getters named directly after them. For example, to
4
- * modify "milliseconds", we can just use that string directly: getUTCMilliseconds. However, for
5
- * "Months", we have to use getUTCMonth.
6
- */
7
- const differentlyNamedDateSettersAndGetterKeys = {
8
- days: {
9
- getKey: 'getUTCDate',
10
- setKey: 'setUTCDate',
11
- },
12
- months: {
13
- getKey: 'getUTCMonth',
14
- setKey: 'setUTCMonth',
15
- },
16
- years: {
17
- getKey: 'getUTCFullYear',
18
- setKey: 'setUTCFullYear',
19
- },
20
- };
21
- export function calculateRelativeDate(startingDate, calculations) {
22
- if (!(startingDate instanceof Date)) {
23
- startingDate = new Date(startingDate);
24
- }
25
- let returnDate = new Date(startingDate);
26
- getObjectTypedKeys(calculations).forEach((calculationKey) => {
27
- const calculationValue = calculations[calculationKey];
28
- if (!calculationValue) {
29
- return;
30
- }
31
- const { getKey, setKey } = hasKey(differentlyNamedDateSettersAndGetterKeys, calculationKey)
32
- ? differentlyNamedDateSettersAndGetterKeys[calculationKey]
33
- : {
34
- getKey: `getUTC${capitalizeFirstLetter(calculationKey)}`,
35
- setKey: `setUTC${capitalizeFirstLetter(calculationKey)}`,
36
- };
37
- const currentValue = returnDate[getKey]();
38
- returnDate[setKey](currentValue + calculationValue);
39
- });
40
- return returnDate;
41
- }
@@ -1,11 +0,0 @@
1
- export function addPx(input) {
2
- if (String(input).endsWith('px')) {
3
- return String(input);
4
- }
5
- else {
6
- return `${input}px`;
7
- }
8
- }
9
- export function removePx(input) {
10
- return Number(input.replace(/px$/, ''));
11
- }
@@ -1,26 +0,0 @@
1
- export declare const englishFullMonthNames: readonly ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"];
2
- export declare const englishShortMonthNames: string[];
3
- export declare class InvalidDateError extends Error {
4
- readonly name = "InvalidDateError";
5
- }
6
- /**
7
- * @param slashFormatString String that should be of format "MM/DD/YY", "MM/DD/YYYY". When the year
8
- * portion only contains 2 numbers ("MM/DD/YY") the century must be provided in the form of the
9
- * yearPrefix input.
10
- * @param yearPrefix String or number that is used to prefix slash format strings that only contain
11
- * 2 digits ("MM/DD/YY"). If the year is entirely missing form the given slash format string, the
12
- * year will default to year 00 of the given century. See test file for examples.
13
- */
14
- export declare function createDateFromSlashFormat(slashFormatString: string, yearPrefix?: number | string): Date;
15
- /**
16
- * @param commaFormatString Should be at string of the form "monthName dayNumber, fullYear" Example:
17
- * "May 19, 2005"
18
- * @param ignoreInvalidMonth Set to true to ignore invalid months and just use the current UTC month
19
- */
20
- export declare function createDateFromNamedCommaFormat(commaFormatString: string, ignoreInvalidMonth?: boolean): Date;
21
- /**
22
- * Converts an iso-formatted string to a UTC date object. The time is nulled out to all zeros.
23
- *
24
- * @param isoFormatString Should be a date in the format YYYY-MM-DD.
25
- */
26
- export declare function createDateFromUtcIsoFormat(isoFormatString: string): Date;
@@ -1,11 +0,0 @@
1
- import { PartialAndUndefined } from '../..';
2
- export type RelativeDateCalculation = PartialAndUndefined<{
3
- milliseconds: number;
4
- seconds: number;
5
- minutes: number;
6
- hours: number;
7
- days: number;
8
- months: number;
9
- years: number;
10
- }>;
11
- export declare function calculateRelativeDate(startingDate: Date | number | string, calculations: RelativeDateCalculation): Date;
@@ -1,3 +0,0 @@
1
- export type WithPx = `${string | number}px`;
2
- export declare function addPx(input: number | string): WithPx;
3
- export declare function removePx(input: WithPx | string): number;