@samatawy/rules-world 0.1.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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,76 @@
1
+ # @samatawy/rules-world
2
+
3
+ World and geography-oriented function providers for [@samatawy/rules](https://www.npmjs.com/package/@samatawy/rules).
4
+
5
+ This package is designed as an optional plugin. It keeps geography and country-data helpers outside the core rules engine package while still integrating through the same `FunctionFactory.registerProvider(...)` API.
6
+
7
+ It currently exposes `42` country-related functions (2 of which are aliases). Data is available for `250` countries.
8
+
9
+ To report incorrect data or behaviour, or to request additional features, use [the Github issue tracker](https://github.com/samatawy/rules-world/issues).
10
+
11
+ This package can be used by:
12
+
13
+ - Node.js and browser runtimes
14
+ - ESM and CommonJS consumers
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @samatawy/rules @samatawy/rules-world
20
+ ```
21
+
22
+ `@samatawy/rules` is a peer dependency, so your application provides the core engine version.
23
+
24
+ ## Usage
25
+
26
+ ```ts
27
+ import { FunctionFactory, Workspace } from '@samatawy/rules';
28
+ import { CommonGeographyFunctionsProvider } from '@samatawy/rules-world';
29
+
30
+ FunctionFactory.registerProvider(CommonGeographyFunctionsProvider);
31
+
32
+ const workspace = new Workspace();
33
+ workspace.addRule('if country_name("CA") = "Canada" then result.country = true');
34
+ workspace.addRule('if country_has_tld("CA", ".ca") then result.local = true');
35
+ ```
36
+
37
+ You can also register the provider through the package helper:
38
+
39
+ ```ts
40
+ import { registerWorldProviders } from '@samatawy/rules-world';
41
+
42
+ registerWorldProviders();
43
+ ```
44
+
45
+ The same package entry works in both Node.js and browser builds, with ESM and CommonJS output generated from the same source.
46
+
47
+ ## Included Provider
48
+
49
+ - `CommonGeographyFunctionsProvider`
50
+
51
+ ## Included Data
52
+
53
+ - `Countries`
54
+ - `CountryCodes`
55
+ - `CurrencyCodes`
56
+ - `Languages`
57
+ - `Continents`
58
+ - `Timezones`
59
+
60
+ ## Example Geography Functions
61
+
62
+ - `country_codes()`
63
+ - `country_code(value)`
64
+ - `country_name(code)`
65
+ - `official_country_name(code)`
66
+ - `country_calling_codes(code)`
67
+ - `country_top_level_domains(code)`
68
+ - `country_languages(code)`
69
+ - `country_timezones(code)`
70
+ - `countries_in_continent(continent)`
71
+ - `countries_in_subregion(subregion)`
72
+ - `countries_using_currency(currency)`
73
+ - `country_has_tld(code, tld)`
74
+ - `country_has_calling_code(code, callingCode)`
75
+ - `country_speaks_language(code, language)`
76
+ - `country_in_timezone(code, timezone)`