@qr-platform/qr-code.js 0.11.5 → 0.11.9
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/docs/advanced-examples.md +269 -8
- package/docs/api-reference-guide.md +20 -12
- package/docs/documentation.md +501 -11
- package/docs/examples.md +127 -21
- package/docs/license-management.md +4 -13
- package/docs/typescript-types-definitions.md +198 -13
- package/docs/usage-guide.md +236 -65
- package/lib/browser.d.ts +3 -0
- package/lib/browser.js +8 -0
- package/lib/chunks/{zbar-scan-validator-CdUmQrkV.js → zbar-scan-validator-CPwNKIiK.js} +1 -1
- package/lib/chunks/zxing-scan-validator-BhQsyUDu.js +1 -0
- package/lib/esm.js +8 -0
- package/lib/index.js +1 -1
- package/lib/node/browser.d.ts +3 -0
- package/lib/node.js +1 -1
- package/package.json +1 -1
- package/lib/chunks/zxing-scan-validator-BF0vLC4Z.js +0 -1
package/docs/documentation.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
---
|
|
2
|
+
title: 'QRCode.js Comprehensive Documentation'
|
|
3
|
+
description: 'Comprehensive documentation for QRCode.js, including installation, usage, and customization options, with a focus on styling, borders, and advanced features.'
|
|
4
|
+
---
|
|
3
5
|
|
|
4
6
|
## Introduction
|
|
5
7
|
|
|
@@ -2136,13 +2138,501 @@ enum ImageMode {
|
|
|
2136
2138
|
}
|
|
2137
2139
|
```
|
|
2138
2140
|
|
|
2139
|
-
|
|
2141
|
+
## Metadata Management
|
|
2142
|
+
|
|
2143
|
+
QRCode.js provides comprehensive metadata management capabilities for organizing, tracking, and categorizing QR code instances. This section covers the various metadata features available through both instance methods and the builder pattern.
|
|
2144
|
+
|
|
2145
|
+
### Overview
|
|
2146
|
+
|
|
2147
|
+
Metadata in QRCode.js allows you to:
|
|
2148
|
+
- Assign unique identifiers to QR code instances
|
|
2149
|
+
- Provide human-readable names and descriptions
|
|
2150
|
+
- Attach custom data for tracking and analytics
|
|
2151
|
+
- Retrieve comprehensive settings information
|
|
2152
|
+
- Support enterprise-level QR code management workflows
|
|
2153
|
+
|
|
2154
|
+
### Instance Metadata Methods
|
|
2155
|
+
|
|
2156
|
+
Once a QR code instance is created, you can manage its metadata using chainable methods:
|
|
2157
|
+
|
|
2158
|
+
#### Setting Metadata
|
|
2159
|
+
|
|
2160
|
+
```typescript
|
|
2161
|
+
const qrCode = new QRCodeJs({
|
|
2162
|
+
data: 'https://company.com/products/laptop-pro'
|
|
2163
|
+
});
|
|
2164
|
+
|
|
2165
|
+
// Chain metadata methods for clean configuration
|
|
2166
|
+
qrCode
|
|
2167
|
+
.setId('product-laptop-pro-2024')
|
|
2168
|
+
.setName('Laptop Pro QR Code')
|
|
2169
|
+
.setDescription('QR code for Laptop Pro product page with specifications and pricing')
|
|
2170
|
+
.setMetadata({
|
|
2171
|
+
productId: 'laptop-pro-001',
|
|
2172
|
+
category: 'electronics',
|
|
2173
|
+
subcategory: 'laptops',
|
|
2174
|
+
brand: 'TechCorp',
|
|
2175
|
+
price: 1299.99,
|
|
2176
|
+
inStock: true,
|
|
2177
|
+
campaign: 'back-to-school-2024',
|
|
2178
|
+
trackingEnabled: true,
|
|
2179
|
+
analytics: {
|
|
2180
|
+
expectedScans: 1000,
|
|
2181
|
+
conversionTarget: 50
|
|
2182
|
+
}
|
|
2183
|
+
});
|
|
2184
|
+
```
|
|
2185
|
+
|
|
2186
|
+
#### Retrieving Metadata
|
|
2187
|
+
|
|
2188
|
+
```typescript
|
|
2189
|
+
// Access individual metadata components
|
|
2190
|
+
const qrId = qrCode.getId(); // 'product-laptop-pro-2024'
|
|
2191
|
+
const qrName = qrCode.getName(); // 'Laptop Pro QR Code'
|
|
2192
|
+
const qrDescription = qrCode.getDescription(); // 'QR code for Laptop Pro...'
|
|
2193
|
+
const customMetadata = qrCode.getMetadata(); // { productId: 'laptop-pro-001', ... }
|
|
2194
|
+
|
|
2195
|
+
// Get comprehensive settings and configuration
|
|
2196
|
+
const settings = qrCode.getSettings();
|
|
2197
|
+
console.log('Complete QR Configuration:', settings);
|
|
2198
|
+
```
|
|
2199
|
+
|
|
2200
|
+
### Builder Pattern Metadata
|
|
2201
|
+
|
|
2202
|
+
The builder pattern provides elegant metadata assignment during QR code construction:
|
|
2203
|
+
|
|
2204
|
+
```typescript
|
|
2205
|
+
const enterpriseQR = QRCodeJs.useTemplate('corporate')
|
|
2206
|
+
.useId('campaign-summer-2024-001')
|
|
2207
|
+
.useName('Summer Campaign Landing Page')
|
|
2208
|
+
.useDescription('Primary QR code for summer marketing campaign directing to landing page')
|
|
2209
|
+
.useMetadata({
|
|
2210
|
+
campaignId: 'summer-2024',
|
|
2211
|
+
campaignType: 'seasonal',
|
|
2212
|
+
targetAudience: ['millennials', 'gen-z'],
|
|
2213
|
+
channels: ['social-media', 'print', 'email'],
|
|
2214
|
+
budget: 25000,
|
|
2215
|
+
duration: {
|
|
2216
|
+
start: '2024-06-01',
|
|
2217
|
+
end: '2024-08-31'
|
|
2218
|
+
},
|
|
2219
|
+
kpis: {
|
|
2220
|
+
primary: 'conversion-rate',
|
|
2221
|
+
secondary: ['engagement', 'reach']
|
|
2222
|
+
},
|
|
2223
|
+
geography: {
|
|
2224
|
+
regions: ['north-america', 'europe'],
|
|
2225
|
+
languages: ['en', 'es', 'fr', 'de']
|
|
2226
|
+
}
|
|
2227
|
+
})
|
|
2228
|
+
.options({
|
|
2229
|
+
data: 'https://company.com/summer-campaign-2024',
|
|
2230
|
+
image: 'https://company.com/assets/summer-logo.png'
|
|
2231
|
+
});
|
|
2232
|
+
```
|
|
2233
|
+
|
|
2234
|
+
### Enterprise Metadata Patterns
|
|
2235
|
+
|
|
2236
|
+
#### Content Management System Integration
|
|
2237
|
+
|
|
2238
|
+
```typescript
|
|
2239
|
+
class CMSQRManager {
|
|
2240
|
+
static createContentQR(content) {
|
|
2241
|
+
const metadata = {
|
|
2242
|
+
contentId: content.id,
|
|
2243
|
+
contentType: content.type,
|
|
2244
|
+
title: content.title,
|
|
2245
|
+
author: content.author,
|
|
2246
|
+
publishDate: content.publishDate,
|
|
2247
|
+
lastModified: content.lastModified,
|
|
2248
|
+
tags: content.tags,
|
|
2249
|
+
language: content.language,
|
|
2250
|
+
seoScore: content.seoScore,
|
|
2251
|
+
readingTime: content.estimatedReadingTime
|
|
2252
|
+
};
|
|
2253
|
+
|
|
2254
|
+
return QRCodeJs.useTemplate('cms-standard')
|
|
2255
|
+
.useId(`cms-${content.type}-${content.id}`)
|
|
2256
|
+
.useName(`${content.title} - ${content.type}`)
|
|
2257
|
+
.useDescription(`QR code for ${content.type}: ${content.title}`)
|
|
2258
|
+
.useMetadata(metadata)
|
|
2259
|
+
.options({
|
|
2260
|
+
data: `https://cms.company.com/content/${content.id}`,
|
|
2261
|
+
qrOptions: { errorCorrectionLevel: 'M' }
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
// Usage
|
|
2267
|
+
const articleQR = CMSQRManager.createContentQR({
|
|
2268
|
+
id: 'art-2024-0315',
|
|
2269
|
+
type: 'article',
|
|
2270
|
+
title: 'Future of Sustainable Technology',
|
|
2271
|
+
author: 'Dr. Jane Smith',
|
|
2272
|
+
publishDate: '2024-03-15',
|
|
2273
|
+
lastModified: '2024-03-20',
|
|
2274
|
+
tags: ['technology', 'sustainability', 'innovation'],
|
|
2275
|
+
language: 'en',
|
|
2276
|
+
seoScore: 94,
|
|
2277
|
+
estimatedReadingTime: '8 minutes'
|
|
2278
|
+
});
|
|
2279
|
+
```
|
|
2280
|
+
|
|
2281
|
+
#### Multi-Channel Campaign Management
|
|
2282
|
+
|
|
2283
|
+
```typescript
|
|
2284
|
+
class CampaignQRGenerator {
|
|
2285
|
+
constructor(campaignConfig) {
|
|
2286
|
+
this.config = campaignConfig;
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
createChannelQR(channel, specific = {}) {
|
|
2290
|
+
const baseMetadata = {
|
|
2291
|
+
campaignId: this.config.id,
|
|
2292
|
+
campaignName: this.config.name,
|
|
2293
|
+
channel: channel.name,
|
|
2294
|
+
channelType: channel.type,
|
|
2295
|
+
medium: channel.medium,
|
|
2296
|
+
budget: channel.budget,
|
|
2297
|
+
expectedReach: channel.expectedReach,
|
|
2298
|
+
createdAt: new Date().toISOString(),
|
|
2299
|
+
...this.config.globalMetadata
|
|
2300
|
+
};
|
|
2301
|
+
|
|
2302
|
+
return QRCodeJs.useTemplate(this.config.template)
|
|
2303
|
+
.useId(`${this.config.id}-${channel.name}-${Date.now()}`)
|
|
2304
|
+
.useName(`${this.config.name} - ${channel.displayName}`)
|
|
2305
|
+
.useDescription(`${this.config.name} campaign QR for ${channel.displayName}`)
|
|
2306
|
+
.useMetadata({ ...baseMetadata, ...specific })
|
|
2307
|
+
.options({
|
|
2308
|
+
data: `${this.config.baseUrl}?utm_source=${channel.name}&utm_medium=${channel.medium}&utm_campaign=${this.config.id}`,
|
|
2309
|
+
...channel.qrOptions
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
// Usage
|
|
2315
|
+
const campaignGen = new CampaignQRGenerator({
|
|
2316
|
+
id: 'holiday-2024',
|
|
2317
|
+
name: 'Holiday Sale Campaign',
|
|
2318
|
+
template: 'festive',
|
|
2319
|
+
baseUrl: 'https://store.company.com/holiday-sale',
|
|
2320
|
+
globalMetadata: {
|
|
2321
|
+
brand: 'TechCorp',
|
|
2322
|
+
season: 'holiday',
|
|
2323
|
+
year: 2024,
|
|
2324
|
+
department: 'marketing'
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
|
|
2328
|
+
const socialQR = campaignGen.createChannelQR(
|
|
2329
|
+
{
|
|
2330
|
+
name: 'instagram',
|
|
2331
|
+
displayName: 'Instagram',
|
|
2332
|
+
type: 'social',
|
|
2333
|
+
medium: 'social-media',
|
|
2334
|
+
budget: 5000,
|
|
2335
|
+
expectedReach: 50000,
|
|
2336
|
+
qrOptions: { margin: 20 }
|
|
2337
|
+
},
|
|
2338
|
+
{
|
|
2339
|
+
platform: 'instagram',
|
|
2340
|
+
contentType: 'story',
|
|
2341
|
+
demographics: 'young-adults'
|
|
2342
|
+
}
|
|
2343
|
+
);
|
|
2344
|
+
```
|
|
2345
|
+
|
|
2346
|
+
#### Analytics and Tracking Integration
|
|
2347
|
+
|
|
2348
|
+
```typescript
|
|
2349
|
+
class AnalyticsQRWrapper {
|
|
2350
|
+
static enhanceWithAnalytics(qrInstance, analyticsConfig) {
|
|
2351
|
+
const enhancedMetadata = {
|
|
2352
|
+
...qrInstance.getMetadata(),
|
|
2353
|
+
analytics: {
|
|
2354
|
+
trackingId: analyticsConfig.trackingId,
|
|
2355
|
+
platform: analyticsConfig.platform,
|
|
2356
|
+
goals: analyticsConfig.goals,
|
|
2357
|
+
customDimensions: analyticsConfig.customDimensions,
|
|
2358
|
+
autoTrack: analyticsConfig.autoTrack,
|
|
2359
|
+
enableHeatmap: analyticsConfig.enableHeatmap,
|
|
2360
|
+
retentionPeriod: analyticsConfig.retentionPeriod
|
|
2361
|
+
},
|
|
2362
|
+
privacy: {
|
|
2363
|
+
gdprCompliant: true,
|
|
2364
|
+
anonymized: analyticsConfig.anonymized,
|
|
2365
|
+
consentRequired: analyticsConfig.consentRequired
|
|
2366
|
+
}
|
|
2367
|
+
};
|
|
2368
|
+
|
|
2369
|
+
qrInstance.setMetadata(enhancedMetadata);
|
|
2370
|
+
return qrInstance;
|
|
2371
|
+
}
|
|
2372
|
+
|
|
2373
|
+
static createAnalyticsReport(qrInstance) {
|
|
2374
|
+
const metadata = qrInstance.getMetadata();
|
|
2375
|
+
const settings = qrInstance.getSettings();
|
|
2376
|
+
|
|
2377
|
+
return {
|
|
2378
|
+
qrInfo: {
|
|
2379
|
+
id: qrInstance.getId(),
|
|
2380
|
+
name: qrInstance.getName(),
|
|
2381
|
+
description: qrInstance.getDescription()
|
|
2382
|
+
},
|
|
2383
|
+
configuration: settings,
|
|
2384
|
+
metadata: metadata,
|
|
2385
|
+
analyticsReadiness: this.validateAnalyticsSetup(metadata),
|
|
2386
|
+
reportGeneratedAt: new Date().toISOString()
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
static validateAnalyticsSetup(metadata) {
|
|
2391
|
+
const analytics = metadata?.analytics;
|
|
2392
|
+
return {
|
|
2393
|
+
hasTrackingId: !!analytics?.trackingId,
|
|
2394
|
+
hasGoals: !!(analytics?.goals && analytics.goals.length > 0),
|
|
2395
|
+
gdprCompliant: metadata?.privacy?.gdprCompliant === true,
|
|
2396
|
+
autoTrackEnabled: analytics?.autoTrack === true
|
|
2397
|
+
};
|
|
2398
|
+
}
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
// Usage
|
|
2402
|
+
const productQR = QRCodeJs.useTemplate('product')
|
|
2403
|
+
.useId('product-smartphone-x1')
|
|
2404
|
+
.useName('Smartphone X1 Product Page')
|
|
2405
|
+
.useMetadata({
|
|
2406
|
+
productId: 'smartphone-x1',
|
|
2407
|
+
category: 'mobile',
|
|
2408
|
+
price: 699.99
|
|
2409
|
+
})
|
|
2410
|
+
.options({
|
|
2411
|
+
data: 'https://store.company.com/smartphone-x1'
|
|
2412
|
+
});
|
|
2413
|
+
|
|
2414
|
+
const enhancedQR = AnalyticsQRWrapper.enhanceWithAnalytics(productQR, {
|
|
2415
|
+
trackingId: 'GA-123456789',
|
|
2416
|
+
platform: 'google-analytics',
|
|
2417
|
+
goals: ['purchase', 'add-to-cart', 'view-specifications'],
|
|
2418
|
+
customDimensions: {
|
|
2419
|
+
productCategory: 'mobile',
|
|
2420
|
+
priceRange: '600-800',
|
|
2421
|
+
season: 'q1-2024'
|
|
2422
|
+
},
|
|
2423
|
+
autoTrack: true,
|
|
2424
|
+
enableHeatmap: true,
|
|
2425
|
+
retentionPeriod: '2-years',
|
|
2426
|
+
anonymized: true,
|
|
2427
|
+
consentRequired: false
|
|
2428
|
+
});
|
|
2429
|
+
|
|
2430
|
+
const analyticsReport = AnalyticsQRWrapper.createAnalyticsReport(enhancedQR);
|
|
2431
|
+
console.log('QR Analytics Report:', analyticsReport);
|
|
2432
|
+
```
|
|
2433
|
+
|
|
2434
|
+
### Metadata Best Practices
|
|
2435
|
+
|
|
2436
|
+
#### 1. Consistent Schema Design
|
|
2437
|
+
|
|
2438
|
+
```typescript
|
|
2439
|
+
// Define a standardized metadata schema
|
|
2440
|
+
const MetadataSchema = {
|
|
2441
|
+
// Core identification
|
|
2442
|
+
id: 'string (required)',
|
|
2443
|
+
name: 'string (required)',
|
|
2444
|
+
description: 'string (required)',
|
|
2445
|
+
|
|
2446
|
+
// Lifecycle tracking
|
|
2447
|
+
createdAt: 'ISO 8601 timestamp',
|
|
2448
|
+
updatedAt: 'ISO 8601 timestamp',
|
|
2449
|
+
createdBy: 'string (user identifier)',
|
|
2450
|
+
lastModifiedBy: 'string (user identifier)',
|
|
2451
|
+
version: 'string (semantic versioning)',
|
|
2452
|
+
|
|
2453
|
+
// Business context
|
|
2454
|
+
businessUnit: 'string',
|
|
2455
|
+
department: 'string',
|
|
2456
|
+
project: 'string',
|
|
2457
|
+
campaign: 'string',
|
|
2458
|
+
|
|
2459
|
+
// Technical details
|
|
2460
|
+
environment: 'development | staging | production',
|
|
2461
|
+
region: 'string',
|
|
2462
|
+
locale: 'string (ISO 639-1)',
|
|
2463
|
+
|
|
2464
|
+
// Analytics and tracking
|
|
2465
|
+
analytics: {
|
|
2466
|
+
enabled: 'boolean',
|
|
2467
|
+
platform: 'string',
|
|
2468
|
+
goals: 'string[]',
|
|
2469
|
+
customDimensions: 'Record<string, any>'
|
|
2470
|
+
},
|
|
2471
|
+
|
|
2472
|
+
// Compliance and governance
|
|
2473
|
+
dataRetention: 'string (duration)',
|
|
2474
|
+
privacyLevel: 'public | internal | confidential | restricted',
|
|
2475
|
+
complianceFlags: 'string[]'
|
|
2476
|
+
};
|
|
2477
|
+
```
|
|
2478
|
+
|
|
2479
|
+
#### 2. Validation and Type Safety
|
|
2480
|
+
|
|
2481
|
+
```typescript
|
|
2482
|
+
class MetadataValidator {
|
|
2483
|
+
static validateRequiredFields(metadata) {
|
|
2484
|
+
const required = ['id', 'name', 'description'];
|
|
2485
|
+
const missing = required.filter(field => !metadata[field]);
|
|
2486
|
+
|
|
2487
|
+
if (missing.length > 0) {
|
|
2488
|
+
throw new Error(`Missing required metadata fields: ${missing.join(', ')}`);
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
static sanitizeMetadata(metadata) {
|
|
2493
|
+
return {
|
|
2494
|
+
...metadata,
|
|
2495
|
+
// Ensure timestamps are ISO strings
|
|
2496
|
+
createdAt: metadata.createdAt || new Date().toISOString(),
|
|
2497
|
+
updatedAt: new Date().toISOString(),
|
|
2498
|
+
// Sanitize strings
|
|
2499
|
+
name: metadata.name?.trim(),
|
|
2500
|
+
description: metadata.description?.trim(),
|
|
2501
|
+
// Ensure arrays are arrays
|
|
2502
|
+
tags: Array.isArray(metadata.tags) ? metadata.tags : [],
|
|
2503
|
+
// Validate email format for creator fields
|
|
2504
|
+
createdBy: this.validateEmail(metadata.createdBy)
|
|
2505
|
+
};
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
static validateEmail(email) {
|
|
2509
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
2510
|
+
return email && emailRegex.test(email) ? email : null;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
// Usage with validation
|
|
2515
|
+
function createValidatedQR(data, metadata) {
|
|
2516
|
+
try {
|
|
2517
|
+
MetadataValidator.validateRequiredFields(metadata);
|
|
2518
|
+
const sanitizedMetadata = MetadataValidator.sanitizeMetadata(metadata);
|
|
2519
|
+
|
|
2520
|
+
return QRCodeJs.useTemplate('validated')
|
|
2521
|
+
.useId(sanitizedMetadata.id)
|
|
2522
|
+
.useName(sanitizedMetadata.name)
|
|
2523
|
+
.useDescription(sanitizedMetadata.description)
|
|
2524
|
+
.useMetadata(sanitizedMetadata)
|
|
2525
|
+
.options({ data });
|
|
2526
|
+
} catch (error) {
|
|
2527
|
+
console.error('QR creation failed:', error.message);
|
|
2528
|
+
throw error;
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
```
|
|
2532
|
+
|
|
2533
|
+
#### 3. Metadata Versioning and Migration
|
|
2534
|
+
|
|
2535
|
+
```typescript
|
|
2536
|
+
class MetadataVersionManager {
|
|
2537
|
+
static CURRENT_VERSION = '2.1.0';
|
|
2538
|
+
|
|
2539
|
+
static migrateMetadata(metadata) {
|
|
2540
|
+
const version = metadata.schemaVersion || '1.0.0';
|
|
2541
|
+
let migrated = { ...metadata };
|
|
2542
|
+
|
|
2543
|
+
if (this.isVersionLess(version, '2.0.0')) {
|
|
2544
|
+
migrated = this.migrateTo2_0_0(migrated);
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
if (this.isVersionLess(version, '2.1.0')) {
|
|
2548
|
+
migrated = this.migrateTo2_1_0(migrated);
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
migrated.schemaVersion = this.CURRENT_VERSION;
|
|
2552
|
+
migrated.lastMigration = new Date().toISOString();
|
|
2553
|
+
|
|
2554
|
+
return migrated;
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
static migrateTo2_0_0(metadata) {
|
|
2558
|
+
return {
|
|
2559
|
+
...metadata,
|
|
2560
|
+
// Migrate old tracking field to new analytics structure
|
|
2561
|
+
analytics: {
|
|
2562
|
+
enabled: metadata.tracking?.enabled || false,
|
|
2563
|
+
platform: metadata.tracking?.platform || 'unknown',
|
|
2564
|
+
goals: metadata.tracking?.events || []
|
|
2565
|
+
},
|
|
2566
|
+
// Remove deprecated fields
|
|
2567
|
+
tracking: undefined
|
|
2568
|
+
};
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2571
|
+
static migrateTo2_1_0(metadata) {
|
|
2572
|
+
return {
|
|
2573
|
+
...metadata,
|
|
2574
|
+
// Add new compliance fields with defaults
|
|
2575
|
+
compliance: {
|
|
2576
|
+
dataRetention: metadata.compliance?.dataRetention || '1-year',
|
|
2577
|
+
privacyLevel: metadata.compliance?.privacyLevel || 'internal'
|
|
2578
|
+
}
|
|
2579
|
+
};
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
static isVersionLess(version1, version2) {
|
|
2583
|
+
const v1Parts = version1.split('.').map(Number);
|
|
2584
|
+
const v2Parts = version2.split('.').map(Number);
|
|
2585
|
+
|
|
2586
|
+
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
|
|
2587
|
+
const v1Part = v1Parts[i] || 0;
|
|
2588
|
+
const v2Part = v2Parts[i] || 0;
|
|
2589
|
+
|
|
2590
|
+
if (v1Part < v2Part) return true;
|
|
2591
|
+
if (v1Part > v2Part) return false;
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
return false;
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
```
|
|
2598
|
+
|
|
2599
|
+
### Integration Examples
|
|
2600
|
+
|
|
2601
|
+
#### Database Integration
|
|
2602
|
+
|
|
2603
|
+
```typescript
|
|
2604
|
+
class QRDatabaseManager {
|
|
2605
|
+
static async saveQRMetadata(qrInstance) {
|
|
2606
|
+
const metadata = {
|
|
2607
|
+
id: qrInstance.getId(),
|
|
2608
|
+
name: qrInstance.getName(),
|
|
2609
|
+
description: qrInstance.getDescription(),
|
|
2610
|
+
customMetadata: qrInstance.getMetadata(),
|
|
2611
|
+
settings: qrInstance.getSettings(),
|
|
2612
|
+
createdAt: new Date(),
|
|
2613
|
+
updatedAt: new Date()
|
|
2614
|
+
};
|
|
2615
|
+
|
|
2616
|
+
// Save to database (pseudo-code)
|
|
2617
|
+
return await database.qrCodes.create(metadata);
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
static async loadQRMetadata(qrId) {
|
|
2621
|
+
const record = await database.qrCodes.findById(qrId);
|
|
2622
|
+
if (!record) return null;
|
|
2623
|
+
|
|
2624
|
+
// Recreate QR instance with stored metadata
|
|
2625
|
+
const qrInstance = new QRCodeJs(record.settings.options || { data: record.data });
|
|
2626
|
+
|
|
2627
|
+
qrInstance
|
|
2628
|
+
.setId(record.id)
|
|
2629
|
+
.setName(record.name)
|
|
2630
|
+
.setDescription(record.description)
|
|
2631
|
+
.setMetadata(record.customMetadata);
|
|
2632
|
+
|
|
2633
|
+
return qrInstance;
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
```
|
|
2140
2637
|
|
|
2141
|
-
|
|
2142
|
-
- [QRCode.js Documentation](./documentation.md#start)
|
|
2143
|
-
- [Quick References Guide](./quick-references-guide.md#start)
|
|
2144
|
-
- [API Reference Guide](./api-reference-guide.md#start)
|
|
2145
|
-
- [TypeScript Types and Definitions](./typescript-types-definitions.md#start)
|
|
2146
|
-
- [License Management](./license-management.md#start)
|
|
2147
|
-
- [Basic Examples](./examples.md#start)
|
|
2148
|
-
- [Advanced Examples](./advanced-examples.md#start)
|
|
2638
|
+
This comprehensive metadata management system enables enterprise-level QR code organization, tracking, and governance while maintaining flexibility for various use cases and integration requirements.
|
package/docs/examples.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
This document provides basic examples to help you get started with QRCode.js and understand its core features. For more complex scenarios, refer to the [Advanced Examples](./advanced-examples.md#start).
|
|
5
|
-
|
|
1
|
+
---
|
|
2
|
+
title: 'Basic Examples'
|
|
3
|
+
description: 'Basic examples to get started with QRCode.js'
|
|
6
4
|
---
|
|
7
5
|
|
|
6
|
+
This document provides basic examples to help you get started with QRCode.js and understand its core features. For more complex scenarios, refer to the [Advanced Examples](./advanced-examples).
|
|
7
|
+
|
|
8
8
|
## Basic Usage
|
|
9
9
|
|
|
10
10
|
Here's a minimal example to generate a QR code and append it to the document:
|
|
@@ -24,14 +24,10 @@ const qrCode = new QRCodeJs(options);
|
|
|
24
24
|
|
|
25
25
|
// Append the generated SVG to your document (in browser)
|
|
26
26
|
const container = document.getElementById('qr-container');
|
|
27
|
-
if (container
|
|
28
|
-
|
|
29
|
-
} else if (!container) {
|
|
30
|
-
console.error("Container element not found.");
|
|
27
|
+
if (container) {
|
|
28
|
+
qrCode.append(container);
|
|
31
29
|
} else {
|
|
32
|
-
console.error("
|
|
33
|
-
// Handle SVG generation for Node.js if needed (e.g., serialize to string)
|
|
34
|
-
// qrCode.serialize().then(svgString => { /* save string */ });
|
|
30
|
+
console.error("Container element not found.");
|
|
35
31
|
}
|
|
36
32
|
```
|
|
37
33
|
|
|
@@ -799,15 +795,125 @@ qrBuilderWithTextOverride.append(document.getElementById('builder-text-override-
|
|
|
799
795
|
// Reset global text when done
|
|
800
796
|
QRCodeJs.setText(null);
|
|
801
797
|
```
|
|
802
|
-
|
|
803
|
-
*For custom border text and advanced features like inner/outer borders, a [Premium License](./license-management.md#start) is required.*
|
|
798
|
+
*For custom border text and advanced features like inner/outer borders, a [Premium License](./license-management) is required.*
|
|
804
799
|
|
|
805
800
|
---
|
|
806
801
|
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
802
|
+
## Metadata Management
|
|
803
|
+
|
|
804
|
+
QRCode.js supports metadata for better organization and tracking:
|
|
805
|
+
|
|
806
|
+
### Metadata Management with Builder Pattern
|
|
807
|
+
|
|
808
|
+
The builder pattern supports metadata methods for assigning identifiers, names, descriptions, and custom metadata to QR code instances.
|
|
809
|
+
|
|
810
|
+
**Example 1: Basic Metadata with Builder Pattern**
|
|
811
|
+
```javascript
|
|
812
|
+
// Create QR code with metadata using builder pattern
|
|
813
|
+
const qrWithMetadata = QRCodeJs.useTemplate('modern')
|
|
814
|
+
.useId('customer-portal-qr-001')
|
|
815
|
+
.useName('Customer Portal Access')
|
|
816
|
+
.useDescription('QR code for customer portal login system')
|
|
817
|
+
.useMetadata({
|
|
818
|
+
campaign: 'winter2024',
|
|
819
|
+
department: 'marketing',
|
|
820
|
+
version: '1.2.0'
|
|
821
|
+
})
|
|
822
|
+
.options({
|
|
823
|
+
data: 'https://customer.company.com/portal'
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
qrWithMetadata.append(document.getElementById('metadata-container'));
|
|
827
|
+
|
|
828
|
+
// Access metadata after creation
|
|
829
|
+
console.log('QR ID:', qrWithMetadata.getId()); // 'customer-portal-qr-001'
|
|
830
|
+
console.log('QR Name:', qrWithMetadata.getName()); // 'Customer Portal Access'
|
|
831
|
+
console.log('QR Description:', qrWithMetadata.getDescription()); // 'QR code for customer portal login system'
|
|
832
|
+
console.log('QR Metadata:', qrWithMetadata.getMetadata());
|
|
833
|
+
// { campaign: 'winter2024', department: 'marketing', version: '1.2.0' }
|
|
834
|
+
```
|
|
835
|
+
|
|
836
|
+
**Example 2: Static Metadata Methods**
|
|
837
|
+
```javascript
|
|
838
|
+
// Set metadata using static methods
|
|
839
|
+
QRCodeJs
|
|
840
|
+
.setId('product-qr-123')
|
|
841
|
+
.setName('Product Landing Page')
|
|
842
|
+
.setDescription('QR code linking to product details page')
|
|
843
|
+
.setMetadata({
|
|
844
|
+
productId: '123',
|
|
845
|
+
category: 'electronics',
|
|
846
|
+
createdBy: 'marketing-team',
|
|
847
|
+
expires: '2024-12-31'
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
const qrInstance = new QRCodeJs({
|
|
851
|
+
data: 'https://example.com/product-123'
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
qrInstance.append(document.getElementById('instance-metadata-container'));
|
|
855
|
+
|
|
856
|
+
// Get current settings and options
|
|
857
|
+
const currentSettings = qrInstance.getSettings();
|
|
858
|
+
console.log('Current Settings:', currentSettings);
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
**Example 3: Chaining Metadata with Templates and Styles**
|
|
862
|
+
```javascript
|
|
863
|
+
// Complex builder chain with metadata
|
|
864
|
+
const qrComplexChain = QRCodeJs.useTemplate('rounded')
|
|
865
|
+
.useStyle({ dotsOptions: { color: '#2E86AB' } })
|
|
866
|
+
.useId('campaign-qr-2024')
|
|
867
|
+
.useName('Summer Campaign QR')
|
|
868
|
+
.useDescription('Multi-channel marketing campaign QR code')
|
|
869
|
+
.useMetadata({
|
|
870
|
+
campaignId: 'summer-2024',
|
|
871
|
+
channels: ['email', 'social', 'print'],
|
|
872
|
+
budget: 5000,
|
|
873
|
+
targetAudience: 'millennials'
|
|
874
|
+
})
|
|
875
|
+
.useImage('https://company.com/assets/summer-logo.png')
|
|
876
|
+
.options({
|
|
877
|
+
data: 'https://campaign.company.com/summer-2024',
|
|
878
|
+
qrOptions: { errorCorrectionLevel: 'Q' }
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
qrComplexChain.append(document.getElementById('complex-chain-container'));
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
**Example 4: Conditional Metadata Setting**
|
|
885
|
+
```javascript
|
|
886
|
+
// Function to create QR codes with conditional metadata
|
|
887
|
+
function createTrackingQR(data, trackingInfo) {
|
|
888
|
+
const builder = QRCodeJs.useTemplate('tracking')
|
|
889
|
+
.useId(trackingInfo.id)
|
|
890
|
+
.useName(trackingInfo.name);
|
|
891
|
+
|
|
892
|
+
// Conditionally add description
|
|
893
|
+
if (trackingInfo.description) {
|
|
894
|
+
builder.useDescription(trackingInfo.description);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// Conditionally add metadata
|
|
898
|
+
if (trackingInfo.metadata) {
|
|
899
|
+
builder.useMetadata(trackingInfo.metadata);
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
return builder.options({ data });
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// Usage
|
|
906
|
+
const trackingQR = createTrackingQR('https://track.company.com/package/ABC123', {
|
|
907
|
+
id: 'package-tracker-ABC123',
|
|
908
|
+
name: 'Package Tracking QR',
|
|
909
|
+
description: 'Scan to track package ABC123',
|
|
910
|
+
metadata: {
|
|
911
|
+
packageId: 'ABC123',
|
|
912
|
+
carrier: 'FedEx',
|
|
913
|
+
priority: 'high',
|
|
914
|
+
estimatedDelivery: '2024-03-15'
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
trackingQR.append(document.getElementById('tracking-qr-container'));
|
|
919
|
+
```
|