Skip to content

Commit

Permalink
fix markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
imdhemy committed Apr 15, 2024
1 parent 27aad8a commit 8d67684
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
68 changes: 34 additions & 34 deletions _posts/nodejs/2024-01-07-effective-nodejs-modules-part-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ of them to export modules as follows:
```js
// config.js
module.exports = {
app: {
name: 'Awesome App',
port: 3000,
}
app: {
name: 'Awesome App',
port: 3000,
}
}
```

Expand All @@ -71,10 +71,10 @@ Is the same as:
```js
// config.js
exports.foo = {
app: {
name: 'Awesome App',
port: 3000,
}
app: {
name: 'Awesome App',
port: 3000,
}
}
```

Expand All @@ -92,14 +92,14 @@ You can also use the `require` function to import a single module from a file th
```js
// config.js
module.exports = {
app: {
name: 'Awesome App',
port: 3000,
},
connection: {
host: 'localhost',
port: 27017,
}
app: {
name: 'Awesome App',
port: 3000,
},
connection: {
host: 'localhost',
port: 27017,
}
}
```

Expand All @@ -120,15 +120,15 @@ const config = require('./config')

let logger
if (config.app.env === 'test') {
logger = require('./silent-logger')
logger = require('./silent-logger')
} else {
logger = require('./logger')
logger = require('./logger')
}
```

### ESM: ECMAScript module system

<div class="tip">
<div class="tip" markdown="1">
<p>
If you want to use ESM modules, you need to set the "type" to module "module" in the package.json file. Or name your files with the ".mjs" extension.
</p>
Expand All @@ -137,9 +137,9 @@ If you want to use ESM modules, you need to set the "type" to module "module" in
```js
// package.json
{
"type"
"type"
:
"module"
"module"
}
```

Expand All @@ -150,7 +150,7 @@ ESM modules became available without any command-line flags.

ESM uses `export` to export modules and `import` to import modules.

<div class="tip">
<div class="tip" markdown="1">
<p>ESM uses `export` in the singular format not `exports` like CJS.</p>
</div>

Expand All @@ -159,7 +159,7 @@ The following example shows how to export a function:
```js
// sum.mjs
function sum(a, b) {
return a + b
return a + b
}

export {sum}
Expand All @@ -182,7 +182,7 @@ The following example shows how to export a default module:
```js
// sum.mjs
export default function sum(a, b) {
return a + b
return a + b
}
```

Expand All @@ -200,15 +200,15 @@ The following example shows a mixed export of a default module and other modules
```js
// calculator.mjs
export function sum(a, b) {
return a + b
return a + b
}

export function subtract(a, b) {
return a - b
return a - b
}

export default function calculate(input) {
// a magic function that takes a string input like "1 + 2" and returns the result
// a magic function that takes a string input like "1 + 2" and returns the result
}
```

Expand Down Expand Up @@ -267,7 +267,7 @@ console.log(calculate('1 + 2')) // 3

The ESM modules doesn't support conditionally importing modules. All the imports should be at the top of the file.

<div class="danger">
<div class="danger" markdown="1">
<p>The following code will throw a SyntaxError: </p>
</div>

Expand All @@ -278,14 +278,14 @@ import config from './config.mjs'

if (config.app.env === 'test') {
import
logger
from
'./silent-logger.mjs'
logger
from
'./silent-logger.mjs'
} else {
import
logger
from
'./logger.mjs'
logger
from
'./logger.mjs'
}
```

Expand Down
6 changes: 3 additions & 3 deletions _posts/nodejs/2024-03-25-esm-dynamic-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const defaultLanguage = 'en';
const language = process.argv[2] || defaultLanguage;

if (!languages.includes(language)) {
console.error(`Unsupported language: ${language}`);
process.exit(1);
console.error(`Unsupported language: ${language}`);
process.exit(1);
}

// Get advantage of top-level await
Expand All @@ -77,7 +77,7 @@ In the `main.js` we used the `import()` expression, commonly called dynamic impo
at runtime, and the module will be loaded asynchronously. The `await` keyword is used to wait for the module to be
loaded before continuing the execution.

<div class="tip">
<div class="tip" markdown="1">
Use dynamic import only when necessary. The static form is preferable for loading initial dependencies, and can benefit more readily from static analysis tools and tree shaking.
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ title: How to test Elasticsearch in PHP applications
date: 2021-09-09T00:00:00.130Z
categories: php
---
<div class="caution">

<div class="caution" markdown="1">
<p>
Starting from Elasticsearch 8.0, they introduced multiple breaking changes in the Elasticsearch client library.
This article is intended to v 7.x and lower. For v 8.0 you can use the <a href="https://github.
Expand Down Expand Up @@ -127,7 +128,7 @@ As simple as that 🚀

### How to add Integration Tests to Elasticsearch in PHP

<div class="info">
<div class="info" markdown="1">
Github actions, Bitbucket pipelines and other CI/CD tools could be used to start Elasticsearch to run integration tests.
The following example uses CircleCI, but it would be much better if you used the same tool you're using in your project
without depending on a third-party service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ should know before using voters.
In Symfony, permissions are always linked to a user object. If you need to secure parts of your application, you
need to create a user object that implements the `UserInterface`.

<div class="tip">
<div class="tip" markdown="1">

Permissions should be linked to a user object. Always stick to this rule, even if you have an external user system

Expand All @@ -33,7 +33,7 @@ the [Symfony security component](https://github.com/symfony/symfony/blob/923c4ef
helps you to make sure that your user object has all the necessary methods to work with Symfony's security system
regardless of how you load or create the user object, e.g., from a database, an API, or a Token.

<div class="tip">
<div class="tip" markdown="1">

The security user interface is the contract between your user object and Symfony's security system.

Expand All @@ -60,7 +60,7 @@ user. It doesn't matter how the roles are stored in the database or how they are
is that every role must start with the `ROLE_` prefix - otherwise, things won't work as expected. You will use these
roles to grant access to specific parts of your application.

<div class="tip">
<div class="tip" markdown="1">

All roles should start with the `ROLE_` prefix. This is a requirement of Symfony's security system.

Expand Down Expand Up @@ -101,7 +101,7 @@ security:
For role hierarchy to work, do not use `$user->getRoles()` manually, instead you should always depend on the
`isGranted()` or `denyAccessUnlessGranted()` methods provided by the `AuthorizationCheckerInterface`.

<div class="tip">
<div class="tip" markdown="1">

Let symfony does the heavy lifting for you. Always use the security methods to check for roles.

Expand Down Expand Up @@ -129,7 +129,7 @@ that a voter can make, like any other voting system:
Normally, only one voter will vote at any given time, and all the rest will `abstain`. However, if you want to
change this behavior, you need to know about the `decision_strategy` configuration.

<div class="tip">
<div class="tip" markdown="1">
It's always good to keep the default `decision_strategy` and design your voters accordingly. A resource oriented
voter should only vote on the resource it is designed for.
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ It's a good practice to write unit tests that document your business logic, and
That means you should write your tests against the `vote()` method not the `can*()` methods. The `can*()` methods
should be private methods, and you should not test them directly.

<div class="tip">
<div class="tip" markdown="1">

Always test the public interface of your classes. In this case, the public interface is the `vote()` method.

Expand Down Expand Up @@ -345,4 +345,3 @@ In this post, we have introduced a new way to write Symfony voters with less boi
`CanDoVoter` class is an abstract class that you can extend to write your voters. Improving the way we write voters
will make our codebase more maintainable and easier to read. I hope you find this post helpful, and I would love to
hear your feedback.

4 changes: 2 additions & 2 deletions _posts/testing/2022-08-13-what-is-a-unit-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ You should already know about test automation. Given a piece of code, you
can write another piece of code that verifies the behavior of the first. The
second piece of code is called a unit test.

<div class="tip">
<div class="tip" markdown="1">
<p>A unit test should verify a small piece of code in isolation quickly.</p>
</div>

Expand All @@ -37,7 +37,7 @@ A small piece of code could be a function, a class, a method, or whatever
you can call a unit. If your test suite's execution time is good enough to
you, it means tests are quick enough.

<div class="tip">
<div class="tip" markdown="1">
A <i>unit</i> in unit testing is a unit of behaviour, not a unit of
<i>code</i>. This behaviour can span across as many as several classes or as
a single method, but it should have a single entry point to trigger the behaviour.
Expand Down
4 changes: 2 additions & 2 deletions _posts/testing/2022-11-11-how-to-organize-your-unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Let's map this to programming. The DUT will be **SUT** (System under test). The
could be a dependency or an argument passed to the SUT. It can also be data in the database or a file in the file
system.

<div class=tip>
<div class=tip markdown="1">
The test fixture's state and behavior should not change during the test, the ramp remains a ramp, or at least the changes should be predictable and controllable.
</div>

Expand Down Expand Up @@ -100,7 +100,7 @@ should end by creating the SUT instance in the initial state.
As far as I know, all xUnit frameworks provide a `setup` method to do the preparations. Even though this is not the
place to put the `Given` section.

<div class=tip>
<div class=tip markdown="1">
The `setup` method is not the place to put the `Given` section. The `setup` method is for the preparations that are common to all test cases. The `Given` section is for the preparations that are specific to the test case.
</div>

Expand Down

0 comments on commit 8d67684

Please sign in to comment.