-
-
Notifications
You must be signed in to change notification settings - Fork 17
Add Transforms #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
agilgur5
wants to merge
9
commits into
main
Choose a base branch
from
transforms
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Transforms #16
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8bba87c
(feat): simple version of transforms
agilgur5 a4d8f16
(refactor): whitelist and blacklist as transforms
agilgur5 c12fd90
(optim): return early if white|blacklist doesn't exist
agilgur5 86099a1
(docs): transforms usage & example, ordering & visual
agilgur5 ac1bbf3
(docs): README is not longer than the source anymore :'(
agilgur5 6b51a29
(refactor): w/blist transform args shouldn't be optional
agilgur5 8417f22
(test): ensure transforms apply and do so in correct order
agilgur5 7998213
(docs): add link to fixtures as another transform example
agilgur5 a117d91
(docs): add an example of building a custom transform
agilgur5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ITransform, arrToDict } from './utils' | ||
|
||
export function blacklistKeys (blacklist: Array<string>): ITransform { | ||
const blacklistDict = arrToDict(blacklist) | ||
|
||
return {toStorage: function blacklistTransform (snapshot) { | ||
Object.keys(snapshot).forEach((key) => { | ||
if (blacklistDict[key]) { delete snapshot[key] } | ||
}) | ||
return snapshot | ||
}} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { ITransform, ITransformArgs } from './utils' | ||
|
||
export { whitelistKeys } from './whitelist' | ||
export { blacklistKeys } from './blacklist' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { StrToAnyMap } from '../utils' | ||
|
||
export interface ITransform { | ||
readonly toStorage?: ITransformArgs, | ||
readonly fromStorage?: ITransformArgs | ||
} | ||
export interface ITransformArgs { | ||
(snapshot: StrToAnyMap): StrToAnyMap | ||
} | ||
|
||
type StrToBoolMap = {[key: string]: boolean} | ||
|
||
export function arrToDict (arr: Array<string>): StrToBoolMap { | ||
return arr.reduce((dict: StrToBoolMap, elem) => { | ||
dict[elem] = true | ||
return dict | ||
}, {}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ITransform, arrToDict } from './utils' | ||
|
||
export function whitelistKeys (whitelist: Array<string>): ITransform { | ||
const whitelistDict = arrToDict(whitelist) | ||
|
||
return {toStorage: function whitelistTransform (snapshot) { | ||
Object.keys(snapshot).forEach((key) => { | ||
if (!whitelistDict[key]) { delete snapshot[key] } | ||
}) | ||
return snapshot | ||
}} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type StrToAnyMap = {[key: string]: any} |
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 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.