libphonenumber-js 1.12.39 → 1.12.41

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.
Files changed (183) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/bundle/libphonenumber-js.min.js +1 -1
  3. package/bundle/libphonenumber-js.min.js.map +1 -1
  4. package/bundle/libphonenumber-max.js +1 -1
  5. package/bundle/libphonenumber-max.js.map +1 -1
  6. package/bundle/libphonenumber-min.js +1 -1
  7. package/bundle/libphonenumber-min.js.map +1 -1
  8. package/bundle/libphonenumber-mobile.js +1 -1
  9. package/bundle/libphonenumber-mobile.js.map +1 -1
  10. package/max/metadata/metadata.max.json +1 -1
  11. package/max/metadata/metadata.max.json.js +1 -1
  12. package/metadata.full.json +1 -1
  13. package/metadata.full.json.js +1 -1
  14. package/metadata.max.json +1 -1
  15. package/metadata.max.json.js +1 -1
  16. package/metadata.min.json +1 -1
  17. package/metadata.min.json.js +1 -1
  18. package/metadata.mobile.json +1 -1
  19. package/metadata.mobile.json.js +1 -1
  20. package/min/metadata/metadata.min.json +1 -1
  21. package/min/metadata/metadata.min.json.js +1 -1
  22. package/mobile/metadata/metadata.mobile.json +1 -1
  23. package/mobile/metadata/metadata.mobile.json.js +1 -1
  24. package/package.json +1 -1
  25. package/.babelrc +0 -21
  26. package/.nycrc +0 -27
  27. package/METADATA.md +0 -155
  28. package/autoupdate.cmd +0 -6
  29. package/autoupdate.sh +0 -16
  30. package/build/AsYouType.test.js +0 -1339
  31. package/build/AsYouTypeFormatter.PatternMatcher.test.js +0 -502
  32. package/build/AsYouTypeFormatter.PatternParser.test.js +0 -49
  33. package/build/AsYouTypeFormatter.util.test.js +0 -24
  34. package/build/PhoneNumber.test.js +0 -141
  35. package/build/PhoneNumberMatcher.test.js +0 -122
  36. package/build/findNumbers/util.test.js +0 -34
  37. package/build/findPhoneNumbersInText.test.js +0 -300
  38. package/build/format.test.js +0 -339
  39. package/build/formatIncompletePhoneNumber.test.js +0 -33
  40. package/build/getCountries.test.js +0 -13
  41. package/build/getCountryCallingCode.test.js +0 -18
  42. package/build/getExampleNumber.test.js +0 -21
  43. package/build/helpers/RFC3966.test.js +0 -47
  44. package/build/helpers/applyInternationalSeparatorStyle.test.js +0 -13
  45. package/build/helpers/checkNumberLength.test.js +0 -81
  46. package/build/helpers/extractCountryCallingCode.test.js +0 -23
  47. package/build/helpers/extractNationalNumber.test.js +0 -27
  48. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -20
  49. package/build/helpers/extractPhoneContext.test.js +0 -71
  50. package/build/helpers/getNumberType.test.js +0 -23
  51. package/build/helpers/matchesEntirely.test.js +0 -16
  52. package/build/helpers/mergeArrays.test.js +0 -12
  53. package/build/helpers/parseDigits.test.js +0 -12
  54. package/build/helpers/stripIddPrefix.test.js +0 -22
  55. package/build/isPossible.test.js +0 -121
  56. package/build/isPossiblePhoneNumber.test.js +0 -42
  57. package/build/isValid.test.js +0 -144
  58. package/build/isValidPhoneNumber.test.js +0 -29
  59. package/build/legacy/findNumbers.test.js +0 -210
  60. package/build/legacy/findPhoneNumbers.test.js +0 -245
  61. package/build/legacy/format.test.js +0 -299
  62. package/build/legacy/getNumberType.test.js +0 -80
  63. package/build/legacy/isPossibleNumber.test.js +0 -82
  64. package/build/legacy/isValidNumber.test.js +0 -102
  65. package/build/legacy/isValidNumberForRegion.test.js +0 -40
  66. package/build/legacy/parse.test.js +0 -617
  67. package/build/legacy/searchNumbers.test.js +0 -33
  68. package/build/metadata.test.js +0 -170
  69. package/build/parse.test.js +0 -653
  70. package/build/parseIncompletePhoneNumber.test.js +0 -109
  71. package/build/parsePhoneNumber.test.js +0 -98
  72. package/build/parsePhoneNumberWithError.test.js +0 -140
  73. package/build/searchPhoneNumbersInText.test.js +0 -51
  74. package/build/tools/semver-compare.test.js +0 -13
  75. package/build/validatePhoneNumberLength.test.js +0 -37
  76. package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +0 -88
  77. package/build-scripts/check-for-metadata-changes-and-release.js +0 -67
  78. package/build-scripts/check-for-uncommitted-files.js +0 -13
  79. package/build-scripts/create-commonjs-package-json-file.js +0 -11
  80. package/build-scripts/create-js-file-for-json-file.js +0 -14
  81. package/build-scripts/create-metadata-update-branch.js +0 -31
  82. package/build-scripts/generate-country-codes-list-in-typescript.js +0 -14
  83. package/build-scripts/generate-metadata-from-google-metadata.js +0 -75
  84. package/build-scripts/helpers/commit.js +0 -14
  85. package/build-scripts/helpers/exec.js +0 -6
  86. package/build-scripts/helpers/getUncommittedChanges.js +0 -33
  87. package/build-scripts/helpers/sendEmail.js +0 -62
  88. package/build-scripts/helpers/updateMetadataFromGoogleMetadata.js +0 -130
  89. package/build-scripts/pull-google-metadata.js +0 -29
  90. package/es6/AsYouType.test.js +0 -1336
  91. package/es6/AsYouTypeFormatter.PatternMatcher.test.js +0 -499
  92. package/es6/AsYouTypeFormatter.PatternParser.test.js +0 -46
  93. package/es6/AsYouTypeFormatter.util.test.js +0 -22
  94. package/es6/PhoneNumber.test.js +0 -138
  95. package/es6/PhoneNumberMatcher.test.js +0 -119
  96. package/es6/findNumbers/util.test.js +0 -32
  97. package/es6/findPhoneNumbersInText.test.js +0 -297
  98. package/es6/format.test.js +0 -336
  99. package/es6/formatIncompletePhoneNumber.test.js +0 -30
  100. package/es6/getCountries.test.js +0 -10
  101. package/es6/getCountryCallingCode.test.js +0 -15
  102. package/es6/getExampleNumber.test.js +0 -18
  103. package/es6/helpers/RFC3966.test.js +0 -45
  104. package/es6/helpers/applyInternationalSeparatorStyle.test.js +0 -10
  105. package/es6/helpers/checkNumberLength.test.js +0 -76
  106. package/es6/helpers/extractCountryCallingCode.test.js +0 -20
  107. package/es6/helpers/extractNationalNumber.test.js +0 -24
  108. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -17
  109. package/es6/helpers/extractPhoneContext.test.js +0 -68
  110. package/es6/helpers/getNumberType.test.js +0 -20
  111. package/es6/helpers/matchesEntirely.test.js +0 -13
  112. package/es6/helpers/mergeArrays.test.js +0 -9
  113. package/es6/helpers/parseDigits.test.js +0 -9
  114. package/es6/helpers/stripIddPrefix.test.js +0 -19
  115. package/es6/isPossible.test.js +0 -118
  116. package/es6/isPossiblePhoneNumber.test.js +0 -39
  117. package/es6/isValid.test.js +0 -141
  118. package/es6/isValidPhoneNumber.test.js +0 -26
  119. package/es6/legacy/findNumbers.test.js +0 -207
  120. package/es6/legacy/findPhoneNumbers.test.js +0 -243
  121. package/es6/legacy/format.test.js +0 -296
  122. package/es6/legacy/getNumberType.test.js +0 -77
  123. package/es6/legacy/isPossibleNumber.test.js +0 -79
  124. package/es6/legacy/isValidNumber.test.js +0 -99
  125. package/es6/legacy/isValidNumberForRegion.test.js +0 -37
  126. package/es6/legacy/parse.test.js +0 -614
  127. package/es6/legacy/searchNumbers.test.js +0 -30
  128. package/es6/metadata.test.js +0 -166
  129. package/es6/parse.test.js +0 -650
  130. package/es6/parseIncompletePhoneNumber.test.js +0 -105
  131. package/es6/parsePhoneNumber.test.js +0 -95
  132. package/es6/parsePhoneNumberWithError.test.js +0 -137
  133. package/es6/searchPhoneNumbersInText.test.js +0 -48
  134. package/es6/tools/semver-compare.test.js +0 -10
  135. package/es6/validatePhoneNumberLength.test.js +0 -34
  136. package/jest.config.json +0 -26
  137. package/rollup.config.mjs +0 -57
  138. package/source/AsYouType.test.js +0 -1409
  139. package/source/AsYouTypeFormatter.PatternMatcher.test.js +0 -644
  140. package/source/AsYouTypeFormatter.PatternParser.test.js +0 -70
  141. package/source/AsYouTypeFormatter.util.test.js +0 -25
  142. package/source/PhoneNumber.test.js +0 -138
  143. package/source/PhoneNumberMatcher.test.js +0 -112
  144. package/source/findNumbers/util.test.js +0 -37
  145. package/source/findPhoneNumbersInText.test.js +0 -316
  146. package/source/format.test.js +0 -273
  147. package/source/formatIncompletePhoneNumber.test.js +0 -33
  148. package/source/getCountries.test.js +0 -12
  149. package/source/getCountryCallingCode.test.js +0 -16
  150. package/source/getExampleNumber.test.js +0 -20
  151. package/source/helpers/RFC3966.test.js +0 -39
  152. package/source/helpers/applyInternationalSeparatorStyle.test.js +0 -11
  153. package/source/helpers/checkNumberLength.test.js +0 -85
  154. package/source/helpers/extractCountryCallingCode.test.js +0 -23
  155. package/source/helpers/extractNationalNumber.test.js +0 -27
  156. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.test.js +0 -18
  157. package/source/helpers/extractPhoneContext.test.js +0 -107
  158. package/source/helpers/getNumberType.test.js +0 -27
  159. package/source/helpers/matchesEntirely.test.js +0 -14
  160. package/source/helpers/mergeArrays.test.js +0 -10
  161. package/source/helpers/parseDigits.test.js +0 -10
  162. package/source/helpers/stripIddPrefix.test.js +0 -24
  163. package/source/isPossible.test.js +0 -86
  164. package/source/isPossiblePhoneNumber.test.js +0 -36
  165. package/source/isValid.test.js +0 -123
  166. package/source/isValidPhoneNumber.test.js +0 -23
  167. package/source/legacy/findNumbers.test.js +0 -220
  168. package/source/legacy/findPhoneNumbers.test.js +0 -252
  169. package/source/legacy/format.test.js +0 -246
  170. package/source/legacy/getNumberType.test.js +0 -70
  171. package/source/legacy/isPossibleNumber.test.js +0 -49
  172. package/source/legacy/isValidNumber.test.js +0 -95
  173. package/source/legacy/isValidNumberForRegion.test.js +0 -31
  174. package/source/legacy/parse.test.js +0 -533
  175. package/source/legacy/searchNumbers.test.js +0 -29
  176. package/source/metadata.test.js +0 -178
  177. package/source/parse.test.js +0 -561
  178. package/source/parseIncompletePhoneNumber.test.js +0 -118
  179. package/source/parsePhoneNumber.test.js +0 -99
  180. package/source/parsePhoneNumberWithError.test.js +0 -115
  181. package/source/searchPhoneNumbersInText.test.js +0 -47
  182. package/source/tools/semver-compare.test.js +0 -43
  183. package/source/validatePhoneNumberLength.test.js +0 -33
@@ -1,31 +0,0 @@
1
- // (deprecated because unused)
2
-
3
- // Ccreates a new git branch called "update-metadata" and switches into it.
4
- // If the branch with such name already exists, it overwrites it with a new one.
5
-
6
- import exec from './helpers/exec.js'
7
-
8
- let metadata_branch_exists = false
9
-
10
- try
11
- {
12
- exec('git rev-parse --verify update-metadata')
13
- metadata_branch_exists = true
14
- }
15
- catch (error)
16
- {
17
- if (error.message.indexOf('fatal: Needed a single revision') === -1)
18
- {
19
- throw error
20
- }
21
- }
22
-
23
- if (metadata_branch_exists)
24
- {
25
- console.log(exec('git checkout master'))
26
- console.log(exec('git branch -D update-metadata'))
27
- }
28
-
29
- console.log(exec('git pull'))
30
- console.log(exec('git branch update-metadata origin/master'))
31
- console.log(exec('git checkout update-metadata'))
@@ -1,14 +0,0 @@
1
- import metadata from '../metadata.min.json' with { type: 'json' }
2
- import fs from 'fs'
3
-
4
- const countryCodes = Object.keys(metadata.countries)
5
-
6
- // Fills in the list of possible values of `CountryCode` type in the TypeScript definition file.
7
- fs.writeFileSync(
8
- './types.d.ts',
9
- fs.readFileSync('./types.d.ts', 'utf-8').replace(
10
- /export type CountryCode = .*;/,
11
- `export type CountryCode = ${countryCodes.map(_ => `'${_}'`).join(' | ')};`
12
- ),
13
- 'utf-8'
14
- )
@@ -1,75 +0,0 @@
1
- // Generates JSON metadata from Google's `PhoneNumberMetadata.xml` file.
2
-
3
- import minimist from 'minimist'
4
- import fs from 'fs'
5
-
6
- import { version, generate, compress } from 'libphonenumber-metadata-generator'
7
-
8
- // const REGION_CODE_FOR_NON_GEO_ENTITY = '001'
9
-
10
- const input_file = process.argv[2]
11
- const output_file = process.argv[3]
12
-
13
- const input = fs.readFileSync(input_file, 'utf8')
14
-
15
- const command_line_arguments = minimist(process.argv.slice(4))
16
-
17
- // Included countries
18
- let included_countries
19
- if (command_line_arguments.countries) {
20
- included_countries = command_line_arguments.countries.split(',')
21
- console.log('Included countries:', included_countries)
22
- included_countries = new Set(included_countries)
23
- }
24
-
25
- // Include all regular expressions
26
- let extended = false
27
- if (command_line_arguments.extended) {
28
- console.log('Include extra validation regular expressions')
29
- extended = true
30
- }
31
-
32
- // Included phone number types
33
- let included_phone_number_types
34
- if (command_line_arguments.types) {
35
- included_phone_number_types = command_line_arguments.types.split(',')
36
- console.log('Included phone number types:', included_phone_number_types)
37
- included_phone_number_types = new Set(included_phone_number_types)
38
- }
39
-
40
- // Generate and compress metadata
41
- generate(input, version, included_countries, extended, included_phone_number_types).then((output) => {
42
- // Write uncompressed metadata into a file for easier debugging
43
- if (command_line_arguments.debug) {
44
- console.log('Output uncompressed JSON for debugging')
45
- fs.writeFileSync('./metadata.json', JSON.stringify(output, undefined, 3))
46
- }
47
-
48
- // Compress the generated metadata
49
- fs.writeFileSync(output_file, JSON.stringify(compress(output)))
50
-
51
- // Output mobile phone number type examples
52
- if (command_line_arguments.examples === 'mobile') {
53
- var examples = Object.keys(output.countries).reduce(function(out, country_code) {
54
- // if (country_code === REGION_CODE_FOR_NON_GEO_ENTITY) {
55
- // return out
56
- // }
57
- var mobile = output.countries[country_code].examples.mobile
58
- var fixed_line = output.countries[country_code].examples.fixed_line
59
- if (mobile) {
60
- out[country_code] = mobile
61
- }
62
- // "TA" country doesn't have any mobile phone number example
63
- else if (fixed_line) {
64
- console.warn(`Country ${country_code} doesn't have a mobile phone number example. Substituting with a fixed line phone number example.`)
65
- out[country_code] = fixed_line
66
- } else {
67
- console.error(`Country ${country_code} doesn't have neither a mobile phone number example nor a fixed line phone number example.`)
68
- // `async` errors aren't being caught at the top level in Node.js
69
- process.exit(1)
70
- }
71
- return out
72
- }, {})
73
- fs.writeFileSync('./examples.mobile.json', JSON.stringify(examples))
74
- }
75
- })
@@ -1,14 +0,0 @@
1
- import exec from './exec.js'
2
-
3
- // Commits the current changes files in the local git repository.
4
- export default function() {
5
- console.log()
6
- console.log('========================================')
7
- console.log('= Committing changes =')
8
- console.log('========================================')
9
- console.log()
10
-
11
- console.log(exec('git add .'))
12
-
13
- console.log(exec('git commit -m "Updated metadata"'))
14
- }
@@ -1,6 +0,0 @@
1
- import { execSync } from 'child_process'
2
-
3
- // Executes a command.
4
- export default function exec(command) {
5
- return execSync(command).toString().trim()
6
- }
@@ -1,33 +0,0 @@
1
- import { exec } from 'child_process'
2
-
3
- export default function getUncommittedChanges() {
4
- return new Promise((resolve, reject) => {
5
- exec('git status --porcelain', (error, stdout, stderr) => {
6
- if (error) {
7
- reject(error);
8
- return
9
- }
10
-
11
- if (stderr) {
12
- reject(new Error(stderr.toString()))
13
- return
14
- }
15
-
16
- const output = stdout.toString().trim()
17
-
18
- if (!output) {
19
- resolve([]);
20
- }
21
-
22
- const uncommittedFiles = output.trim().split('\n').map((line) => {
23
- line = line.trim()
24
- const whitespaceIndex = line.indexOf(' ')
25
- const status = line.slice(0, whitespaceIndex)
26
- const filename = line.slice(whitespaceIndex + ' '.length)
27
- return { status, filename }
28
- })
29
-
30
- resolve(uncommittedFiles)
31
- })
32
- })
33
- }
@@ -1,62 +0,0 @@
1
- import fs from 'fs'
2
- import gmailSend from 'gmail-send'
3
-
4
- export default async function sendEmail({ subject, text }) {
5
- const emailSettings = getEmailSettings()
6
- if (emailSettings) {
7
- // Send an email notification through GMail.
8
- //
9
- // Example output:
10
- //
11
- // {
12
- // result: '250 2.0.0 OK 1759154240 2adb3069b0e04-58313dd67c4sm4173572e87.55 - gsmtp',
13
- // full: {
14
- // accepted: [ 'kuchumovn@gmail.com' ],
15
- // rejected: [],
16
- // ehlo: [
17
- // 'SIZE 35882577',
18
- // '8BITMIME',
19
- // 'AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH',
20
- // 'ENHANCEDSTATUSCODES',
21
- // 'PIPELINING',
22
- // 'CHUNKING',
23
- // 'SMTPUTF8'
24
- // ],
25
- // envelopeTime: 297,
26
- // messageTime: 565,
27
- // messageSize: 799,
28
- // response: '250 2.0.0 OK 1759154240 2adb3069b0e04-58313dd67c4sm4173572e87.55 - gsmtp',
29
- // envelope: { from: 'kuchumovn@gmail.com', to: [Array] },
30
- // messageId: '<b7c49e37-1f0f-5c42-13c5-2398a778abd2@gmail.com>'
31
- // }
32
- // }
33
- //
34
- const { result, full } = await gmailSend({
35
- user: emailSettings.email,
36
- pass: emailSettings.accessToken,
37
- to: emailSettings.email,
38
- subject,
39
- text
40
- // html: '<b>html text</b>' // alternative to specifying `text`, one could specify `html`.
41
- })()
42
- return true
43
- }
44
- }
45
-
46
- // Reads email settings from a JSON file just outside of `libphonenumber-js` repo folder.
47
- function getEmailSettings() {
48
- const emailSettingsPath = '../libphonenumber-js-autoupdate-email-notification-settings.json'
49
- if (fs.existsSync(emailSettingsPath)) {
50
- const emailSettings = JSON.parse(fs.readFileSync(emailSettingsPath, 'utf-8'))
51
- // Validate `emailSettings`.
52
- if (!emailSettings.email) {
53
- throw new Error('`email` parameter not specified in the email config file')
54
- }
55
- // The instructions on how to obtain an `accessToken` are described in `gmail-send` readme:
56
- // https://www.npmjs.com/package/gmail-send
57
- if (!emailSettings.accessToken) {
58
- throw new Error('`accessToken` parameter not specified in the email config file')
59
- }
60
- return emailSettings;
61
- }
62
- }
@@ -1,130 +0,0 @@
1
- import fs from 'fs'
2
- import semver from 'semver'
3
-
4
- import exec from './exec.js'
5
-
6
- // Checks if Google's metadata XML file has changes, and, if it has,
7
- // generates JSON metadata files from it, runs the tests and updates `CHANGELOG.md`.
8
- export default function(googleMetadataFilePath, metadataInfoFilePath) {
9
- let metadataChanged = exec(`git ls-files --modified ${googleMetadataFilePath}`)
10
-
11
- if (!metadataChanged) {
12
- console.log()
13
- console.log('========================================')
14
- console.log('= Metadata is up-to-date. Exiting. =')
15
- console.log('========================================')
16
- console.log()
17
-
18
- return
19
- }
20
-
21
- console.log()
22
- console.log('========================================')
23
- console.log('= Metadata has changed, updating files =')
24
- console.log('========================================')
25
- console.log()
26
-
27
- console.log(exec('npm run metadata:generate'))
28
-
29
- console.log()
30
- console.log('========================================')
31
- console.log('= Running tests =')
32
- console.log('========================================')
33
- console.log()
34
-
35
- // console.log('* Actually not running tests because if they fail then it won\'t be reported in any way, and if instead tests fail for the Pull Request on github then the repo owner will be notified by Travis CI about that.')
36
- console.log(exec('npm run build'))
37
- console.log(exec('npm test'))
38
-
39
- let modified_files = exec('git ls-files --modified').split(/\s/)
40
-
41
- let unexpected_modified_files = modified_files.filter((file) => {
42
- return file !== googleMetadataFilePath &&
43
- !/^metadata\.[a-z]+\.json$/.test(file) &&
44
- !/^examples\.[a-z]+\.json$/.test(file)
45
- })
46
-
47
- // Turned off this "modified files" check
48
- // because on Windows random files constantly got "modified"
49
- // without actually being modified.
50
- // (perhaps something related to line endings)
51
- if (false && unexpected_modified_files.length > 0) {
52
- let error
53
-
54
- error += 'Only `' + googleMetadataFilePath + '`, `metadata.*.json` and `examples.*.json` files should be modified. Unexpected modified files:'
55
- error += '\n'
56
- error += '\n'
57
- error += unexpected_modified_files.join('\n')
58
-
59
- console.log()
60
- console.log('========================================')
61
- console.log('= Error =')
62
- console.log('========================================')
63
- console.log()
64
- console.log(error)
65
-
66
- throw new Error(error)
67
- }
68
-
69
- // Doesn't work
70
- //
71
- // // http://stackoverflow.com/questions/33610682/git-list-of-staged-files
72
- // let staged_files = exec('git diff --name-only --cached').split(/\s/)
73
- //
74
- // if (staged_files.length > 0)
75
- // {
76
- // console.log()
77
- // console.log('========================================')
78
- // console.log('= Error =')
79
- // console.log('========================================')
80
- // console.log()
81
- // console.log('There are some staged files already. Aborting metadata update process.')
82
- // console.log()
83
- // console.log(staged_files.join('\n'))
84
- //
85
- // process.exit(1)
86
- // }
87
-
88
- // Add an entry in `CHANGELOG.md`.
89
- addMetadataUpdateChangelogEntry(metadataInfoFilePath)
90
-
91
- return true
92
- }
93
-
94
- function addMetadataUpdateChangelogEntry(metadataInfoFilePath) {
95
- const {
96
- version: metadataVersion,
97
- changes: metadataChanges
98
- } = JSON.parse(fs.readFileSync(metadataInfoFilePath, 'utf8'))
99
-
100
- const packageVersion = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version
101
- const nextPackageVersion = semver.inc(packageVersion, 'patch')
102
-
103
- const now = new Date()
104
-
105
- let changesLog = ''
106
- changesLog += `${nextPackageVersion} / ${now.getDate()}.${now.getMonth() + 1}.${now.getFullYear()}`
107
- changesLog += '\n'
108
- changesLog += '==================='
109
- changesLog += '\n'
110
- changesLog += '\n'
111
- changesLog += `* Updated metadata to version ${metadataVersion}`
112
- if (metadataChanges.length > 0) {
113
- changesLog += ':'
114
- changesLog += '\n'
115
- changesLog += metadataChanges.map(change => ` - ${change.replace(/\n/g, '\n' + ' ')}`).join('\n')
116
- }
117
-
118
- const changelog = fs.readFileSync('./CHANGELOG.md', 'utf8')
119
-
120
- const changesLogStartMarker = '<!-- CHANGELOG START -->'
121
- const changesLogStartMarkerStartsAt = changelog.indexOf(changesLogStartMarker)
122
- if (changesLogStartMarkerStartsAt < 0) {
123
- throw new Error('Changelog start marker not found in CHANGELOG.md')
124
- }
125
- const changesLogStartsAt = changesLogStartMarkerStartsAt + changesLogStartMarker.length
126
- const changelogPre = changelog.slice(0, changesLogStartsAt)
127
- const previousChangesLog = changelog.slice(changesLogStartsAt).trim()
128
-
129
- fs.writeFileSync('./CHANGELOG.md', changelogPre + '\n\n' + changesLog + '\n\n' + previousChangesLog)
130
- }
@@ -1,29 +0,0 @@
1
- import fs from 'fs'
2
- import { download } from 'libphonenumber-metadata-generator'
3
-
4
- const metadataFileOutputPath = process.argv[2]
5
- const infoFileOutputPath = process.argv[3]
6
-
7
- // Pulls the latest released metadata from Google's repostory.
8
- // Updates `PhoneNumberMetadata.xml` and `metadata-info.json` files.
9
- download().then(({ date, version, changes, xml }) => {
10
- // Print the metadata version and a list of changes.
11
- console.log('========================================')
12
- console.log(`= Metadata / ${version}`)
13
- console.log('=')
14
- console.log(`= Date: ${date.toUTCString()
15
- .slice(0, date.toUTCString().indexOf('00:00:00') - 1)
16
- .slice(date.toUTCString().indexOf(',') + ', '.length)
17
- }`)
18
- console.log('=')
19
- const consoleOutputPrefix = '= '
20
- console.log(`= Changes:\n${changes.map(_ => consoleOutputPrefix + '* ' + _.replace(/\n/g, '\n' + consoleOutputPrefix + ' ')).join('\n')}`)
21
- console.log('========================================')
22
- // Write metadata changes info.
23
- fs.writeFileSync(infoFileOutputPath, JSON.stringify({ date, version, changes }, null, 2))
24
- // Write the latest metadata XML to `PhoneNumberMetadata.xml` file.
25
- fs.writeFileSync(metadataFileOutputPath, xml)
26
- }).catch((error) => {
27
- console.error(error)
28
- process.exit(1)
29
- })