@dpgradio/creative 5.9.0 → 5.9.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dpgradio/creative",
|
|
3
|
-
"version": "5.9.
|
|
3
|
+
"version": "5.9.1",
|
|
4
4
|
"description": "Support package for standalone Javascript applications",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"sockjs-client": "^1.6.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
+
"@babel/preset-env": "^7.22.9",
|
|
31
32
|
"@dpgradio/eslint-config-recommended": "^0.0.1",
|
|
32
33
|
"eslint": "^8.32.0",
|
|
33
34
|
"eslint-plugin-import": "^2.27.5",
|
|
@@ -2,7 +2,7 @@ import { describe, expect, test, jest } from '@jest/globals'
|
|
|
2
2
|
import hybrid from '../../app/hybrid.js'
|
|
3
3
|
import openLink from '../../utils/openLink.js'
|
|
4
4
|
|
|
5
|
-
jest.mock('../../
|
|
5
|
+
jest.mock('../../app/hybrid.js', () => ({
|
|
6
6
|
isNativeApp: jest.fn(),
|
|
7
7
|
call: jest.fn(),
|
|
8
8
|
}))
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, test, jest } from '@jest/globals'
|
|
2
|
+
import { removePhoneNumberCountryPrefix } from '../../index.js'
|
|
3
|
+
|
|
4
|
+
describe('removing explicitly given prefixes', () => {
|
|
5
|
+
test('it removes the country prefix when there is a match', () => {
|
|
6
|
+
const result = removePhoneNumberCountryPrefix('+31.634542211', '+31')
|
|
7
|
+
|
|
8
|
+
expect(result).toBe('0634542211')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('it does not remove the country prefix when there is no match, but it does remove the .', () => {
|
|
12
|
+
const result = removePhoneNumberCountryPrefix('+33.634542211', '+31')
|
|
13
|
+
|
|
14
|
+
expect(result).toBe('+33634542211')
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
jest.mock('../../config/config.js', () => ({
|
|
19
|
+
config: jest.fn(() => 'NL'),
|
|
20
|
+
}))
|
|
21
|
+
|
|
22
|
+
describe('removing prefixes provided by the config', () => {
|
|
23
|
+
test('it removes the country prefix when there is a match', () => {
|
|
24
|
+
const result = removePhoneNumberCountryPrefix('+31.634542211')
|
|
25
|
+
|
|
26
|
+
expect(result).toBe('0634542211')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('it does not remove the country prefix when there is no match, but it does remove the .', () => {
|
|
30
|
+
const result = removePhoneNumberCountryPrefix('+32.634542211')
|
|
31
|
+
|
|
32
|
+
expect(result).toBe('+32634542211')
|
|
33
|
+
})
|
|
34
|
+
})
|
package/src/index.js
CHANGED
|
@@ -13,3 +13,4 @@ export { default as loadScript } from './utils/loadScript.js'
|
|
|
13
13
|
export { default as openLink } from './utils/openLink.js'
|
|
14
14
|
export { default as tap } from './utils/tap.js'
|
|
15
15
|
export { cdnImageUrl, cdnUrl } from './utils/cdnUrl.js'
|
|
16
|
+
export { removePhoneNumberCountryPrefix } from './utils/phoneNumber.js'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { config } from '../config/config.js'
|
|
2
|
+
|
|
3
|
+
const prefixes = {
|
|
4
|
+
BE: '+32',
|
|
5
|
+
NL: '+31',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const removePhoneNumberCountryPrefix = (phoneNumber, prefix = null) => {
|
|
9
|
+
prefix ||= prefixes[config('country_code')]
|
|
10
|
+
|
|
11
|
+
if (prefix) {
|
|
12
|
+
phoneNumber = phoneNumber.replace(`${prefix}.`, '0')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return phoneNumber.replace('.', '')
|
|
16
|
+
}
|