Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

The model does not match property keys with the dynamic name. #15

Closed
brunos3d opened this issue Nov 17, 2020 · 4 comments
Closed

The model does not match property keys with the dynamic name. #15

brunos3d opened this issue Nov 17, 2020 · 4 comments

Comments

@brunos3d
Copy link

Hi. 馃槉
I'm using pupa in a discord bot in a multi-language system. 馃

The files containing the translations are made up of objects with properties whose keys contain names with special characters such as spaces and -.

However, the formatter does not find these properties. I added a simple code below simulating the environment. 馃槄

var pupa = require("pupa")

const args = {
   "commonName": {
      test: 1
   },
   "dynamic-key-name": {
      test: 2
   },
   "dynamic key name": {
      test: 2
   }
}

console.log(pupa("testing {commonName.test}", args))         //=> "testing 1"
console.log(pupa("testing {dynamic-key-name.test}", args))   //=> "testing {dynamic-key-name.test}"
console.log(pupa("testing {dynamic key name.test}", args))   //=> "testing {dynamic key name.test}"
@brunos3d brunos3d changed the title Template not matches property keys with dynamic name Template not matches property keys with dynamic name. Nov 17, 2020
@brunos3d brunos3d changed the title Template not matches property keys with dynamic name. The model does not match property keys with the dynamic name. Nov 17, 2020
@mukaschultze
Copy link

Maybe the package should interpret keys enclosed by quotes as literal strings? For example pupa("testing {'dynamic key name'.test}", args) should work, as strings are also valid JS keys.

@brunos3d
Copy link
Author

I also thought that this could work. But it did not work.

@brunos3d
Copy link
Author

These tests were done using RunKit

image

@brunos3d
Copy link
Author

I believe that another good solution would be to implement the object-path package to solve this problem.

These tests were done using RunKit

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants