Skip to content

Instantly share code, notes, and snippets.

View djabif's full-sized avatar

Dayana Jabif djabif

View GitHub Profile
@djabif
djabif / slugify.pipe.ts
Last active July 18, 2025 09:54
Angular Pipe to transform a string into a slug
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'slugify'})
export class SlugifyPipe implements PipeTransform {
transform(input: string): string {
return input.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
@djabif
djabif / matching-passwords.validator.ts
Last active May 19, 2023 14:10
Angular Validator for Matching Passwords
import { FormControl, FormGroup } from '@angular/forms';
export class PasswordValidator {
// If our validation fails, we return an object with a key for the error name and a value of true.
// Otherwise, if the validation passes, we simply return null because there is no error.
static areNotEqual(formGroup: FormGroup) {
let firstControlValue: any;
let valid = true;
@djabif
djabif / home.service.ts
Last active March 20, 2023 13:46
Angular Components Challenge - service with dummy data
import { Injectable } from '@angular/core';
import { CardItem } from 'src/app/shared/card-helpers/card-item.model';
import { PostCardComponent } from 'src/app/shared/card-templates/post-card/post-card.component';
import { ProductCardComponent } from 'src/app/shared/card-templates/product-card/product-card.component';
import { QuoteCardComponent } from 'src/app/shared/card-templates/quote-card/quote-card.component';
@Injectable()
export class HomeService {
public getItems(): CardItem[] {
return [
@djabif
djabif / phone.validator.ts
Last active February 28, 2023 12:38
Angular Phone + Country Validator
//Complete example for Ionic Framework in: https://ionicthemes.com/tutorials/about/forms-and-validation-in-ionic
//Complete example for Angular in: https://angular-templates.io/tutorials/about/angular-forms-and-validations
import { AbstractControl, ValidatorFn } from '@angular/forms';
import * as libphonenumber from 'google-libphonenumber';
export class PhoneValidator {
// Inspired on: https://github.com/yuyang041060120/ng2-validation/blob/master/src/equal-to/validator.ts
static validCountryPhone = (countryControl: AbstractControl): ValidatorFn => {
@djabif
djabif / password.validator.ts
Last active February 28, 2023 12:38
Password Validator for ionic apps
import { FormControl, FormGroup } from '@angular/forms';
export class PasswordValidator {
static areEqual(formGroup: FormGroup) {
let val;
let valid = true;
for (let key in formGroup.controls) {
if (formGroup.controls.hasOwnProperty(key)) {
let control: FormControl = <FormControl>formGroup.controls[key];
@djabif
djabif / form.ts
Last active February 28, 2023 12:38
Ionic Password validator
import { PasswordValidator } from '../../validators/password.validator';
this.matching_passwords_group = new FormGroup({
password: new FormControl('', Validators.compose([
Validators.minLength(5),
Validators.required,
Validators.pattern('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$') //this is for the letters (both uppercase and lowercase) and numbers validation
])),
confirm_password: new FormControl('', Validators.required)
}, (formGroup: FormGroup) => {
return PasswordValidator.areEqual(formGroup);
@djabif
djabif / .gitignore
Last active January 12, 2023 13:04
gitignore
# Specifies intentionally untracked files to ignore when using Git
# http://git-scm.com/docs/gitignore
*~
*.sw[mnpcod]
*.log
*.tmp
*.tmp.*
log.txt
*.sublime-project
{
"controls": [
{
"name": "address1",
"label": "Address line 1:",
"value": "",
"type": "text"
},
{
"name": "address2",
{
"controls": [
{
"name": "firstName",
"label": "First name:",
"value": "",
"type": "text"
},
{
"name": "lastName",
<ng-container *ngFor="let control of jsonFormData?.controls">
<label class="block mt-6" for="{{ control.name }}">{{
control.label
}}</label>
<input
*ngIf="
[
'text',
'password',
'email',