You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

babel-plugin-react-intl-auto

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-react-intl-auto - npm Package Compare versions

Comparing version

to
3.1.0

4

lib/__tests__/components.test.js

@@ -82,3 +82,3 @@ "use strict";

`,
error: /\[React Intl Auto\] defaultMessage must be statically evaluate\x2Dable for extraction/u,
error: /\[React Intl Auto\] defaultMessage must be statically evaluate-able for extraction/u,
snapshot: false

@@ -183,3 +183,3 @@ };

pluginOptions: {
removePrefix: /[\/\\]__fixtures__/u
removePrefix: /[\\/]__fixtures__/u
}

@@ -186,0 +186,0 @@ }, {

@@ -88,3 +88,3 @@ "use strict";

`,
error: /\[React Intl Auto\] defaultMessage must be statically evaluate\x2Dable for extraction/u,
error: /\[React Intl Auto\] defaultMessage must be statically evaluate-able for extraction/u,
snapshot: false

@@ -170,3 +170,3 @@ };

pluginOptions: {
removePrefix: /[\/\\]__fixtures__/u
removePrefix: /[\\/]__fixtures__/u
}

@@ -173,0 +173,0 @@ }, {

@@ -281,3 +281,3 @@ "use strict";

pluginOptions: {
removePrefix: /src[\/\\]__f[\0-\t\x0B\f\x0E-\u2027\u202A-\u{10FFFF}]+?_/u,
removePrefix: /src[\\/]__f.+?_/u,
includeExportName: true

@@ -304,2 +304,21 @@ }

}
}, {
title: 'separator = ""',
tests: [defaultTest, multiExportTest],
pluginOptions: {
separator: ''
}
}, {
title: 'separator = "_"',
// tests: [defaultTest, multiExportTest],
tests: [defaultTest, multiExportTest],
pluginOptions: {
separator: '_'
}
}, {
title: 'separator = "foo"',
tests: [defaultTest, multiExportTest],
pluginOptions: {
separator: 'foo'
}
}]);

@@ -88,3 +88,3 @@ "use strict";

`,
error: /\[React Intl Auto\] defaultMessage must be statically evaluate\x2Dable for extraction/u,
error: /\[React Intl Auto\] defaultMessage must be statically evaluate-able for extraction/u,
snapshot: false

@@ -170,3 +170,3 @@ };

pluginOptions: {
removePrefix: /[\/\\]__fixtures__/u
removePrefix: /[\\/]__fixtures__/u
}

@@ -173,0 +173,0 @@ }, {

@@ -12,2 +12,20 @@ "use strict";

const escapeRegExp = text => {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/gu, '\\$&');
};
const dotPathReplace = (fomatted, removePrefix, separator) => {
const exp = `^${removePrefix.replace(/\//gu, '')}\\${(0, _.dotPath)(_path.sep, separator)}?`;
let reg; // certain separators can throw an error and need to be escaped
// e.g. "_"
try {
reg = new RegExp(exp, 'u');
} catch (error) {
reg = new RegExp(escapeRegExp(exp), 'u');
}
return (0, _.dotPath)(fomatted, separator).replace(reg, '');
};
const getPrefix = ({

@@ -21,3 +39,4 @@ file: {

removePrefix,
filebase = false
filebase = false,
separator
}

@@ -30,5 +49,5 @@ }, exportName) => {

const file = (0, _path.relative)(process.cwd(), filename);
const fomatted = filebase ? file.replace(/\.[\0-\t\x0B\f\x0E-\u2027\u202A-\u{10FFFF}]+$/u, '') : (0, _path.dirname)(file);
const fomatted = filebase ? file.replace(/\..+$/u, '') : (0, _path.dirname)(file);
removePrefix = removePrefix === undefined || removePrefix === false ? '' : removePrefix;
const fixed = removePrefix instanceof RegExp ? (0, _.dotPath)(fomatted.replace(removePrefix, '')) : (0, _.dotPath)(fomatted).replace(new RegExp(`^${removePrefix.replace(/\//gu, '')}\\${(0, _.dotPath)(_path.sep)}?`, 'u'), '');
const fixed = removePrefix instanceof RegExp ? (0, _.dotPath)(fomatted.replace(removePrefix, ''), separator) : dotPathReplace(fomatted, removePrefix, separator);

@@ -35,0 +54,0 @@ if (exportName === null) {

@@ -29,3 +29,3 @@ "use strict";

const dotPath = str => str.replace(REG, '.');
const dotPath = (str, separator = '.') => str.replace(REG, separator);

@@ -32,0 +32,0 @@ exports.dotPath = dotPath;

@@ -22,3 +22,3 @@ "use strict";

const getId = (path, prefix) => {
const getId = (path, prefix, separator) => {
let name;

@@ -36,3 +36,3 @@

return (0, _utils.dotPath)((0, _path.join)(prefix, name));
return (0, _utils.dotPath)((0, _path.join)(prefix, name), separator);
};

@@ -48,2 +48,7 @@

const prefix = (0, _getPrefix.getPrefix)(state, exportName);
const {
opts: {
separator
}
} = state;

@@ -69,3 +74,3 @@ for (const prop of properties) {

if (isNotHaveId) {
const id = getId(objectKeyPath, prefix);
const id = getId(objectKeyPath, prefix, separator);
messageDescriptorProperties.push((0, _utils.objectProperty)('id', id));

@@ -77,3 +82,3 @@ }

// 'hello' or `hello ${user}`
const id = getId(objectKeyPath, prefix);
const id = getId(objectKeyPath, prefix, separator);
messageDescriptorProperties.push((0, _utils.objectProperty)('id', id), (0, _utils.objectProperty)('defaultMessage', objectValuePath.node));

@@ -84,3 +89,3 @@ } else {

if (evaluated.confident && typeof evaluated.value === 'string') {
const id = (0, _utils.dotPath)((0, _path.join)(prefix, evaluated.value));
const id = (0, _utils.dotPath)((0, _path.join)(prefix, evaluated.value), separator);
messageDescriptorProperties.push((0, _utils.objectProperty)('id', id), (0, _utils.objectProperty)('defaultMessage', evaluated.value));

@@ -87,0 +92,0 @@ }

{
"name": "babel-plugin-react-intl-auto",
"version": "3.0.1",
"version": "3.1.0",
"main": "lib/index.js",

@@ -65,11 +65,11 @@ "types": "types.d.ts",

"@akameco/tsconfig": "0.3.0",
"@babel/cli": "7.6.4",
"@babel/preset-env": "7.6.3",
"@babel/preset-typescript": "7.6.0",
"@babel/register": "7.6.2",
"@babel/cli": "7.7.0",
"@babel/preset-env": "7.7.1",
"@babel/preset-typescript": "7.7.2",
"@babel/register": "7.7.0",
"@types/babel__core": "7.1.3",
"@types/babel__traverse": "7.0.7",
"@types/jest": "24.0.20",
"@types/jest": "24.0.23",
"@types/murmurhash3js": "3.0.2",
"all-contributors-cli": "6.9.3",
"all-contributors-cli": "6.11.0",
"babel-core": "7.0.0-bridge.0",

@@ -79,3 +79,3 @@ "babel-eslint": "10.0.3",

"babel-log": "2.0.0",
"babel-plugin-tester": "7.0.1",
"babel-plugin-tester": "7.0.4",
"coveralls": "3.0.7",

@@ -86,7 +86,7 @@ "eslint": "6.6.0",

"jest": "24.9.0",
"lint-staged": "9.4.2",
"prettier": "1.18.2",
"react-intl": "3.4.0",
"lint-staged": "9.4.3",
"prettier": "1.19.1",
"react-intl": "3.6.0",
"string-snapshot-serializer": "1.0.1",
"typescript": "3.6.4"
"typescript": "3.7.2"
},

@@ -93,0 +93,0 @@ "husky": {

@@ -355,2 +355,28 @@ # babel-plugin-react-intl-auto

#### separator
Allows you to specify a custom separator
Type: `string` <br>
Default: `.`
##### Example
when `separator` is `"_"`
```js
export const test = defineMessages({
hello: 'hello {name}',
})
↓ ↓ ↓ ↓ ↓ ↓
export const test = defineMessages({
hello: {
id: 'path_to_file_test_hello',
defaultMessage: 'hello {name}',
},
})
```
### Support variable

@@ -463,2 +489,3 @@

<td align="center"><a href="https://github.com/Filson14"><img src="https://avatars1.githubusercontent.com/u/4540538?v=4" width="100px;" alt="Filip "Filson" Pasternak"/><br /><sub><b>Filip "Filson" Pasternak</b></sub></a><br /><a href="https://github.com/akameco/babel-plugin-react-intl-auto/commits?author=Filson14" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/ericmasiello"><img src="https://avatars3.githubusercontent.com/u/3525886?v=4" width="100px;" alt="Eric Masiello"/><br /><sub><b>Eric Masiello</b></sub></a><br /><a href="https://github.com/akameco/babel-plugin-react-intl-auto/commits?author=ericmasiello" title="Code">💻</a> <a href="https://github.com/akameco/babel-plugin-react-intl-auto/commits?author=ericmasiello" title="Tests">⚠️</a></td>
</tr>

@@ -465,0 +492,0 @@ </table>