{"id":17972362,"url":"https://github.com/mlezcano1985/json-mask-values","last_synced_at":"2026-04-13T18:02:42.928Z","repository":{"id":44718133,"uuid":"450536831","full_name":"mlezcano1985/json-mask-values","owner":"mlezcano1985","description":"Find keys into a JSON and mask its values.","archived":false,"fork":false,"pushed_at":"2022-01-28T19:36:54.000Z","size":113,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-14T11:23:14.969Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlezcano1985.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-21T15:10:13.000Z","updated_at":"2022-01-28T19:40:13.000Z","dependencies_parsed_at":"2022-08-31T16:11:25.424Z","dependency_job_id":null,"html_url":"https://github.com/mlezcano1985/json-mask-values","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/mlezcano1985/json-mask-values","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlezcano1985%2Fjson-mask-values","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlezcano1985%2Fjson-mask-values/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlezcano1985%2Fjson-mask-values/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlezcano1985%2Fjson-mask-values/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlezcano1985","download_url":"https://codeload.github.com/mlezcano1985/json-mask-values/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlezcano1985%2Fjson-mask-values/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31764317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T15:25:13.801Z","status":"ssl_error","status_checked_at":"2026-04-13T15:25:09.162Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-29T16:13:24.034Z","updated_at":"2026-04-13T18:02:42.911Z","avatar_url":"https://github.com/mlezcano1985.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON-MASK-VALUES\n\n![GitHub Workflow Status](https://github.com/mlezcano1985/json-mask-values/actions/workflows/npm-publish.yml/badge.svg)\n![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/mlezcano1985/json-mask-values?include_prereleases)\n![npm](https://img.shields.io/npm/v/@mlezcano1985/json-mask-values)\n![GitHub](https://img.shields.io/github/license/mlezcano1985/json-mask-values)\n\nFind keys into a JSON and mask its values.\n\n:white_check_mark: JS and TS compatibility.\n\n## How to mask values inside a JSON?\n\nYou need to create a dictionary where the key is the name of the key in the json and the value is the function that is going to mask the value in the JSON. This function receives as a parameter the value of the JSON key to mask.\n\nThe functions to mask json values is called _plugins_. This tools has two plugins:\n\n- portion: Masks a section of the string. You must specify how many characters you want to leave visible. If the value is positive it will be to the left and if it is negative it will be to the right.\n- ends: Masks the center of the string. You must specify how many characters you want to leave visible on the right and on the left.\n- date: Masks a date string.\n- email: Masks an email address.\n\nAll plugins use the default character `*` to mask the string. But you can use whatever you want. See [How to use it?](#how-to-use-it) section.\n\nYou may use custom functions to mask a string.\n\n## How to install?\n\n```sh\nnpm i -P @mlezcano1985/json-mask-values\n```\n\n## How to use it?\n\n```ts\nimport {\n  ends,\n  maskJSON,\n  MaskKeyFn,\n  portion,\n  date,\n  email,\n} from '@mlezcano1985/json-mask-values';\n\n// Original JSON\nconst json = {\n  person: {\n    dni: '123456789',\n    address: {\n      street: 'This is a fake address',\n      streetNumber: '50',\n    },\n    birthdate: '1990-09-10',\n    email: 'test@email.com',\n  },\n  cardNumber: '1234567890',\n  expireIn: '1/3/2024',\n};\n\n// Dictionary of keys to mask\nconst keys: MaskKeyFn = {\n  dni: (value: string) =\u003e ends(value, 2, 2, '#'), // Mask the dni value in the JSON. The value parameter is \"123456789\". The character # is used to mask the string. Leave visible the 2 first and 2 last characters.\n  street: (value: string) =\u003e portion(value, 7), // Mask the street value in the JSON. The value parameter is \"This is a fake address\". Leave visible the first 7 characters\n  cardNumber: (value: string) =\u003e portion(value, -4), // Mask the cardNumber value in the JSON. The value parameter is \"1234567890\". Leave visible the last 4 characters.\n  birthdate: (value: string) =\u003e date(value),\n  expireIn: (value: string) =\u003e date(value, '#'),\n  email: (value: string) =\u003e email(value),\n};\n\nconst result = maskJSON(json, keys);\nconsole.log(result.toJSON\u003cRecord\u003cstring, unknown\u003e\u003e()); // Export result as JSON\nconsole.log(result.toString()); // Export result as json string\n```\n\nOutput JSON:\n\n```json\n{\n  \"person\": {\n    \"dni\": \"12#####89\",\n    \"address\": {\n      \"street\": \"This is***************\",\n      \"streetNumber\": \"50\"\n    },\n    \"birthdate\": \"***0-*9-*0\",\n    \"email\": \"te**@e****.c**\"\n  },\n  \"cardNumber\": \"******7890\",\n  \"expireIn\": \"1/3/###4\"\n}\n```\n\nOutput String:\n\n```\n{\"person\":{\"dni\":\"12#####89\",\"address\":{\"street\":\"This is***************\",\"streetNumber\":\"50\"},\"birthdate\":\"***0-*9-*0\",\"email\":\"te**@e****.c**\"},\"cardNumber\":\"******7890\",\"expireIn\":\"1/3/###4\"}\n```\n\n## Feedbacks\n\nSomething to report? let me know here :point_right: [Twitter](https://twitter.com/mlezcano1985).\n\nIf you believe you have found an issue, please report it using the [GitHub issue tracker](https://github.com/mlezcano1985/rut/issues), or better yet, create a PR with the changes.\n\nIf you're using this package, I'd love to hear your thoughts. Thanks!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlezcano1985%2Fjson-mask-values","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlezcano1985%2Fjson-mask-values","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlezcano1985%2Fjson-mask-values/lists"}