This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Address { | |
street: string; | |
area: string; | |
landmark: string; | |
pincode: number; | |
} | |
type previewAddress = Pick<Address, 'pincode' | 'area'>; | |
type previewAddress2 = Omit<Address, 'pincode'>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// monogodb | |
ITEMS_PER_PAGE = 2; | |
exports.getIndex = (req, res, next) => { | |
let page = req.query.page; | |
let totalItems; | |
Product.find() | |
.count() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// monogodb | |
ITEMS_PER_PAGE = 2; | |
exports.getIndex = (req, res, next) => { | |
let page = req.query.page; | |
Product.find() | |
.skip((page - 1) * ITEMS_PER_PAGE) | |
.limit(ITEMS_PER_PAGE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validators.pattern(/^(?=.*[a-zA-Z])[a-zA-Z\s]+(?:-[a-zA-Z\s]+)*[a-zA-Z]$/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.form.get('optionalField').valueChanges.subscribe(value => { | |
const control = this.form.get('optionalField'); | |
if (value && value.length > 0) { | |
// If user enters any character, add 'required' validator | |
control.setValidators([Validators.required]); | |
} else { | |
// Otherwise, no validator (optional) | |
control.clearValidators(); | |
} | |
control.updateValueAndValidity({emitEvent: false}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {readdir, cp} from 'node:fs/promises'; | |
import { fileURLToPath } from 'node:url'; | |
import { dirname, join } from 'node:path'; | |
const currentPath = dirname(fileURLToPath(import.meta.url)); | |
const currentDir = await readdir(currentPath + '/browser', {withFileTypes: true}); | |
const desitination = join(currentPath, 'server'); | |
const source = join(currentPath, 'browser', 'assets'); | |
await cp(source, desitination + '/assets', {recursive: true}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//App.js | |
import React from 'react'; | |
import './style.css'; | |
import { fetchUsers } from './custom_hook.js'; | |
export default function App() { | |
const { data, loading, error } = fetchUsers( | |
'https://jsonplaceholder.typicode.com/posts' | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const AuthGuard: CanActivateFn = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => { | |
const store = inject(Store); | |
return new Promise<boolean>(resolve => { | |
const sub = store.select(getAgeSelector).subscribe(res => { | |
if (res && res?.token && res?.token?.length) { | |
resolve(true); | |
} else { | |
window.open(environment.WHATEVER, '_SELF'); | |
resolve(false); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deepCopy(obj) { | |
if (typeof obj !== 'object' || obj === null) { | |
return obj; // Return primitive values and null as is | |
} | |
const copy = Array.isArray(obj) ? [] : {}; | |
for (let key in obj) { | |
copy[key] = deepCopy(obj[key]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.values(this.anyform.controls).filter(control => { | |
if (control.invalid) { | |
control.patchValue(control?.value?.length === 0 ? ' ' : control?.value); | |
control.markAsDirty(); | |
control.markAsTouched(); | |
control.setErrors({ incorrect: true }); | |
control.updateValueAndValidity(); | |
} | |
}); |
NewerOlder