├── .circleci
└── config.yml
├── .gitignore
├── .midje.clj
├── LICENSE
├── Makefile
├── NEWS.md
├── README.md
├── TODO
├── aliases
├── build
│ └── phone_number
│ │ └── build
│ │ └── main.clj
├── codox
│ └── phone_number
│ │ └── codox
│ │ └── main.clj
├── nrepl
│ └── nrepl.clj
└── rebel
│ └── phone_number
│ └── rebel
│ └── main.clj
├── bin
├── build
├── docs
├── lint
├── nrepl
├── repl
├── test
└── test-notifier
├── circle.yml
├── deps.edn
├── dev
└── src
│ ├── infra.clj
│ ├── phone_number
│ └── generator.clj
│ └── user.clj
├── doc
├── 10_introduction.md
├── 30_specs.md
└── 40_development.md
├── docs
├── .gitignore
├── 10_introduction.html
├── 30_specs.html
├── 40_development.html
├── LICENSE
├── css
│ ├── default.css
│ ├── highlight.css
│ └── randomseed.css
├── index.html
├── js
│ ├── highlight.min.js
│ ├── jquery.min.js
│ └── page_effects.js
├── phone-number.calling-code.html
├── phone-number.core.html
├── phone-number.cost.html
├── phone-number.country-code.html
├── phone-number.db.html
├── phone-number.format.html
├── phone-number.html
├── phone-number.leniency.html
├── phone-number.locale.html
├── phone-number.match.html
├── phone-number.net-code.html
├── phone-number.region.html
├── phone-number.spec.html
├── phone-number.type.html
├── phone-number.tz-format.html
└── phone-number.util.html
├── phone-number.jar.asc
├── pom.xml
├── pom.xml.asc
├── resources
└── codox
│ └── theme
│ └── randomseed
│ ├── css
│ └── randomseed.css
│ └── theme.edn
├── src
├── phone_number.clj
└── phone_number
│ ├── calling_code.clj
│ ├── core.clj
│ ├── cost.clj
│ ├── country_code.clj
│ ├── db.clj
│ ├── dialing_region.clj
│ ├── format.clj
│ ├── leniency.clj
│ ├── locale.clj
│ ├── match.clj
│ ├── net_code.clj
│ ├── region.clj
│ ├── sample.clj
│ ├── short.clj
│ ├── spec.clj
│ ├── type.clj
│ ├── tz_format.clj
│ └── util.clj
├── test
└── phone_number
│ └── core_test.clj
└── tests.edn
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | # Clojure CircleCI 2.0 configuration file
2 | #
3 | # Check https://circleci.com/docs/2.0/language-clojure/ for more details
4 | #
5 | version: 2
6 | jobs:
7 | build:
8 | docker:
9 | # specify the version you desire here
10 | - image: cimg/clojure:1.11.1
11 |
12 | # Specify service dependencies here if necessary
13 | # CircleCI maintains a library of pre-built images
14 | # documented at https://circleci.com/docs/2.0/circleci-images/
15 | # - image: circleci/postgres:9.4
16 |
17 | working_directory: ~/repo
18 |
19 | environment:
20 | # Customize the JVM maximum heap limit
21 | JVM_OPTS: -Xmx3200m
22 |
23 | steps:
24 | - checkout
25 |
26 | # Download and cache dependencies
27 | - restore_cache:
28 | keys:
29 | - v1-dependencies-{{ checksum "deps.edn" }}
30 | # fallback to using the latest cache if no exact match is found
31 | - v1-dependencies-
32 |
33 | - run: sudo apt-get install -y make
34 | - run: make test
35 |
36 | - save_cache:
37 | paths:
38 | - ~/.m2
39 | key: v1-dependencies-{{ checksum "deps.edn" }}
40 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 | /classes
3 | /checkouts
4 | *.jar
5 | *.class
6 | /.lein-*
7 | /.rebel_*
8 | /.nrepl-port
9 | .DS_Store
10 | .hgignore
11 | .hg/
12 | gh-pages
13 | .cpcache/
14 | /DELETE_ME
15 | /.dir-locals.el
16 | /.shadow-cljs/
17 | /todo.org
18 | /project.clj.bak
19 | /bin/test-cljs
20 | node_modules/
21 | /cljs-test-runner-out
22 | pom.xml.versionsBackup
23 |
--------------------------------------------------------------------------------
/.midje.clj:
--------------------------------------------------------------------------------
1 | (change-defaults :emitter 'midje.emission.plugins.default
2 | :print-level :print-facts)
3 | (change-defaults
4 | :visible-future false)
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
167 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | APPNAME = "phone-number"
2 | VERSION = "8.13.6-3"
3 |
4 | .PHONY: watch default docs deploy test test-clj sig jar pom clean tag
5 |
6 | default: docs
7 |
8 | lint:
9 | bin/lint
10 |
11 | docs:
12 | bin/docs "$(VERSION)"
13 |
14 | push-docs:
15 | git subtree push --prefix=docs docs master
16 |
17 | test-clj:
18 | bin/test --no-profiling
19 |
20 | test:
21 | @$(MAKE) test-clj
22 |
23 | pom: pom.xml
24 | clojure -Spom && awk 'NF > 0' pom.xml > pom.new.xml && mv -f pom.new.xml pom.xml
25 | mvn versions:set versions:commit -DnewVersion="$(VERSION)" versions:set-scm-tag -DnewTag="$(VERSION)"
26 | rm -f pom.xml.asc
27 |
28 | $(APPNAME).jar: pom.xml
29 | bin/build
30 |
31 | jar: $(APPNAME).jar
32 |
33 | sig: pom.xml
34 | rm -f pom.xml.asc
35 | gpg2 --armor --detach-sig pom.xml
36 |
37 | tag: pom.xml
38 | git tag -s "$(VERSION)" -m "Release $(VERSION)"
39 |
40 | deploy:
41 | @$(MAKE) clean
42 | @$(MAKE) pom
43 | @$(MAKE) jar
44 | mvn gpg:sign-and-deploy-file -Dfile=$(APPNAME).jar -DrepositoryId=clojars -Durl=https://clojars.org/repo -DpomFile=pom.xml
45 |
46 | clean:
47 | rm -f $(APPNAME).jar pom.xml.asc
48 |
49 | .PHONY: list
50 | list:
51 | @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
52 |
--------------------------------------------------------------------------------
/NEWS.md:
--------------------------------------------------------------------------------
1 | # History of phone-number releases
2 |
3 | ## 8.13.6-3 (2023-02-26)
4 |
5 | - Improvements:
6 |
7 | * Speed optimizations (type hints, referential equality).
8 |
9 | ## 8.13.6-2 (2023-02-24)
10 |
11 | - Improvements:
12 |
13 | * Memoization support for parsing phone numbers as strings.
14 | * Improved assertion function `phone-number.core/valid-input?`.
15 |
16 | ## 8.13.6-1 (2023-02-11)
17 |
18 | - Improvements:
19 |
20 | * Added `phone-number.core/number-optraw`.
21 | * `phone-number.core/noraw` now creates a copy and strips raw input when
22 | a `PhoneNumber` is given.
23 | * Inline documentation strings edited.
24 |
25 | ## 8.13.6-0 (2023-02-11)
26 |
27 | - Improvements:
28 |
29 | * Libphonenumber version bump.
30 | * Added printing method.
31 |
32 | ## 8.13.2-0 (2022-12-13)
33 |
34 | - Improvements:
35 |
36 | * Libphonenumber version bump.
37 |
38 | ## 8.12.52-0 (2022-07-29)
39 |
40 | - Improvements:
41 |
42 | * Improved building and documentation generating code.
43 | * Separated nREPL from REPL (development mode).
44 | * Syntactical cleanups.
45 | * Libphonenumber dependency updated to match version 8.12.52.
46 | * Geocoder dependency updated to match version 2.188.
47 | * Prefixmapper dependency updated to match version 2.188.
48 | * Carrier dependency updated to match version 1.178.
49 | * Development dependencies updated to match their newest versions.
50 |
51 | ## 8.12.28-0, 8.12.28-1 (2021-07-21)
52 |
53 | - Improvements:
54 |
55 | * Libphonenumber version bump.
56 |
57 | - Bug fixes:
58 |
59 | * Removed development dependencies (orchestra) from `spec.clj`.
60 | * Moved development file `generator.clj` to `dev/src`.
61 |
62 | ## 8.12.21-0 (2021-04-19)
63 |
64 | - Improvements:
65 |
66 | * Libphonenumber version bump.
67 | * Removed reflection warnings.
68 |
69 | ## 8.12.16-1 (2021-01-31)
70 |
71 | - Improvements:
72 |
73 | * Added some missing validators and databases for argument processing
74 | * Samplers corrected to use -arg versions of databases
75 | * Added support for pseudo-region `:phone-number.region/world` for non-geographic numbers
76 | * Created `phone-number.db` with cross-databases:
77 | * Regions to types
78 | * Types to regions
79 | * Regions to calling codes
80 | * Calling codes to regions
81 | * Calling codes to types
82 | * Types to calling codes
83 | * New functions in core:
84 | * `phone-number.core/calling-code-prefix`
85 | * `phone-number.core/regions-for-calling-code`
86 | * `phone-number.core/region-for-calling-code`
87 | * `phone-number.core/calling-codes-for-region`
88 | * Improved main phone numbers generator
89 | (random regions and calling codes are picked up from valid sets for randomly
90 | generated types)
91 | * Specs divided into 3 groups:
92 | * Input data specs
93 | * Generic specs (outputs, common data structures)
94 | * Internal specs (arguments, properties)
95 | * Removed legacy support for accepting region codes as enum type values
96 | * Shuffling functions from `phone-number.util` are now short-circuiting on `nil` values
97 | * Assertion errors reporting improved
98 | * Development process now uses Eastwood linter
99 |
100 | - Bug fixes:
101 |
102 | * Function for building phone numbers from maps now properly handles invalid data
103 | * Removed unneeded `:phone-number.region/unknown`
104 | * Removed global network calling codes from `phone-number.country-code/all` and
105 | related
106 | * Documentation corrected in some places
107 |
108 | ## 8.12.16-0 (2021-01-23)
109 |
110 | - Improvements:
111 |
112 | * Libphonenumber dependency updated to match version 8.12.16
113 | * Geocoder dependency updated to match version 2.152
114 | * Carrier dependency updated to match version 1.142
115 | * Development dependencies updated to match newest versions
116 |
117 | - Bug fixes:
118 |
119 | * Some local tests (run from REPL) are now using proper default region
120 |
121 | ## 8.12.4-3 (2021-01-23)
122 |
123 | - Improvements:
124 |
125 | * More relaxed arities (usually allowing to skip region code)
126 | * Locale support moved to a separate file (with parsing and validation)
127 | * Added leniency support (`phone-number/leniency`, `phone-number.core/leniencies`)
128 | * Added leniency and max-tries support to `phone-number.core/find-numbers`
129 | * Added tests for `phone-number.core/find-numbers`
130 | * Specs updated to reflect changes
131 | * Documentation updated
132 |
133 | - Bug fixes:
134 |
135 | * Fixed typo in spec for `phone-number.core/time-zones` return value
136 | * Fixed setting the default value of dialing region in `phone-number.core/info`
137 | when main arity is called by other arities.
138 |
139 | ## 8.12.4-2 (2020-06-27)
140 |
141 | - Improvements:
142 |
143 | * Type-hinted `locale-specification` arguments as keywords
144 | * Improved fetching of the required data from phone numbers expressed as maps:
145 | * `phone-number.core/raw-input`
146 | * `phone-number.core/valid-input?`
147 | * Changed from accepting phone numbers only as strings to polymorphic:
148 | * `phone-number.core/short-emergency?`
149 | * `phone-number.core/short-to-emergency?`
150 | * Added namespaces and namespace aliases for shorter keywords notation:
151 | * `phone-number`
152 | * `phone-number.short`
153 | * `phone-number.sample`
154 | * `phone-number.dialing-region`
155 | * `phone-number.arg` (specs only)
156 | * `phone-number.args` (specs only)
157 | * `phone-number.prop` (specs only)
158 |
159 | - Bug fixes:
160 |
161 | * Fixed spec for `phone-number.core/raw-input`
162 |
163 | ## 8.12.4-1 (2020-06-24)
164 |
165 | - BREAKING CHANGES:
166 |
167 | * Calling region (code) is now renamed to dialing region (code)
168 | * `:phone-number.calling-region` is now `:phone-number.dialing-region`
169 | * `:phone-number.short/dialing-region` property is replaced by
170 | `:phone-number/dialing-region`
171 | * `phone-number.core/valid-for-region?` is now deprecated in favor of `phone-number.core/valid?`
172 |
173 | - Improvements:
174 |
175 | * Default dialing region support with `phone-number.core/*default-dialing-region*`
176 | * Dialing region derivation support with `phone-number.core/*info-dialing-region-derived*`
177 | * Improved support for maps as phone numbers (incl. dialing region retention)
178 | * Added validation for locale specification (`phone-number.util/valid-locale?`)
179 | * Samples generator now uses custom, simpler phone number parser
180 | * Additional arities in `phone-number.format/global?` and
181 | `phone-number.format/regional?`
182 | * Input validation is more relaxed (no strict asserts based on first digits)
183 | * Added `phone-number.core/has-raw-input?`
184 | * Added `phone-number.core/numeric`
185 | * Added utility functions in `phone-number.util`:
186 | - `count-digits`
187 | - `char-ranges->set`
188 | - `available-locales`
189 | * Specs updated
190 | * Tests updated
191 | * Generative testing based on generators and specs
192 |
193 | - Bug fixes:
194 |
195 | * Proper handling of corner cases (nil punning) at:
196 | - `phone-number.core/short-info`
197 | - `phone-number.core/time-zones-all-formats`
198 | - `phone-number.core/all-formats`
199 | - `phone-number.core/has-calling-code?`
200 | - `phone-number.core/raw-input`
201 |
202 | ## 8.12.4-0 (2020-06-11)
203 |
204 | - Initial release.
205 |
206 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | - tests
2 |
--------------------------------------------------------------------------------
/aliases/build/phone_number/build/main.clj:
--------------------------------------------------------------------------------
1 | (ns phone-number.build.main
2 |
3 | (:require [clojure.java.io :as io]
4 | [clojure.data.xml :as xml]
5 | [clojure.tools.build.api :as b]
6 | [juxt.pack.api :as pack]))
7 |
8 | (defn jar
9 | [_]
10 | (pack/library
11 | {:basis (b/create-basis)
12 | :path "phone-number.jar"
13 | :lib 'io.randomseed/phone-number
14 | :pom (java.io.ByteArrayInputStream.
15 | (.getBytes
16 | (xml/emit-str
17 | (xml/parse (io/reader "pom.xml")))
18 | "UTF-8"))}))
19 |
20 | (defn -main
21 | [& args]
22 | (jar nil))
23 |
--------------------------------------------------------------------------------
/aliases/codox/phone_number/codox/main.clj:
--------------------------------------------------------------------------------
1 | (ns phone-number.codox.main
2 | (:require [codox.main :as c]
3 | [clojure.java.io :as io]
4 | [clojure.edn :as edn]
5 | [clojure.tools.deps.alpha :as deps]
6 | [clojure.string :as str]))
7 |
8 | (defn- read-deps
9 | []
10 | (:project-edn (deps/find-edn-maps)))
11 |
12 | (defn- get-options [deps & more]
13 | (let [key (or (first more) :codox)
14 | version (or (second more) "0.0.0")
15 | codox (key deps)
16 | userdir (System/getProperty "user.dir")]
17 | (merge {:source-paths (:paths deps ["src"])
18 | :root-path (:root-path deps userdir)
19 | :output-path (str (io/file (:target deps userdir) "docs"))}
20 | codox
21 | {:name (str/capitalize (:name codox (:name deps)))
22 | :license (:license codox (:license deps))
23 | :package (:package codox (:license deps))
24 | :description (:description codox (:description deps))
25 | :version (or version (:version codox (:version deps)))})))
26 |
27 | (defn codox
28 | "Generate API documentation from source code."
29 | [key version]
30 | (let [version (when version (str version))
31 | deps (read-deps)
32 | options (get-options deps key version)]
33 | (codox.main/generate-docs options)
34 | (shutdown-agents)
35 | (println "Generated HTML docs in" (:output-path options))))
36 |
37 | (defn -main
38 | [& args]
39 | (codox :codox (first args)))
40 |
--------------------------------------------------------------------------------
/aliases/nrepl/nrepl.clj:
--------------------------------------------------------------------------------
1 | (ns ^{:clojure.tools.namespace.repl/load false} nrepl
2 | (:require
3 | [nrepl.server :refer [start-server stop-server]]
4 | [cider.nrepl]
5 | ;;[refactor-nrepl.middleware :as refactor.nrepl]
6 | [io.aviso.ansi]
7 | [puget.printer :refer [cprint]]))
8 |
9 | (defn start-nrepl-old
10 | [opts]
11 | (let [server
12 | (start-server
13 | :port (:port opts)
14 | :handler
15 | (apply nrepl.server/default-handler
16 | (conj (map #'cider.nrepl/resolve-or-fail cider.nrepl/cider-middleware)
17 | ;; #'refactor.nrepl/wrap-refactor
18 | )))]
19 | (spit ".nrepl-port" (:port server))
20 | (println (io.aviso.ansi/yellow (str "[phone-number] nREPL client can be connected to port " (:port server))))
21 | server))
22 |
23 | (defn nrepl-handler []
24 | (ns-resolve 'cider.nrepl 'cider-nrepl-handler))
25 |
26 | (defn start-nrepl
27 | [opts]
28 | (let [server (start-server :port (:port opts) :handler (nrepl-handler))]
29 | (println (io.aviso.ansi/yellow (str "[phone-number] nREPL client can be connected to port " (:port server))))
30 | server))
31 |
32 | (println "[phone-number] Starting nREPL server")
33 |
34 | (def server (start-nrepl {:port 5610}))
35 |
--------------------------------------------------------------------------------
/aliases/rebel/phone_number/rebel/main.clj:
--------------------------------------------------------------------------------
1 | (ns phone-number.rebel.main
2 | (:require
3 | rebel-readline.clojure.main
4 | rebel-readline.core
5 | io.aviso.ansi
6 | puget.printer))
7 |
8 | (defn -main
9 | [& args]
10 | (rebel-readline.core/ensure-terminal
11 | (rebel-readline.clojure.main/repl
12 | :init (fn []
13 | (try
14 | (println "[phone-number] Loading Clojure code, please wait...")
15 | (require 'user)
16 | (in-ns 'user)
17 | (catch Exception e
18 | (.printStackTrace e)
19 | (println "[phone-number] Failed to require user, this usually means there was a syntax error. See exception above.")))))))
20 |
--------------------------------------------------------------------------------
/bin/build:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "[phone-number] Building JAR, please wait..."
4 |
5 | clojure -M:build
6 |
--------------------------------------------------------------------------------
/bin/docs:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "[phone-number] Building docs, please wait..."
4 |
5 | clojure -M:docs "${1}"
6 |
--------------------------------------------------------------------------------
/bin/lint:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "[phone-number] Running Eastwood lint tool..."
4 |
5 | clojure -A:eastwood
6 |
--------------------------------------------------------------------------------
/bin/nrepl:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "[phone-number] Starting development environment, please wait..."
4 |
5 | clojure -A:dev:dev-nrepl:dev-rebel
6 |
--------------------------------------------------------------------------------
/bin/repl:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | echo "[phone-number] Starting development environment, please wait..."
4 |
5 | clojure -A:dev:dev-rebel
6 |
--------------------------------------------------------------------------------
/bin/test:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | test -f secrets.env && . secrets.env
4 | clojure -A:test "$@"
5 |
--------------------------------------------------------------------------------
/bin/test-notifier:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | terminal-notifier -message "${1}" -title "${2}" -appIcon "${3}"
4 |
--------------------------------------------------------------------------------
/circle.yml:
--------------------------------------------------------------------------------
1 | test:
2 | override:
3 | - 'make test'
4 |
--------------------------------------------------------------------------------
/deps.edn:
--------------------------------------------------------------------------------
1 | {
2 | :paths ["src" "resources"]
3 |
4 | :deps {trptr/java-wrapper {:mvn/version "0.2.3"}
5 | malabarba/lazy-map {:mvn/version "1.3"}
6 | org.clojure/core.memoize {:mvn/version "1.0.257"}
7 | com.googlecode.libphonenumber/libphonenumber {:mvn/version "8.13.6"}
8 | com.googlecode.libphonenumber/geocoder {:mvn/version "2.200"}
9 | com.googlecode.libphonenumber/carrier {:mvn/version "1.190"}
10 | com.googlecode.libphonenumber/prefixmapper {:mvn/version "2.200"}}
11 |
12 | :aliases {:dev {:extra-deps {org.clojure/tools.namespace {:mvn/version "1.1.0"}
13 | org.clojure/tools.deps.alpha {:mvn/version "0.9.857"}
14 | org.clojure/spec.alpha {:mvn/version "0.2.194"}
15 | org.clojure/test.check {:mvn/version "1.1.1"}
16 | orchestra/orchestra {:mvn/version "2021.01.01-1"}
17 | expound/expound {:mvn/version "0.8.7"}
18 | io.aviso/pretty {:mvn/version "1.1.1"}
19 | midje/midje {:mvn/version "1.10.5"}
20 | lambdaisland/kaocha {:mvn/version "1.69.1069"}
21 | lambdaisland/kaocha-midje {:mvn/version "0.0-5"}
22 | lambdaisland/kaocha-cloverage {:mvn/version "1.0.75"}
23 | spyscope/spyscope {:mvn/version "0.1.6"}
24 | fipp/fipp {:mvn/version "0.6.23"}
25 | cljfmt/cljfmt {:mvn/version "0.6.4"}
26 | ns-tracker/ns-tracker {:mvn/version "0.4.0"}
27 | mvxcvi/puget {:mvn/version "1.3.1"}
28 | org.slf4j/slf4j-simple {:mvn/version "2.0.0-alpha7"}}
29 | :extra-paths ["dev/src" "test"]
30 | :jvm-opts ["-Dclojure.spec.compile-asserts=true"]}
31 | :test {:extra-paths ["test"]
32 | :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"}
33 | io.aviso/pretty {:mvn/version "1.1.1"}
34 | midje/midje {:mvn/version "1.10.5"}
35 | orchestra/orchestra {:mvn/version "2021.01.01-1"}
36 | expound/expound {:mvn/version "0.8.7"}
37 | lambdaisland/kaocha {:mvn/version "1.69.1069"}
38 | lambdaisland/kaocha-midje {:mvn/version "0.0-5"}
39 | lambdaisland/kaocha-cloverage {:mvn/version "1.0.75"}
40 | org.slf4j/slf4j-simple {:mvn/version "2.0.0-alpha7"}}
41 | :main-opts ["-m" "kaocha.runner",
42 | "--config-file" "tests.edn",
43 | "--stc-num-tests" "100"
44 | "--stc-instrumentation"
45 | "--stc-asserts"]
46 | :jvm-opts ["-Xmx512m"]}
47 | :eastwood {:main-opts ["-m" "eastwood.lint" {:source-paths ["src"]}]
48 | :extra-deps {org.clojure/test.check {:mvn/version "1.1.1"}
49 | io.aviso/pretty {:mvn/version "1.1.1"}
50 | midje/midje {:mvn/version "1.10.5"}
51 | orchestra/orchestra {:mvn/version "2021.01.01-1"}
52 | expound/expound {:mvn/version "0.8.7"}
53 | org.clojure/tools.namespace {:mvn/version "1.1.0"}
54 | org.clojure/tools.deps.alpha {:mvn/version "0.9.857"}
55 | org.clojure/spec.alpha {:mvn/version "0.2.194"}
56 | jonase/eastwood {:mvn/version "0.3.13"}}}
57 | :docs {:extra-paths ["aliases/codox"]
58 | :extra-deps {org.clojure/tools.deps.alpha {:mvn/version "0.9.857"}
59 | org.clojure/spec.alpha {:mvn/version "0.2.194"}
60 | org.clojure/test.check {:mvn/version "1.1.1"}
61 | orchestra/orchestra {:mvn/version "2021.01.01-1"}
62 | expound/expound {:mvn/version "0.8.7"}
63 | codox/codox {:mvn/version "0.10.8"}}
64 | :main-opts ["-m" "phone-number.codox.main"]}
65 | :build {:paths ["."]
66 | :extra-paths ["aliases/build"]
67 | :deps {io.github.juxt/pack.alpha {:git/sha "9fd4a63ddeec3bedcbc819422de5a40ccb9eb8c9"}
68 | io.github.clojure/tools.build {:git/tag "v0.7.4" :git/sha "ac442da"}
69 | org.clojure/data.zip {:mvn/version "1.0.0"}
70 | org.clojure/data.xml {:mvn/version "0.2.0-alpha6"}}
71 | :ns-default phone-number.build.main
72 | :main-opts ["-m" "phone-number.build.main"]}
73 | :dev-nrepl {:jvm-opts ["-Dnrepl.load=true"]
74 | :extra-paths ["aliases/nrepl"]
75 | :extra-deps {cider/cider-nrepl {:mvn/version "0.25.9"}
76 | ;;refactor-nrepl {:mvn/version "2.3.1"}
77 | cider/piggieback {:mvn/version "0.5.2"}
78 | nrepl/nrepl {:mvn/version "0.8.3"}
79 | kaocha-nrepl/kaocha-nrepl {:mvn/version "1.0.3"}
80 | mvxcvi/puget {:mvn/version "1.3.1"}
81 | org.clojure/tools.nrepl {:mvn/version "0.2.13"}}}
82 | :cider-clj {:extra-paths ["aliases/nrepl"]
83 | :extra-deps {cider/cider-nrepl {:mvn/version "0.25.9"}
84 | cider/piggieback {:mvn/version "0.5.2"}
85 | nrepl/nrepl {:mvn/version "0.8.3"}
86 | kaocha-nrepl/kaocha-nrepl {:mvn/version "1.0.3"}
87 | mvxcvi/puget {:mvn/version "1.3.1"}
88 | org.clojure/tools.nrepl {:mvn/version "0.2.13"}}
89 | :main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}
90 | :dev-rebel {:extra-paths ["aliases/rebel"]
91 | :extra-deps {com.bhauman/rebel-readline {:mvn/version "0.1.4"}
92 | com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}
93 | io.aviso/pretty {:mvn/version "1.1.1"}
94 | mvxcvi/puget {:mvn/version "1.3.1"}}
95 | :main-opts ["-m" "phone-number.rebel.main"]}}
96 | :codox {:name "phone-number"
97 | :description "Generation, validation and inspection of phone numbers"
98 | :license "GNU Lesser General Public License 3.0"
99 | :package io.randomseed/phone-number
100 | :output-path "docs"
101 | :source-uri "https://github.com/randomseed-io/phone-number/tree/{version}/{filepath}#L{line}"
102 | :metadata {:doc/format :markdown}
103 | :themes [:default :randomseed]}}
104 |
--------------------------------------------------------------------------------
/dev/src/infra.clj:
--------------------------------------------------------------------------------
1 | (ns infra)
2 |
3 | ;; (defonce nrepl (start-nrepl))
4 |
--------------------------------------------------------------------------------
/dev/src/phone_number/generator.clj:
--------------------------------------------------------------------------------
1 | (ns
2 |
3 | ^{:doc "Sample data generator interface for phone-number library."
4 | :author "Paweł Wilk"
5 | :added "8.12.4-0"
6 | :no-doc true}
7 |
8 | phone-number.generator
9 |
10 | (:require [phone-number.core :as phone]
11 | [clojure.test.check.rose-tree :as rose]
12 | [clojure.test.check.generators :as gens])
13 |
14 | (:import [java.util Random]))
15 |
16 | (def phone-number
17 | (gens/no-shrink
18 | (clojure.test.check.generators/->Generator
19 | (fn [^Random rng _]
20 | (rose/make-rose
21 | (phone/generate nil nil phone/valid? nil nil (.nextLong ^Random rng))
22 | [])))))
23 |
--------------------------------------------------------------------------------
/dev/src/user.clj:
--------------------------------------------------------------------------------
1 | (ns user
2 | (:require
3 | [clojure.spec.alpha :as s]
4 | [orchestra.spec.test :as st]
5 | [clojure.spec.test.alpha :as cst]
6 | [clojure.spec.gen.alpha :as gen]
7 | [clojure.repl :refer :all]
8 | [clojure.tools.namespace.repl :refer [refresh
9 | refresh-all]]
10 | [expound.alpha :as expound]
11 | [phone-number.core :as phone]
12 | [phone-number.util :as util]
13 | [phone-number.spec :as spec]
14 | [phone-number.db :as db]
15 | [phone-number.region :as region]
16 | [phone-number.type :as type]
17 |
18 | [puget.printer :refer [cprint]]
19 | [midje.repl :refer :all]
20 | [kaocha.repl :refer :all]
21 | [infra])
22 |
23 | (:import [com.google.i18n.phonenumbers
24 | Phonenumber$PhoneNumber
25 | ShortNumberInfo
26 | geocoding.PhoneNumberOfflineGeocoder
27 | PhoneNumberToCarrierMapper
28 | PhoneNumberToTimeZonesMapper
29 | NumberParseException]))
30 |
31 | (set! *warn-on-reflection* true)
32 |
33 | (alter-var-root
34 | #'s/*explain-out*
35 | (constantly
36 | (expound/custom-printer {:show-valid-values? false
37 | :print-specs? true
38 | :theme :figwheel-theme})))
39 |
40 | (when (System/getProperty "nrepl.load")
41 | (require 'nrepl))
42 |
43 | (st/instrument)
44 |
45 | (defn test-all []
46 | (refresh)
47 | (cst/with-instrument-disabled
48 | (binding [phone/*default-dialing-region* :phone-number.region/us]
49 | (load-facts :print-facts))))
50 |
51 | (alter-var-root #'*warn-on-reflection*
52 | (constantly true)
53 | (when (thread-bound? #'*warn-on-reflection*)
54 | (set! *warn-on-reflection* true)))
55 |
56 | (comment
57 | (refresh-all)
58 | (cst/with-instrument-disabled (test-all))
59 | (cst/with-instrument-disabled (run-all))
60 | )
61 |
--------------------------------------------------------------------------------
/doc/30_specs.md:
--------------------------------------------------------------------------------
1 | # Specs and checks
2 |
3 | ## Predicates
4 |
5 | The phone-number provides many predicate functions that can be used to check for
6 | certain properties of phone numbers. These include:
7 |
8 | | Function Name | Description |
9 | |-----------------------------------------------------|-----------------------------------------------------------|
10 | | [`core/valid-input?`](phone-number.core.html#var-valid-input.3F) | Checks if a value can possibly be used as a phone number |
11 | | [`core/valid?`](phone-number.core.html#var-valid.3F) | Checks if a phone numer is valid |
12 | | [`core/invalid?`](phone-number.core.html#var-invalid.3F) | Checks if a phone numer is invalid |
13 | | [`core/possible?`](phone-number.core.html#var-possible.3F) | Checks if a phone numer is a possible number |
14 | | [`core/impossible?`](phone-number.core.html#var-impossible.3F) | Checks if a phone numer is an impossible number |
15 | | [`core/native?`](phone-number.core.html#var-native.3F) | Checks if a phone numer is in a native format (`PhoneNumber`) |
16 | | [`core/has-raw-input?`](phone-number.core.html#var-has-raw-input.3F) | Checks if a phone numer contains the retained raw input |
17 | | [`core/geographical?`](phone-number.core.html#var-geographical.3F) | Checks if a phone numer identifies a line with some geographical location |
18 | | [`core/short-possible?`](phone-number.core.html#var-short-possible.3F) | Checks if a phone numer is in a possible short number |
19 | | [`core/short-valid?`](phone-number.core.html#var-short-valid.3F) | Checks if a phone numer is in a valid short number |
20 | | [`core/short-emergency?`](phone-number.core.html#var-short-emergency.3F) | Checks if a phone numer is in an emergency number |
21 | | [`core/short-to-emergency?`](phone-number.core.html#var-short-to-emergency.3F) | Checks if a phone numer can be used to connect to an emergency |
22 | | [`core/short-to-emergency?`](phone-number.core.html#var-short-to-emergency.3F) | Checks if a phone numer can be used to connect to an emergency |
23 |
24 |
25 | ## Specs
26 |
27 | Clojure Spec is used in the phone-number library to validate data and generate
28 | property-based tests. Most of the defined specs have generators attached.
29 |
30 | There are 3 groups of specs:
31 |
32 | * **Input specs**, created for easy data validation.
33 | (ns-prefix: `phone-number.input`)
34 |
35 | * **Generic specs** used to describe the output data.
36 | (ns-prefix: `phone-number`)
37 |
38 | * Specs that are used **internally** to test the library for corner cases
39 | and make sure that new features or other changes won't break anything.
40 | (ns-prefixes: `phone-number.arg`, `phone-number.args`, `phone-number.props`)
41 |
42 | This page lists the input and some of the generic specs. To use them just require
43 | `phone-number.spec`, `clojure.spec.alpha` and optionally `clojure.spec.gen.alpha`:
44 |
45 | ``` clojure
46 | (require [phone-number.spec :as spec]
47 | [clojure.spec.alpha :as s]
48 | [clojure.spec.gen.alpha :as gen])
49 | ```
50 |
51 | | Spec Name | Data description |
52 | |-----------------------------------|-------------------------------------------------------|
53 | |`:phone-number.input/region` | region code |
54 | |`:phone-number.input/type` | phone number type |
55 | |`:phone-number.input/leniency` | phone number leniency |
56 | |`:phone-number.input/format` | phone number format |
57 | |`:phone-number.input/format-global` | phone number format (with calling code prefix) |
58 | |`:phone-number.input/format-regional` | phone number format (without calling code prefix) |
59 | |`:phone-number.input/tz-format` | time zone format |
60 | |`:phone-number.input/net-code` | global network calling code |
61 | |`:phone-number.input/country-code` | country calling code |
62 | |`:phone-number.input/calling-code` | calling code (either global or country) |
63 | |`:phone-number.input/cost` | cost class of short numbers |
64 | |`:phone-number.input/native` | phone number in native format (`PhoneNumber` object)|
65 | |`:phone-number.input/native-valid` | native phone number which is valid |
66 | |`:phone-number.input/string` | phone number as a string |
67 | |`:phone-number.input/string-global` | phone number as a string with a calling code |
68 | |`:phone-number.input/string-regional` | phone number as a string without a calling code |
69 | |`:phone-number.input/string-valid` | valid phone number as a string |
70 | |`:phone-number.input/string-invalid` | invalid phone number as a string |
71 | |`:phone-number.input/numeric` | phone number as natural number without calling code |
72 | |`:phone-number/info` | phone number as a map |
73 | |`:phone-number/info-valid` | valid phone number as a map |
74 | |`:phone-number/info-invalid` | invalid phone number as a map |
75 | |`:phone-number.input/possible` | possible phone number |
76 | |`:phone-number.input/impossible` | impossible phone number |
77 | |`:phone-number.input/unknown` | phone number of unknown type |
78 | |`:phone-number.input/has-region` | phone number with region code information |
79 | |`:phone-number.input/has-calling-code` | phone number with calling code |
80 | |`:phone-number.input/has-location` | phone number having geographical location |
81 | |`:phone-number.input/has-time-zone` | phone number having time zone information |
82 | |`:phone-number.input/has-known-type` | phone number of known type |
83 | |`:phone-number.input/mobile` | mobile phone number |
84 | |`:phone-number.input/fixed-line` | fixed-line phone number |
85 | |`:phone-number.input/toll-free` | toll-free phone number |
86 | |`:phone-number.input/premium-rate` | premium-rate phone number |
87 | |`:phone-number.input/shared-cost` | shared-cost phone number |
88 | |`:phone-number.input/voip` | VoIP phone number |
89 | |`:phone-number.input/personal ` | personal phone number |
90 | |`:phone-number.input/pager` | pager number |
91 | |`:phone-number.input/uan` | UAN number |
92 | |`:phone-number.input/voicemail` | voicemail number |
93 | |`:phone-number.input/fixed-line-or-mobile`| fixed-line or mobile number (incl. uncertain) |
94 | |`:phone-number.input/uncertain-fixed-line-or-mobile` | uncertain number (fixed line or mobile) |
95 | |`:phone-number.input/maybe-mobile` | uncertain number (fixed line or mobile) or mobile |
96 | |`:phone-number.input/maybe-fixed-line` | uncertain number (fixed line or mobile) or fixed-line |
97 | |`:phone-number.input/short` | valid short number |
98 | |`:phone-number.input/maybe-short` | possible short number |
99 | |`:phone-number.input.short/valid` | valid short number |
100 | |`:phone-number.input.short/invalid` | invalid short number |
101 | |`:phone-number.input.short/possible` | possible short number |
102 | |`:phone-number.input.short/carrier-specific`| carrier-specific short number |
103 | |`:phone-number.input.short/info` | short number properties as a map |
104 | |`:phone-number.input/number` | phone number (with calling code or without) |
105 |
106 | Phone-number also contains specs for functions, however they are intended for testing
107 | and it is **NOT RECOMMENDED** to enable the **instrumentation** in production.
108 |
109 | Please note that if you intend to use phone-number's specs in a program (not in
110 | phone-number's REPL) you should add proper dependencies since production profile of
111 | phone-number does not depend on spec nor test library. Example, minimal `deps.edn`:
112 |
113 | ``` clojure
114 | {:paths ["src" "resources"]
115 |
116 | :deps {io.randomseed/phone-number {:mvn/version "8.12.16-1"}}
117 |
118 | :aliases {
119 | :dev {
120 | :extra-deps {org.clojure/spec.alpha {:mvn/version "0.2.194"}
121 | org.clojure/test.check {:mvn/version "1.1.0"}}
122 | :extra-paths ["dev/src" "test"]
123 | :jvm-opts ["-Dclojure.spec.compile-asserts=true"]}
124 |
125 | :test {
126 | :extra-paths ["test"]
127 | :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}}}}
128 | ```
129 |
--------------------------------------------------------------------------------
/doc/40_development.md:
--------------------------------------------------------------------------------
1 | # Development
2 |
3 | [](https://circleci.com/gh/randomseed-io/phone-number)
4 |
5 | ## Source code
6 |
7 | * https://github.com/randomseed-io/phone-number
8 |
9 | ## Common tasks
10 |
11 | ### Building docs
12 |
13 | ```bash
14 | make docs
15 | ```
16 |
17 | ### Building JAR
18 |
19 | ```bash
20 | make jar
21 | ```
22 |
23 | ### Rebuilding POM
24 |
25 | ```bash
26 | make pom
27 | ```
28 |
29 | ### Signing POM
30 |
31 | ```bash
32 | make sig
33 | ```
34 |
35 | ### Deploying to Clojars
36 |
37 | ```bash
38 | make deploy
39 | ```
40 |
41 | ### Interactive development
42 |
43 | ```bash
44 | bin/repl
45 | ```
46 |
47 | Starts REPL and nREPL server (port number is stored in `.nrepl-port`).
48 |
49 | ### Testing
50 |
51 | ```bash
52 | bin/test
53 | ```
54 |
--------------------------------------------------------------------------------
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | pom.xml
2 | pom.xml.asc
3 | *.jar
4 | *.class
5 | /lib/
6 | /classes/
7 | /target/
8 | /checkouts/
9 | .lein-deps-sum
10 | .lein-repl-history
11 | .lein-plugins/
12 | .lein-failures
13 | .nrepl-port
14 | .cpcache/
15 |
--------------------------------------------------------------------------------
/docs/40_development.html:
--------------------------------------------------------------------------------
1 |
3 |
Template macro for constructing specs with generators for the given predicate. It uses the generate function from phone-number.core to support generation of samples that are meeting the criteria.
Parses a time zone format specification and returns a value that can be supplied to phone-number functions. If nil is given it returns the default value.
For the given Locale object and TextStyle object renders a string describing a time zone identifier (given as a string) passed as the first argument. If the style is nil then the original object passed as a zone-id argument is returned.