Skip to content

Commit b84395e

Browse files
committedFeb 18, 2021
chore: update badges
1 parent 08c6d8f commit b84395e

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed
 

‎babel-plugin-optimize-obj-str/readme.md

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# babel-plugin-optimize-obj-str
1+
# babel-plugin-optimize-obj-str [![CI](https://github.com/lukeed/obj-str/workflows/CI/badge.svg)](https://github.com/lukeed/obj-str/actions) [![codecov](https://badgen.net/codecov/c/github/lukeed/obj-str)](https://codecov.io/gh/lukeed/obj-str)
22

33
> [Babel](https://babeljs.io/) plugin to optimize [`obj-str`](../) calls by replacing them with an equivalent unrolled expression.
44
55
Even though the `obj-str` function is negligible in size over-the-wire, the motivation for this plugin is that transformed expressions [execute almost twice as fast as equivalent calls.](#performance)
66

77
```js
88
import objstr from 'obj-str';
9+
910
objstr({
1011
'my-classname': true,
1112
'another-one': maybe,
@@ -27,6 +28,7 @@ npm install --save-dev babel-plugin-optimize-obj-str
2728
**Via babel.config.js** ([recommended](https://babeljs.io/docs/en/configuration)):
2829

2930
```js
31+
// babel.config.js
3032
module.exports = {
3133
plugins: ['optimize-obj-str'],
3234
};
@@ -41,25 +43,22 @@ babel --plugins optimize-obj-str script.js
4143
## Options
4244

4345
```js
46+
// babel.config.js
4447
module.exports = {
4548
plugins: [
46-
[
47-
'optimize-obj-str',
48-
{
49-
strict: false,
50-
},
51-
],
49+
['optimize-obj-str', {
50+
strict: false,
51+
}],
5252
],
5353
};
5454
```
5555

56-
### `strict`
56+
### options.strict
5757

58-
| type | default |
59-
| ------------- | ------- |
60-
| **`boolean`** | `false` |
58+
Type: `boolean` <br>
59+
Default: `false`
6160

62-
**Enable to fail when encountering calls that cannot be optimized.**
61+
Allow Babel to throw errors when encountering `obj-str` calls that cannot be optimized.
6362

6463
We can only optimize function calls whose single argument is an **object literal** containing only **keyed properties**.
6564

@@ -95,6 +94,7 @@ Instead, when setting the option **`{ strict: true }`** the plugin errors out to
9594
> 2 | objstr(cannotOptimizeIdentifierArg);
9695
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^</code></pre></blockquote>
9796
97+
9898
## Caveats
9999

100100
### Performance
@@ -105,10 +105,13 @@ You should not expect this transform should to reduce bundle size. Depending on
105105

106106
### Leading Space
107107

108-
Direct results from `objstr()` always omit a leading space. This is not the case when y using this transform:
108+
Direct results from `objstr()` always omit a leading space. This is not the case when using this transform:
109109

110110
```js
111-
objstr({ a: false, foo: true });
111+
objstr({
112+
a: false,
113+
foo: true
114+
});
112115

113116
// transformed:
114117
(' foo');
@@ -121,15 +124,17 @@ You must ensure that your expression consumers ignore this leading space. A [cla
121124
Object literals may contain duplicate property names, in which case [the lastly defined value is preserved.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Duplicate_property_names)
122125

123126
```js
124-
objstr({ dupe: one, dupe: two });
127+
objstr({
128+
dupe: one,
129+
dupe: two
130+
});
125131

126132
// Transformed:
127133
'' + (two ? 'dupe' : '');
128134
```
129135

130-
The example above is transformed properly since the duplicate property names are literal and constant. The plugin does its best to override duplicates by comparing property name expressions, but it's unable to compare equal computed results whose expressions vary.
136+
The example above is transformed properly since the duplicate property names are literal and constant. The plugin does its best to override duplicates by comparing property name expressions, but it's unable to compare equal computed results whose expressions vary:
131137

132-
<!-- prettier-ignore -->
133138
```js
134139
objstr({
135140
good: one,

‎readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# obj-str [![Build Status](https://travis-ci.org/lukeed/obj-str.svg?branch=master)](https://travis-ci.org/lukeed/obj-str)
1+
# obj-str [![CI](https://github.com/lukeed/obj-str/workflows/CI/badge.svg)](https://github.com/lukeed/obj-str/actions) [![codecov](https://badgen.net/codecov/c/github/lukeed/obj-str)](https://codecov.io/gh/lukeed/obj-str)
22

33
> A tiny (96B) library for serializing Object values to Strings.
44
@@ -31,7 +31,7 @@ import React from 'react';
3131
import objstr from 'obj-str';
3232

3333
const TodoItem = ({ text, isDone, disabled }) => (
34-
<li className={ objstr({ item:true, completed:isDone, disabled }) }>
34+
<li className={ objstr({ item:true, completed:isDone, disabled }) }>
3535
<input type="checkbox" disabled={ disabled } checked={ isDone } />
3636
<label>{ text }</label>
3737
</li>

0 commit comments

Comments
 (0)
Please sign in to comment.