svelte-copyright 1.2.0 → 2.0.0-rc.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dave Lunny
3
+ Copyright (c) 2023 Dave Lunny
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -50,7 +50,7 @@ This will output HTML which looks something like this:
50
50
 
51
51
  ```html
52
52
  <footer>
53
- <span>© Copyright 2020 Dave Lunny</span>
53
+ <span>© Copyright 2023 Dave Lunny</span>
54
54
  </footer>
55
55
  ```
56
56
 
@@ -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
+ &#169; Copyright {displayDate}
17
+ {/if}
18
+ <slot />
19
+ {#if position === POSITION.POST}
20
+ &#169; 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 {};
@@ -0,0 +1,3 @@
1
+ import type { Format, Position } from './types.js';
2
+ export declare const FORMAT: Record<string, Format>;
3
+ export declare const POSITION: Record<string, Position>;
@@ -0,0 +1,8 @@
1
+ export const FORMAT = {
2
+ NUMERIC: 'numeric',
3
+ TWO_DIGIT: '2-digit',
4
+ };
5
+ export const POSITION = {
6
+ PRE: 'pre',
7
+ POST: 'post',
8
+ };
@@ -0,0 +1 @@
1
+ export { default } from "./Copyright.svelte";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // Reexport your entry components here
2
+ export { default } from './Copyright.svelte';
@@ -0,0 +1,2 @@
1
+ export type Format = '2-digit' | 'numeric';
2
+ export type Position = 'post' | 'pre';
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
- return new Date();
4
+ return new Date();
6
5
  }
7
-
8
6
  // Gets the year string from a date.
9
7
  export function toYear(date = today()) {
10
- return date.getFullYear().toString();
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
- if (format === FORMAT.NUMERIC) {
21
- return toYear(date);
22
- }
23
- if (format === FORMAT.TWO_DIGIT) {
24
- return `’${toYear(date).slice(-2)}`;
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
- // Don't show a range if years are the same, as that would be dumb.
36
- if (date1 === date2) {
37
- return date1;
38
- }
39
- return `${date1} - ${date2}`;
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
- showRange = false,
51
- date = today(),
52
- format = FORMAT.NUMERIC,
53
- }) {
54
- const formatted = formatDate(date, format);
55
- // Early return if we don't show the range
56
- if (!showRange) {
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,75 @@
1
1
  {
2
2
  "name": "svelte-copyright",
3
3
  "description": "A Svelte component to format and display a copyright notice.",
4
- "version": "1.2.0",
4
+ "version": "2.0.0-rc.0",
5
5
  "author": {
6
6
  "name": "himynameisdave",
7
7
  "email": "d@velunny.com",
8
8
  "url": "https://himynameisdave.com"
9
9
  },
10
- "svelte": "src/index.js",
11
- "module": "lib/index.mjs",
12
- "main": "lib/index.js",
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
- "build": "rollup -c --bundleConfigAsCjs",
19
- "test": "jest src",
20
- "release": "np --no-yarn"
21
- },
22
- "devDependencies": {
23
- "@babel/core": "^7.20.5",
24
- "@babel/preset-env": "^7.20.2",
25
- "@rollup/plugin-node-resolve": "^15.0.1",
26
- "@testing-library/jest-dom": "^5.16.5",
27
- "@testing-library/svelte": "^3.2.2",
28
- "babel-jest": "^29.3.1",
29
- "husky": "^8.0.2",
30
- "jest": "^29.3.1",
31
- "jest-environment-jsdom": "^29.3.1",
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
- "husky": {
42
- "hooks": {
43
- "pre-commit": "npm test"
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/index.d.ts",
32
+ "svelte": "./dist/index.js"
44
33
  }
45
34
  },
46
- "keywords": [
47
- "svelte",
48
- "svelte-component",
49
- "copyright",
50
- "ui-component",
51
- "svelte-copyright"
35
+ "files": [
36
+ "dist",
37
+ "!dist/**/*.test.*",
38
+ "!dist/**/*.spec.*"
52
39
  ],
53
40
  "engines": {
54
- "node": ">= 10"
41
+ "node": ">= 16"
42
+ },
43
+ "lint-staged": {
44
+ "*.ts": "eslint ./ --fix --quiet",
45
+ "*.svelte": "eslint ./ --fix --quiet"
55
46
  },
56
- "repository": {
57
- "type": "git",
58
- "url": "git+https://github.com/himynameisdave/svelte-copyright.git"
47
+ "peerDependencies": {
48
+ "svelte": "^4.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@playwright/test": "^1.37.0",
52
+ "@sveltejs/adapter-auto": "^2.0.0",
53
+ "@sveltejs/kit": "^1.22.6",
54
+ "@sveltejs/package": "^2.2.1",
55
+ "@typescript-eslint/eslint-plugin": "^6.3.0",
56
+ "@typescript-eslint/parser": "^6.3.0",
57
+ "eslint": "^8.47.0",
58
+ "eslint-config-himynameisdave": "^7.1.0",
59
+ "eslint-plugin-promise": "^6.1.1",
60
+ "eslint-plugin-svelte": "^2.32.4",
61
+ "eslint-plugin-unicorn": "^48.0.1",
62
+ "husky": "^8.0.3",
63
+ "less": "^4.2.0",
64
+ "lint-staged": "^14.0.0",
65
+ "np": "^8.0.4",
66
+ "publint": "^0.2.0",
67
+ "svelte": "^4.2.0",
68
+ "svelte-check": "^3.5.0",
69
+ "tslib": "^2.6.1",
70
+ "typescript": "^5.0.0",
71
+ "vite": "^4.4.9",
72
+ "vitest": "^0.34.1"
59
73
  },
60
- "homepage": "https://github.com/himynameisdave/svelte-copyright",
61
- "license": "MIT",
62
- "sideEffects": false,
63
74
  "private": false
64
75
  }