libphonenumber-js 1.12.22 → 1.12.24

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 (73) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +18 -26
  3. package/build/format.js +46 -17
  4. package/build/format.js.map +1 -1
  5. package/build/legacy/PhoneNumberSearch.js +128 -0
  6. package/build/legacy/PhoneNumberSearch.js.map +1 -0
  7. package/build/legacy/findPhoneNumbers.test.js +4 -4
  8. package/build/legacy/findPhoneNumbers.test.js.map +1 -1
  9. package/build/legacy/findPhoneNumbersInitialImplementation.js +20 -127
  10. package/build/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  11. package/build/legacy/format.js +12 -13
  12. package/build/legacy/format.js.map +1 -1
  13. package/build/legacy/getNumberType.js +11 -12
  14. package/build/legacy/getNumberType.js.map +1 -1
  15. package/build/parseIncompletePhoneNumber.test.js +34 -0
  16. package/build/parseIncompletePhoneNumber.test.js.map +1 -1
  17. package/build-scripts/check-for-metadata-changes-and-create-pull-request.js +4 -3
  18. package/build-scripts/check-for-metadata-changes-and-release.js +10 -35
  19. package/build-scripts/check-for-uncommitted-files.js +10 -8
  20. package/build-scripts/helpers/commit.js +1 -2
  21. package/build-scripts/helpers/exec.js +3 -4
  22. package/build-scripts/helpers/getUncommittedChanges.js +3 -3
  23. package/build-scripts/helpers/sendEmail.js +62 -0
  24. package/build-scripts/helpers/{update-metadata-from-google-metadata.js → updateMetadataFromGoogleMetadata.js} +5 -9
  25. package/bundle/libphonenumber-js.min.js +1 -1
  26. package/bundle/libphonenumber-js.min.js.map +1 -1
  27. package/bundle/libphonenumber-max.js +1 -1
  28. package/bundle/libphonenumber-max.js.map +1 -1
  29. package/bundle/libphonenumber-min.js +1 -1
  30. package/bundle/libphonenumber-min.js.map +1 -1
  31. package/bundle/libphonenumber-mobile.js +1 -1
  32. package/bundle/libphonenumber-mobile.js.map +1 -1
  33. package/custom.js +1 -1
  34. package/es6/format.js +43 -17
  35. package/es6/format.js.map +1 -1
  36. package/es6/legacy/PhoneNumberSearch.js +126 -0
  37. package/es6/legacy/PhoneNumberSearch.js.map +1 -0
  38. package/es6/legacy/findPhoneNumbers.test.js +1 -1
  39. package/es6/legacy/findPhoneNumbers.test.js.map +1 -1
  40. package/es6/legacy/findPhoneNumbersInitialImplementation.js +15 -124
  41. package/es6/legacy/findPhoneNumbersInitialImplementation.js.map +1 -1
  42. package/es6/legacy/format.js +12 -13
  43. package/es6/legacy/format.js.map +1 -1
  44. package/es6/legacy/getNumberType.js +11 -12
  45. package/es6/legacy/getNumberType.js.map +1 -1
  46. package/es6/parseIncompletePhoneNumber.test.js +34 -0
  47. package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
  48. package/index.cjs +1 -1
  49. package/index.cjs.js +1 -1
  50. package/index.es6.exports/PhoneNumberSearch.js +1 -1
  51. package/index.js +1 -1
  52. package/max/metadata/metadata.max.json +1 -1
  53. package/max/metadata/metadata.max.json.js +1 -1
  54. package/metadata.full.json +1 -1
  55. package/metadata.full.json.js +1 -1
  56. package/metadata.max.json +1 -1
  57. package/metadata.max.json.js +1 -1
  58. package/metadata.min.json +1 -1
  59. package/metadata.min.json.js +1 -1
  60. package/metadata.mobile.json +1 -1
  61. package/metadata.mobile.json.js +1 -1
  62. package/min/metadata/metadata.min.json +1 -1
  63. package/min/metadata/metadata.min.json.js +1 -1
  64. package/mobile/metadata/metadata.mobile.json +1 -1
  65. package/mobile/metadata/metadata.mobile.json.js +1 -1
  66. package/package.json +1 -1
  67. package/source/format.js +42 -7
  68. package/source/legacy/PhoneNumberSearch.js +122 -0
  69. package/source/legacy/findPhoneNumbers.test.js +1 -1
  70. package/source/legacy/findPhoneNumbersInitialImplementation.js +24 -134
  71. package/source/legacy/format.js +12 -1
  72. package/source/legacy/getNumberType.js +11 -1
  73. package/source/parseIncompletePhoneNumber.test.js +34 -0
@@ -1,8 +1,7 @@
1
1
  import exec from './exec.js'
2
2
 
3
3
  // Commits the current changes files in the local git repository.
4
- export default function()
5
- {
4
+ export default function() {
6
5
  console.log()
7
6
  console.log('========================================')
8
7
  console.log('= Committing changes =')
@@ -1,7 +1,6 @@
1
- import child_process from 'child_process'
1
+ import { execSync } from 'child_process'
2
2
 
3
3
  // Executes a command.
4
- export default function exec(command)
5
- {
6
- return child_process.execSync(command).toString().trim()
4
+ export default function exec(command) {
5
+ return execSync(command).toString().trim()
7
6
  }
@@ -21,9 +21,9 @@ export default function getUncommittedChanges() {
21
21
 
22
22
  const uncommittedFiles = output.trim().split('\n').map((line) => {
23
23
  line = line.trim()
24
- const status = line[0]
25
- line = line.slice(2)
26
- const filename = line
24
+ const whitespaceIndex = line.indexOf(' ')
25
+ const status = line.slice(0, whitespaceIndex)
26
+ const filename = line.slice(whitespaceIndex + ' '.length)
27
27
  return { status, filename }
28
28
  })
29
29
 
@@ -0,0 +1,62 @@
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
+ }
@@ -5,12 +5,10 @@ import exec from './exec.js'
5
5
 
6
6
  // Checks if Google's metadata XML file has changes, and, if it has,
7
7
  // generates JSON metadata files from it, runs the tests and updates `CHANGELOG.md`.
8
- export default function(googleMetadataFilePath, metadataInfoFilePath)
9
- {
10
- let metadata_changed = exec(`git ls-files --modified ${googleMetadataFilePath}`)
8
+ export default function(googleMetadataFilePath, metadataInfoFilePath) {
9
+ let metadataChanged = exec(`git ls-files --modified ${googleMetadataFilePath}`)
11
10
 
12
- if (!metadata_changed)
13
- {
11
+ if (!metadataChanged) {
14
12
  console.log()
15
13
  console.log('========================================')
16
14
  console.log('= Metadata is up-to-date. Exiting. =')
@@ -40,8 +38,7 @@ export default function(googleMetadataFilePath, metadataInfoFilePath)
40
38
 
41
39
  let modified_files = exec('git ls-files --modified').split(/\s/)
42
40
 
43
- let unexpected_modified_files = modified_files.filter(function(file)
44
- {
41
+ let unexpected_modified_files = modified_files.filter((file) => {
45
42
  return file !== googleMetadataFilePath &&
46
43
  !/^metadata\.[a-z]+\.json$/.test(file) &&
47
44
  !/^examples\.[a-z]+\.json$/.test(file)
@@ -51,8 +48,7 @@ export default function(googleMetadataFilePath, metadataInfoFilePath)
51
48
  // because on Windows random files constantly got "modified"
52
49
  // without actually being modified.
53
50
  // (perhaps something related to line endings)
54
- if (false && unexpected_modified_files.length > 0)
55
- {
51
+ if (false && unexpected_modified_files.length > 0) {
56
52
  let error
57
53
 
58
54
  error += 'Only `' + googleMetadataFilePath + '`, `metadata.*.json` and `examples.*.json` files should be modified. Unexpected modified files:'