svelte-copyright 1.2.0 → 2.0.0-rc.1
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/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/Copyright.svelte +22 -0
- package/dist/Copyright.svelte.d.ts +23 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/dist/utils/date.d.ts +30 -0
- package/{src → dist}/utils/date.js +23 -32
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +51 -46
- package/lib/index.js +0 -691
- package/lib/index.mjs +0 -680
- package/src/Copyright.svelte +0 -30
- package/src/__tests__/Copyright.spec.js +0 -61
- package/src/__tests__/Copyright.spec.svelte +0 -11
- package/src/constants.js +0 -9
- package/src/index.js +0 -2
- package/src/utils/__test__/date.spec.js +0 -88
- package/src/utils/index.js +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script>import { FORMAT, POSITION } from "./constants.js";
|
|
2
|
+
import { getDisplayDate, today } from "./utils/index.js";
|
|
3
|
+
export let date = today();
|
|
4
|
+
export let format = FORMAT.NUMERIC;
|
|
5
|
+
export let position = POSITION.PRE;
|
|
6
|
+
export let showRange = false;
|
|
7
|
+
const displayDate = getDisplayDate({
|
|
8
|
+
showRange,
|
|
9
|
+
format,
|
|
10
|
+
date
|
|
11
|
+
});
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<span {...$$restProps}>
|
|
15
|
+
{#if position === POSITION.PRE}
|
|
16
|
+
© Copyright {displayDate}
|
|
17
|
+
{/if}
|
|
18
|
+
<slot />
|
|
19
|
+
{#if position === POSITION.POST}
|
|
20
|
+
© Copyright {displayDate}
|
|
21
|
+
{/if}
|
|
22
|
+
</span>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { Format, Position } from './types.js';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
date?: Date | undefined;
|
|
7
|
+
format?: Format | undefined;
|
|
8
|
+
position?: Position | undefined;
|
|
9
|
+
showRange?: boolean | undefined;
|
|
10
|
+
};
|
|
11
|
+
events: {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
};
|
|
14
|
+
slots: {
|
|
15
|
+
default: {};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type CopyrightProps = typeof __propDef.props;
|
|
19
|
+
export type CopyrightEvents = typeof __propDef.events;
|
|
20
|
+
export type CopyrightSlots = typeof __propDef.slots;
|
|
21
|
+
export default class Copyright extends SvelteComponent<CopyrightProps, CopyrightEvents, CopyrightSlots> {
|
|
22
|
+
}
|
|
23
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./Copyright.svelte";
|
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare function today(): Date;
|
|
2
|
+
export declare function toYear(date?: Date): string;
|
|
3
|
+
/**
|
|
4
|
+
* Formats the date, just for you!
|
|
5
|
+
*
|
|
6
|
+
* @param {Date} date - Date to format
|
|
7
|
+
* @param {'numeric' | '2-digit'} format - Format for the date.
|
|
8
|
+
*/
|
|
9
|
+
export declare function formatDate(date?: Date, format?: import("../types.js").Format): string;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the "range string", unless the dates are the same.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} date1 - First date (formatted to a string)
|
|
14
|
+
* @param {string} date2 - Second date (formatted to a string).
|
|
15
|
+
*/
|
|
16
|
+
export declare function getRange(date1: string, date2: string): string;
|
|
17
|
+
type GetDisplayDateProps = {
|
|
18
|
+
showRange?: boolean;
|
|
19
|
+
date?: Date;
|
|
20
|
+
format?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Returns the displayed date for the component.
|
|
24
|
+
*
|
|
25
|
+
* @param {boolean} options.showRange - If a date range should be displayed.
|
|
26
|
+
* @param {Date} options.date - Copyright year to be used. If showRange is true, this is the start year of the range.
|
|
27
|
+
* @param {'numeric' | '2-digit'} options.format - Date format to be used.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getDisplayDate({ showRange, date, format, }: GetDisplayDateProps): string;
|
|
30
|
+
export {};
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { FORMAT } from '../constants';
|
|
2
|
-
|
|
1
|
+
import { FORMAT } from '../constants.js';
|
|
3
2
|
// Returns new Date() - for default/fallback values.
|
|
4
3
|
export function today() {
|
|
5
|
-
|
|
4
|
+
return new Date();
|
|
6
5
|
}
|
|
7
|
-
|
|
8
6
|
// Gets the year string from a date.
|
|
9
7
|
export function toYear(date = today()) {
|
|
10
|
-
|
|
8
|
+
return date.getFullYear().toString();
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
/**
|
|
14
11
|
* Formats the date, just for you!
|
|
15
12
|
*
|
|
@@ -17,14 +14,13 @@ export function toYear(date = today()) {
|
|
|
17
14
|
* @param {'numeric' | '2-digit'} format - Format for the date.
|
|
18
15
|
*/
|
|
19
16
|
export function formatDate(date = today(), format = FORMAT.NUMERIC) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
if (format === FORMAT.NUMERIC) {
|
|
18
|
+
return toYear(date);
|
|
19
|
+
}
|
|
20
|
+
if (format === FORMAT.TWO_DIGIT) {
|
|
21
|
+
return `’${toYear(date).slice(-2)}`;
|
|
22
|
+
}
|
|
26
23
|
}
|
|
27
|
-
|
|
28
24
|
/**
|
|
29
25
|
* Returns the "range string", unless the dates are the same.
|
|
30
26
|
*
|
|
@@ -32,13 +28,12 @@ export function formatDate(date = today(), format = FORMAT.NUMERIC) {
|
|
|
32
28
|
* @param {string} date2 - Second date (formatted to a string).
|
|
33
29
|
*/
|
|
34
30
|
export function getRange(date1, date2) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
// Don't show a range if years are the same, as that would be dumb.
|
|
32
|
+
if (date1 === date2) {
|
|
33
|
+
return date1;
|
|
34
|
+
}
|
|
35
|
+
return `${date1} - ${date2}`;
|
|
40
36
|
}
|
|
41
|
-
|
|
42
37
|
/**
|
|
43
38
|
* Returns the displayed date for the component.
|
|
44
39
|
*
|
|
@@ -46,17 +41,13 @@ export function getRange(date1, date2) {
|
|
|
46
41
|
* @param {Date} options.date - Copyright year to be used. If showRange is true, this is the start year of the range.
|
|
47
42
|
* @param {'numeric' | '2-digit'} options.format - Date format to be used.
|
|
48
43
|
*/
|
|
49
|
-
export function getDisplayDate({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return formatted;
|
|
58
|
-
}
|
|
59
|
-
// Get today's year, formatted correctly.
|
|
60
|
-
const formattedToday = formatDate(today(), format);
|
|
61
|
-
return getRange(formatted, formattedToday);
|
|
44
|
+
export function getDisplayDate({ showRange = false, date = today(), format = FORMAT.NUMERIC, }) {
|
|
45
|
+
const formatted = formatDate(date, format);
|
|
46
|
+
// Early return if we don't show the range
|
|
47
|
+
if (!showRange) {
|
|
48
|
+
return formatted;
|
|
49
|
+
}
|
|
50
|
+
// Get today's year, formatted correctly.
|
|
51
|
+
const formattedToday = formatDate(today(), format);
|
|
52
|
+
return getRange(formatted, formattedToday);
|
|
62
53
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getDisplayDate, today } from './date.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getDisplayDate, today } from './date.js';
|
package/package.json
CHANGED
|
@@ -1,64 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-copyright",
|
|
3
3
|
"description": "A Svelte component to format and display a copyright notice.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-rc.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "himynameisdave",
|
|
7
7
|
"email": "d@velunny.com",
|
|
8
8
|
"url": "https://himynameisdave.com"
|
|
9
9
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"files": [
|
|
14
|
-
"src",
|
|
15
|
-
"lib"
|
|
16
|
-
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"svelte": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
17
13
|
"scripts": {
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"np": "^7.6.2",
|
|
33
|
-
"rollup": "^3.7.3",
|
|
34
|
-
"rollup-plugin-svelte": "^7.1.0",
|
|
35
|
-
"svelte": "^3.54.0",
|
|
36
|
-
"svelte-jester": "^2.3.2"
|
|
37
|
-
},
|
|
38
|
-
"peerDependencies": {
|
|
39
|
-
"svelte": "^3.0.0"
|
|
14
|
+
"dev": "vite dev",
|
|
15
|
+
"build": "vite build && npm run package",
|
|
16
|
+
"preview": "vite preview",
|
|
17
|
+
"package": "svelte-kit sync && svelte-package && publint",
|
|
18
|
+
"prepublishOnly": "npm run package",
|
|
19
|
+
"test": "npm run test:integration && npm run test:unit",
|
|
20
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
21
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
|
22
|
+
"lint": "eslint . --ext .js,.ts,.svelte",
|
|
23
|
+
"lint:fix": "eslint . --ext .js,.ts,.svelte --fix",
|
|
24
|
+
"test:integration": "playwright test",
|
|
25
|
+
"test:unit": "vitest --run",
|
|
26
|
+
"test:unit:watch": "vitest",
|
|
27
|
+
"release": "npm run package && np --no-yarn"
|
|
40
28
|
},
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"svelte": "./dist/index.js"
|
|
44
33
|
}
|
|
45
34
|
},
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"ui-component",
|
|
51
|
-
"svelte-copyright"
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"!dist/**/*.test.*",
|
|
38
|
+
"!dist/**/*.spec.*"
|
|
52
39
|
],
|
|
53
40
|
"engines": {
|
|
54
|
-
"node": ">=
|
|
41
|
+
"node": ">= 16"
|
|
42
|
+
},
|
|
43
|
+
"lint-staged": {
|
|
44
|
+
"*.ts": "eslint ./ --fix --quiet",
|
|
45
|
+
"*.svelte": "eslint ./ --fix --quiet"
|
|
55
46
|
},
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"svelte": "^4.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@playwright/test": "^1.37.1",
|
|
52
|
+
"@sveltejs/adapter-auto": "^2.0.0",
|
|
53
|
+
"@sveltejs/kit": "^1.24.0",
|
|
54
|
+
"@sveltejs/package": "^2.2.2",
|
|
55
|
+
"eslint-config-himynameisdave": "^8.1.0",
|
|
56
|
+
"husky": "^8.0.3",
|
|
57
|
+
"less": "^4.2.0",
|
|
58
|
+
"lint-staged": "^14.0.1",
|
|
59
|
+
"np": "^8.0.4",
|
|
60
|
+
"publint": "^0.2.2",
|
|
61
|
+
"svelte": "^4.2.0",
|
|
62
|
+
"svelte-check": "^3.5.1",
|
|
63
|
+
"tslib": "^2.6.2",
|
|
64
|
+
"typescript": "^5.2.2",
|
|
65
|
+
"vite": "^4.4.9",
|
|
66
|
+
"vitest": "^0.34.3"
|
|
59
67
|
},
|
|
60
|
-
"homepage": "https://github.com/himynameisdave/svelte-copyright",
|
|
61
|
-
"license": "MIT",
|
|
62
|
-
"sideEffects": false,
|
|
63
68
|
"private": false
|
|
64
69
|
}
|