Skip to content

Instantly share code, notes, and snippets.

View mahdikhashan's full-sized avatar
🏸

Mahdi Khashan mahdikhashan

🏸
View GitHub Profile
@mahdikhashan
mahdikhashan / release.config.js
Created April 18, 2023 09:57 — forked from yyynnn/release.config.js
release.config.js
/* eslint-disable no-template-curly-in-string */
const gitlabUrl = 'https://gitlab.com'
const gitlabApiPathPrefix = '/api/v4'
const assets = [
{ path: 'index.js', label: 'JS distribution' }
]
const verifyConditions = [
['@semantic-release/changelog'],
@mahdikhashan
mahdikhashan / DateTimeFormatMock.js
Created March 28, 2023 12:15
Vitest Mock Timezone
it("should get the client timezone as a string", () => {
const DateTimeFormat = Intl.DateTimeFormat;
vi.spyOn(global.Intl, "DateTimeFormat").mockImplementation(
(locale, options) =>
new DateTimeFormat(locale, { ...options, timeZone: "Asia/Tehran" })
);
const date: MyDate = new MyDate("2023-03-28T11:06:48+00:00");
expect(date.getClientTZ()).toEqual("Asia/Tehran");
@mahdikhashan
mahdikhashan / mutableSource.tsx
Created March 21, 2023 00:05 — forked from Aslemammad/mutableSource.tsx
Consistent version of useMutableSource.
// Consistent version of `useMutableSource`, Inspired by https://github.com/pmndrs/valtio/blob/master/src/useMutableSource.ts
import { useEffect, useRef, useState } from 'react';
const TARGET = Symbol('target');
const GET_VERSION = Symbol('getVersion');
export type Source<TargetType extends any, VersionType extends any> = {
[TARGET]: TargetType;
[GET_VERSION]: (target: TargetType) => VersionType;
};