Skip to content

Commit

Permalink
ci: add formatting check
Browse files Browse the repository at this point in the history
  • Loading branch information
stas-nc committed Oct 2, 2024
1 parent 5560fb8 commit a74b1c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ on:
- "**"

jobs:
common_checks:
name: Common checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.8.0
cache: 'npm'
cache-dependency-path: '**/package-lock.json'

- name: Install dependencies
run: npm ci

- name: Check formatting
run: npm run format:check
build_ilc:
name: Build ILC
runs-on: ubuntu-latest
Expand Down
43 changes: 14 additions & 29 deletions ilc/common/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const errorExtender = require('@namecheap/error-extender');
const deepmerge = require('deepmerge');
import errorExtender from '@namecheap/error-extender';
import deepmerge from 'deepmerge';

function appIdToNameAndSlot(appId) {
export function appIdToNameAndSlot(appId) {
const [appNameWithoutPrefix, slotName] = appId.split('__at__');

// Case for shared libraries
Expand All @@ -18,24 +18,24 @@ function appIdToNameAndSlot(appId) {
};
}

function makeAppId(appName, slotName) {
export function makeAppId(appName, slotName) {
return `${appName.replace('@portal/', '')}__at__${slotName}`;
}

function cloneDeep(source) {
export function cloneDeep(source) {
return deepmerge({}, source);
}

const uniqueArray = (array) => [...new Set(array)];
export const uniqueArray = (array) => [...new Set(array)];

const encodeHtmlEntities = (value) => value.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
const decodeHtmlEntities = (value) =>
export const encodeHtmlEntities = (value) => value.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
export const decodeHtmlEntities = (value) =>
value
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"');

const removeQueryParams = (url) => {
export const removeQueryParams = (url) => {
const index = url.indexOf('?');
if (index !== -1) {
return url.substring(0, index);
Expand All @@ -44,15 +44,15 @@ const removeQueryParams = (url) => {
}
};

const addTrailingSlash = (url) => {
export const addTrailingSlash = (url) => {
if (url.endsWith('/')) {
return url;
}

return `${url}/`;
};

function addTrailingSlashToPath(url) {
export function addTrailingSlashToPath(url) {
const isFullUrl = url.includes('://');
const parsedUrl = isFullUrl ? new URL(url) : new URL(`https://example.com/${url}`);
const hasTrailingSlash = parsedUrl.pathname.endsWith('/');
Expand All @@ -61,14 +61,14 @@ function addTrailingSlashToPath(url) {
return isFullUrl ? parsedUrl.toString() : parsedUrl.pathname.slice(1);
}

class TimeoutError extends Error {}
export class TimeoutError extends Error {}

/**
*
* @param {Promise}
* @param {number} timeout
*/
async function withTimeout(promise, ms, message = 'Promise timeout') {
export async function withTimeout(promise, ms, message = 'Promise timeout') {
let timeoutId;
const timeoutPromise = new Promise((resolve, reject) => {
timeoutId = setTimeout(() => reject(new TimeoutError(message)), ms);
Expand All @@ -77,21 +77,6 @@ async function withTimeout(promise, ms, message = 'Promise timeout') {
return Promise.race([decoratedPromise, timeoutPromise]);
}

function extendError(name, options = {}) {
export function extendError(name, options = {}) {
return errorExtender(name, { ...options, inverse: true });
}

module.exports = {
appIdToNameAndSlot,
makeAppId,
cloneDeep,
uniqueArray,
encodeHtmlEntities,
decodeHtmlEntities,
removeQueryParams,
addTrailingSlash,
addTrailingSlashToPath,
withTimeout,
TimeoutError,
extendError,
};

0 comments on commit a74b1c6

Please sign in to comment.