@tuspe/components 1.6.26

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/dist/index.js ADDED
@@ -0,0 +1,105 @@
1
+ import { get, writable } from 'svelte/store';
2
+ import Breadcrumbs from './Breadcrumbs.svelte';
3
+ import Button from './Button.svelte';
4
+ import ButtonArrow from './ButtonArrow.svelte';
5
+ import ButtonClose from './ButtonClose.svelte';
6
+ import ButtonMenu from './ButtonMenu.svelte';
7
+ import Checkbox from './Checkbox.svelte';
8
+ import Image from './Image.svelte';
9
+ import Input from './Input.svelte';
10
+ import Modal from './Modal.svelte';
11
+ import Select from './Select.svelte';
12
+ export { Breadcrumbs, Button, ButtonArrow, ButtonClose, ButtonMenu, Checkbox, Image, Input, Modal, Select };
13
+ export const loading = writable(0);
14
+ /**
15
+ * PRICES AND NUMBERS
16
+ */
17
+ export const formatPrice = (value, comma = false, currency = '€') => {
18
+ if (!value) {
19
+ return '0.00 ' + currency;
20
+ }
21
+ let price = Number(value)
22
+ .toFixed(2) // Ensure two decimal places
23
+ .replace(/\B(?=(\d{3})+(?!\d))/g, ' '); // Add space as thousand separator
24
+ if (comma) {
25
+ price = price.replace('.', ','); // Replace dot with comma
26
+ }
27
+ if (currency) {
28
+ price += ' ' + currency;
29
+ }
30
+ return price;
31
+ };
32
+ export const fixNumber = (value) => {
33
+ if (typeof value === 'string') {
34
+ value = Number(value);
35
+ }
36
+ if (!value) {
37
+ return 0;
38
+ }
39
+ return Math.round((value + Number.EPSILON) * 100) / 100;
40
+ };
41
+ /**
42
+ * VAT CALCULATION
43
+ */
44
+ const defaultVatPercentage = 25.5;
45
+ export const calculateTax = (total, vatPercentage = defaultVatPercentage) => fixNumber((vatPercentage * total) / (100 + vatPercentage));
46
+ export const calculatePreTax = (total, vatPercentage = defaultVatPercentage) => fixNumber(total - calculateTax(total, vatPercentage));
47
+ /**
48
+ * STRING VALIDATIONS
49
+ */
50
+ export const slugify = (value) => {
51
+ if (!value) {
52
+ return '';
53
+ }
54
+ return value
55
+ .toLowerCase()
56
+ .replace(/[äå]/g, 'a') // Replace ä and å with a
57
+ .replace(/ö/g, 'o') // Replace ö with o
58
+ .replace(/['"]/g, '') // Remove ' and "
59
+ .replace(/[^a-z0-9]+/g, '-') // Replace any non-alphanumeric characters with -
60
+ .replace(/^-+|-+$/g, ''); // Trim leading and trailing hyphens
61
+ };
62
+ export const validateSlug = (value) => {
63
+ return value && slugify(value) === value ? true : false;
64
+ };
65
+ export const validateEmail = (email) => {
66
+ var re = /\S+@\S+\.\S+/;
67
+ return re.test(email);
68
+ };
69
+ export const validateString = (value) => {
70
+ return value && value.replace(/[^\w\s@!.:;äÄöÖåÅ/%&-]/gi, '') === value ? true : false;
71
+ };
72
+ /**
73
+ * ARRAY VALIDATIONS
74
+ */
75
+ export const validateArray = (value, items = 0) => {
76
+ return value && Array.isArray(value) && value.length > items ? true : false;
77
+ };
78
+ /**
79
+ * CACHE
80
+ */
81
+ export const cacheValues = writable({});
82
+ export const handleCache = (key, value = undefined) => {
83
+ if (!key) {
84
+ return null;
85
+ }
86
+ const newKey = slugify(key);
87
+ const cache = get(cacheValues);
88
+ if (value) {
89
+ const newValues = cache ? { ...cache, [newKey]: value } : { [newKey]: value };
90
+ cacheValues.set({ ...newValues });
91
+ }
92
+ else if (cache?.[newKey]) {
93
+ return cache[newKey];
94
+ }
95
+ return null;
96
+ };
97
+ /**
98
+ * PREVENT DEFAULT
99
+ */
100
+ export const preventDefault = (fn) => {
101
+ return function (event) {
102
+ event.preventDefault();
103
+ fn.call(this, event);
104
+ };
105
+ };
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@tuspe/components",
3
+ "version": "1.6.26",
4
+ "description": "A reusable SvelteKit component library for form elements, breadcrumbs, prices and images.",
5
+ "keywords": [
6
+ "svelteKit",
7
+ "components",
8
+ "cache",
9
+ "modal",
10
+ "breadcrumb",
11
+ "form",
12
+ "numbers",
13
+ "image",
14
+ "input",
15
+ "checkbox",
16
+ "select",
17
+ "preventDefault"
18
+ ],
19
+ "homepage": "https://github.com/TuspeDesign/svelte-components",
20
+ "license": "MIT",
21
+ "author": {
22
+ "name": "Timo Anttila",
23
+ "url": "https://timoanttila.com"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/TuspeDesign/svelte-components.git"
28
+ },
29
+ "scripts": {
30
+ "dev": "vite dev",
31
+ "build": "vite build && npm run prepack",
32
+ "preview": "vite preview",
33
+ "prepare": "svelte-kit sync",
34
+ "prepack": "svelte-kit sync && svelte-package",
35
+ "publint": "publint .",
36
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
37
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
38
+ "format": "prettier --write .",
39
+ "lint": "prettier --check . && eslint .",
40
+ "publish": "npm publish --access public"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "!dist/**/*.test.*",
45
+ "!dist/**/*.spec.*"
46
+ ],
47
+ "sideEffects": false,
48
+ "svelte": "./dist/index.js",
49
+ "types": "./dist/index.d.ts",
50
+ "type": "module",
51
+ "exports": {
52
+ ".": {
53
+ "types": "./dist/index.d.ts",
54
+ "svelte": "./dist/index.js"
55
+ }
56
+ },
57
+ "peerDependencies": {
58
+ "@sveltejs/kit": "^2.17.2",
59
+ "svelte": "^5.20.2"
60
+ },
61
+ "devDependencies": {
62
+ "@eslint/compat": "^1.2.7",
63
+ "@eslint/js": "^9.21.0",
64
+ "@sveltejs/adapter-static": "^3.0.8",
65
+ "@sveltejs/kit": "^2.17.2",
66
+ "@sveltejs/package": "^2.3.10",
67
+ "@sveltejs/vite-plugin-svelte": "^5.0.3",
68
+ "eslint-config-prettier": "^10.0.1",
69
+ "eslint-plugin-svelte": "^2.46.1",
70
+ "eslint": "^9.21.0",
71
+ "globals": "^16.0.0",
72
+ "prettier-plugin-svelte": "^3.3.3",
73
+ "prettier": "^3.5.2",
74
+ "publint": "^0.3.6",
75
+ "svelte-check": "^4.1.4",
76
+ "svelte": "^5.20.2",
77
+ "typescript-eslint": "^8.24.1",
78
+ "typescript": "^5.7.3",
79
+ "vite": "^6.1.1"
80
+ }
81
+ }