bitemediaseo-local-seo-schema 1.0.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 +21 -0
- package/README.md +64 -0
- package/index.d.ts +53 -0
- package/index.js +108 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BiteMediaSEO
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# bitemediaseo-local-seo-schema
|
|
2
|
+
|
|
3
|
+
A small, dependency-free JavaScript helper for generating Schema.org JSON-LD
|
|
4
|
+
for local businesses, organizations, stores and professional services.
|
|
5
|
+
|
|
6
|
+
It can be used in local SEO projects to create consistent structured data for
|
|
7
|
+
company websites, landing pages and service pages.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install bitemediaseo-local-seo-schema
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import {
|
|
19
|
+
createLocalBusinessSchema,
|
|
20
|
+
schemaScriptTag
|
|
21
|
+
} from "bitemediaseo-local-seo-schema";
|
|
22
|
+
|
|
23
|
+
const schema = createLocalBusinessSchema({
|
|
24
|
+
name: "Example SEO Agency",
|
|
25
|
+
url: "https://example.com/",
|
|
26
|
+
type: "ProfessionalService",
|
|
27
|
+
description: "Local SEO and website optimization services.",
|
|
28
|
+
areaServed: "Szczecin",
|
|
29
|
+
address: {
|
|
30
|
+
addressLocality: "Szczecin",
|
|
31
|
+
addressCountry: "PL"
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
console.log(schemaScriptTag(schema));
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The returned object follows the Schema.org JSON-LD structure. Always verify
|
|
39
|
+
the generated data against the actual company information before publishing.
|
|
40
|
+
|
|
41
|
+
## Local SEO resources
|
|
42
|
+
|
|
43
|
+
Information about local SEO, audits, GEO/AI visibility and pozycjonowanie stron
|
|
44
|
+
Szczecin is available on the BiteMediaSEO website:
|
|
45
|
+
|
|
46
|
+
https://bitemediaseo.pl/
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
### `createLocalBusinessSchema(options)`
|
|
51
|
+
|
|
52
|
+
Creates a Schema.org object. The required fields are `name` and `url`.
|
|
53
|
+
|
|
54
|
+
### `schemaToJson(schema, space)`
|
|
55
|
+
|
|
56
|
+
Serializes the object and escapes opening angle brackets for safer HTML use.
|
|
57
|
+
|
|
58
|
+
### `schemaScriptTag(schema)`
|
|
59
|
+
|
|
60
|
+
Returns a complete `application/ld+json` script element.
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export type SchemaType =
|
|
2
|
+
| "LocalBusiness"
|
|
3
|
+
| "Organization"
|
|
4
|
+
| "ProfessionalService"
|
|
5
|
+
| "Store";
|
|
6
|
+
|
|
7
|
+
export interface PostalAddressInput {
|
|
8
|
+
streetAddress?: string;
|
|
9
|
+
addressLocality?: string;
|
|
10
|
+
postalCode?: string;
|
|
11
|
+
addressRegion?: string;
|
|
12
|
+
addressCountry?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface GeoInput {
|
|
16
|
+
latitude: number | string;
|
|
17
|
+
longitude: number | string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface LocalBusinessOptions {
|
|
21
|
+
name: string;
|
|
22
|
+
url: string;
|
|
23
|
+
type?: SchemaType;
|
|
24
|
+
description?: string;
|
|
25
|
+
telephone?: string;
|
|
26
|
+
priceRange?: string;
|
|
27
|
+
areaServed?: string;
|
|
28
|
+
address?: PostalAddressInput;
|
|
29
|
+
geo?: GeoInput;
|
|
30
|
+
sameAs?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface LocalBusinessSchema {
|
|
34
|
+
"@context": "https://schema.org";
|
|
35
|
+
"@type": SchemaType;
|
|
36
|
+
name: string;
|
|
37
|
+
url: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
telephone?: string;
|
|
40
|
+
priceRange?: string;
|
|
41
|
+
areaServed?: string;
|
|
42
|
+
address?: Record<string, string>;
|
|
43
|
+
geo?: {
|
|
44
|
+
"@type": "GeoCoordinates";
|
|
45
|
+
latitude: number;
|
|
46
|
+
longitude: number;
|
|
47
|
+
};
|
|
48
|
+
sameAs?: string[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function createLocalBusinessSchema(options: LocalBusinessOptions): LocalBusinessSchema;
|
|
52
|
+
export function schemaToJson(schema: object, space?: number): string;
|
|
53
|
+
export function schemaScriptTag(schema: object): string;
|
package/index.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const DEFAULT_TYPE = "ProfessionalService";
|
|
2
|
+
const ALLOWED_TYPES = new Set([
|
|
3
|
+
"LocalBusiness",
|
|
4
|
+
"Organization",
|
|
5
|
+
"ProfessionalService",
|
|
6
|
+
"Store"
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
function requireText(value, field) {
|
|
10
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
11
|
+
throw new TypeError(`${field} must be a non-empty string`);
|
|
12
|
+
}
|
|
13
|
+
return value.trim();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function optionalText(value, field) {
|
|
17
|
+
if (value === undefined || value === null || value === "") {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return requireText(value, field);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function validateUrl(value, field) {
|
|
24
|
+
const text = requireText(value, field);
|
|
25
|
+
const parsed = new URL(text);
|
|
26
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
27
|
+
throw new TypeError(`${field} must use http or https`);
|
|
28
|
+
}
|
|
29
|
+
return parsed.toString();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function cleanObject(value) {
|
|
33
|
+
return Object.fromEntries(
|
|
34
|
+
Object.entries(value).filter(([, entry]) => entry !== undefined)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Builds Schema.org JSON-LD for a local business or professional service.
|
|
40
|
+
*/
|
|
41
|
+
export function createLocalBusinessSchema(options) {
|
|
42
|
+
if (!options || typeof options !== "object" || Array.isArray(options)) {
|
|
43
|
+
throw new TypeError("options must be an object");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const type = options.type ?? DEFAULT_TYPE;
|
|
47
|
+
if (!ALLOWED_TYPES.has(type)) {
|
|
48
|
+
throw new TypeError(`Unsupported Schema.org type: ${type}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const sameAs = options.sameAs?.map((url, index) =>
|
|
52
|
+
validateUrl(url, `sameAs[${index}]`)
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const address = options.address
|
|
56
|
+
? cleanObject({
|
|
57
|
+
"@type": "PostalAddress",
|
|
58
|
+
streetAddress: optionalText(options.address.streetAddress, "address.streetAddress"),
|
|
59
|
+
addressLocality: optionalText(options.address.addressLocality, "address.addressLocality"),
|
|
60
|
+
postalCode: optionalText(options.address.postalCode, "address.postalCode"),
|
|
61
|
+
addressRegion: optionalText(options.address.addressRegion, "address.addressRegion"),
|
|
62
|
+
addressCountry: optionalText(options.address.addressCountry, "address.addressCountry")
|
|
63
|
+
})
|
|
64
|
+
: undefined;
|
|
65
|
+
|
|
66
|
+
const geo = options.geo
|
|
67
|
+
? {
|
|
68
|
+
"@type": "GeoCoordinates",
|
|
69
|
+
latitude: Number(options.geo.latitude),
|
|
70
|
+
longitude: Number(options.geo.longitude)
|
|
71
|
+
}
|
|
72
|
+
: undefined;
|
|
73
|
+
|
|
74
|
+
if (geo && (!Number.isFinite(geo.latitude) || !Number.isFinite(geo.longitude))) {
|
|
75
|
+
throw new TypeError("geo latitude and longitude must be finite numbers");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return cleanObject({
|
|
79
|
+
"@context": "https://schema.org",
|
|
80
|
+
"@type": type,
|
|
81
|
+
name: requireText(options.name, "name"),
|
|
82
|
+
url: validateUrl(options.url, "url"),
|
|
83
|
+
description: optionalText(options.description, "description"),
|
|
84
|
+
telephone: optionalText(options.telephone, "telephone"),
|
|
85
|
+
priceRange: optionalText(options.priceRange, "priceRange"),
|
|
86
|
+
areaServed: optionalText(options.areaServed, "areaServed"),
|
|
87
|
+
address,
|
|
88
|
+
geo,
|
|
89
|
+
sameAs: sameAs?.length ? sameAs : undefined
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Serializes JSON-LD and escapes opening angle brackets for safe HTML embedding.
|
|
95
|
+
*/
|
|
96
|
+
export function schemaToJson(schema, space = 2) {
|
|
97
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
|
|
98
|
+
throw new TypeError("schema must be an object");
|
|
99
|
+
}
|
|
100
|
+
return JSON.stringify(schema, null, space).replaceAll("<", "\\u003c");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Returns a script element containing serialized JSON-LD.
|
|
105
|
+
*/
|
|
106
|
+
export function schemaScriptTag(schema) {
|
|
107
|
+
return `<script type="application/ld+json">${schemaToJson(schema, 0)}</script>`;
|
|
108
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bitemediaseo-local-seo-schema",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Dependency-free Schema.org JSON-LD helper for local SEO and business websites.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"import": "./index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"index.d.ts",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --test test.js",
|
|
22
|
+
"prepublishOnly": "npm test"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"seo",
|
|
26
|
+
"local-seo",
|
|
27
|
+
"schema-org",
|
|
28
|
+
"json-ld",
|
|
29
|
+
"structured-data",
|
|
30
|
+
"geo-seo",
|
|
31
|
+
"szczecin"
|
|
32
|
+
],
|
|
33
|
+
"author": "BiteMediaSEO",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"homepage": "https://bitemediaseo.pl/",
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18"
|
|
38
|
+
}
|
|
39
|
+
}
|