Skip to content

Commit

Permalink
♻️ refactor: rename json transformers to apply various transformation…
Browse files Browse the repository at this point in the history
…s to JSON data #2
  • Loading branch information
pnguyen215 committed Dec 22, 2024
1 parent 38d65a2 commit d12cb1e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package fj
// If set to false, modifiers will be applied as expected.
var DisableModifiers = false

// modifiers is a map that associates a string key (the modifier type) with a function that
// jsonTransformers is a map that associates a string key (the modifier type) with a function that
// takes two string arguments (`json` and `arg`), and returns a modified string. The map is used
// to apply various transformations to JSON data based on the specified modifiers.
var modifiers map[string]func(json, arg string) string
// to apply various transformations to JSON data based on the specified jsonTransformers.
var jsonTransformers map[string]func(json, arg string) string

// hexDigits is an array of bytes representing the hexadecimal digits used in JSON encoding.
// It contains the characters '0' to '9' and 'a' to 'f', which are used for encoding hexadecimal numbers.
Expand Down
8 changes: 4 additions & 4 deletions fj.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ func IsValidJSONBytes(json []byte) bool {
// - Once registered, the modifier can be used in fj queries to transform the JSON data
// according to the logic defined in the `fn` function.
func AddModifier(name string, fn func(json, arg string) string) {
modifiers[name] = fn
jsonTransformers[name] = fn
}

// IsModifierRegistered checks whether a specified modifier has been registered in the fj system.
Expand Down Expand Up @@ -577,10 +577,10 @@ func IsModifierRegistered(name string) bool {
if unify4g.IsEmpty(name) {
return false
}
if len(modifiers) == 0 {
if len(jsonTransformers) == 0 {
return false
}
_, ok := modifiers[name]
_, ok := jsonTransformers[name]
return ok
}

Expand Down Expand Up @@ -1621,7 +1621,7 @@ func (t Type) String() string {
}

func init() {
modifiers = map[string]func(json, arg string) string{
jsonTransformers = map[string]func(json, arg string) string{
"pretty": applyPretty,
"ugly": modUgly,
"reverse": modReverse,
Expand Down
4 changes: 2 additions & 2 deletions h.go
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@ func isModifierOrJSONStart(s string) bool {
break
}
}
_, ok := modifiers[s[1:i]]
_, ok := jsonTransformers[s[1:i]]
return ok
}
return c == '[' || c == '{'
Expand Down Expand Up @@ -3518,7 +3518,7 @@ func adjustModifier(json, path string) (pathYield, result string, ok bool) {
}
}
// check if the modifier exists in the modifiers map and apply it if found.
if fn, ok := modifiers[name]; ok {
if fn, ok := jsonTransformers[name]; ok {
var args string
if hasArgs { // if arguments are found, parse and handle them.
var parsedArgs bool
Expand Down

0 comments on commit d12cb1e

Please sign in to comment.