-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
<div> | ||
<textarea [(ngModel)]="html" [controlValueTransformer]="'html-to-markdown'"></textarea> | ||
<textarea [(ngModel)]="html" [controlValueTransformer]="'html-to-markdown'" [rewriteValueOnChange]="false"></textarea> | ||
<div [innerHTML]="html"></div> | ||
</div> | ||
<br /> | ||
<br /> | ||
<div> | ||
<input [(ngModel)]="password" [controlValueTransformer]="'emoji-password'" [rewriteValueOnChange]="true" /> | ||
<input [(ngModel)]="password" [controlValueTransformer]="'emoji-password'" /> | ||
<div>{{ password }}</div> | ||
</div> | ||
<br /> | ||
<br /> | ||
<div> | ||
<input [(ngModel)]="url" [controlValueTransformer]="httpsPrefixTransformer" /> | ||
<div>{{ url }}</div> | ||
</div> | ||
<br /> | ||
<br /> | ||
<div> | ||
<input [(ngModel)]="number" [controlValueTransformer]="'number'" /> | ||
<div>{{ number }}</div> | ||
</div> |
This file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Injectable, Inject, LOCALE_ID } from '@angular/core'; | ||
import { DecimalPipe } from '@angular/common'; | ||
import { ControlValueTransformer, Transformer } from '@ngze/control-value-transformer'; | ||
|
||
@Injectable() | ||
@ControlValueTransformer({ | ||
name: 'number', | ||
}) | ||
export class NumberTransformer implements Transformer<number, string> { | ||
private readonly decimalPipe = new DecimalPipe(this.localeId); | ||
|
||
constructor(@Inject(LOCALE_ID) private readonly localeId: string) {} | ||
|
||
toTarget(number: number): string { | ||
return this.decimalPipe.transform(number); | ||
} | ||
|
||
toSource(string: string): number { | ||
return Number(string.replace(/[^0-9 ]/g, '')); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,33 @@ | ||
import { Inject, Injectable, InjectionToken } from '@angular/core'; | ||
import { ControlValueTransformer, Transformer } from '@ngze/control-value-transformer'; | ||
|
||
export const EMOJIS = new InjectionToken<string[]>('EMOJIS', { | ||
providedIn: 'root', | ||
factory: () => ['🤫', '🤐', '😷', '😑', '😶', '🤭'], | ||
}); | ||
|
||
@Injectable() | ||
@ControlValueTransformer({ | ||
name: 'emoji-password', | ||
}) | ||
export class PasswordToEmojiTransformer implements Transformer<string, string> { | ||
private readonly emojis = ['🤫', '🤐', '😷', '😑', '😶', '🤭']; | ||
currentPassword: string; | ||
|
||
constructor(@Inject(EMOJIS) private readonly emojis: string[]) {} | ||
|
||
toTarget(password: string): string { | ||
this.currentPassword = password; | ||
return Array.from(password || '') | ||
.map((char, index) => this.emojis[index % this.emojis.length]) | ||
.join(''); | ||
} | ||
|
||
toSource(emojiPassword: string, currentSourcePassword: string): string { | ||
if (!emojiPassword || !currentSourcePassword) { | ||
toSource(emojiPassword: string): string { | ||
if (!emojiPassword || !this.currentPassword) { | ||
return emojiPassword; | ||
} | ||
|
||
const { 0: characters, index } = emojiPassword.match(/[^\u00FF-\uFFFF]+/); | ||
return currentSourcePassword.substring(0, index) + characters + currentSourcePassword.substring(index); | ||
return this.currentPassword.substring(0, index) + characters + this.currentPassword.substring(index); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Transformer } from '@ngze/control-value-transformer'; | ||
|
||
export class PrefixTransformer implements Transformer<string, string> { | ||
constructor(private readonly prefix: string) {} | ||
|
||
toTarget(text: string): string { | ||
return text ? this.prefix.concat(text) : text; | ||
} | ||
|
||
toSource(text: string): string { | ||
return text ? text.replace(this.prefix, '') : text; | ||
} | ||
} |