{"id":20347373,"url":"https://github.com/prinorange/nullify-undefined","last_synced_at":"2025-07-29T23:05:03.415Z","repository":{"id":65498083,"uuid":"593464905","full_name":"PrinOrange/nullify-undefined","owner":"PrinOrange","description":"Convert undefined in the object to null to solve the problem of javascript object serialization in some scenarios","archived":false,"fork":false,"pushed_at":"2023-05-05T09:50:11.000Z","size":43,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-14T22:48:08.096Z","etag":null,"topics":["javascript","null","null-safety","typescript","undefined"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PrinOrange.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-26T03:43:51.000Z","updated_at":"2024-06-28T03:03:19.000Z","dependencies_parsed_at":"2023-02-14T14:02:17.031Z","dependency_job_id":null,"html_url":"https://github.com/PrinOrange/nullify-undefined","commit_stats":null,"previous_names":["prinorange/nullify"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrinOrange%2Fnullify-undefined","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrinOrange%2Fnullify-undefined/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrinOrange%2Fnullify-undefined/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrinOrange%2Fnullify-undefined/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PrinOrange","download_url":"https://codeload.github.com/PrinOrange/nullify-undefined/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241877512,"owners_count":20035417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["javascript","null","null-safety","typescript","undefined"],"created_at":"2024-11-14T22:16:23.811Z","updated_at":"2025-03-04T16:13:06.109Z","avatar_url":"https://github.com/PrinOrange.png","language":"TypeScript","readme":"## EMPTY HANDLING FOR JS OBJECT\n\nWhen writing JavaScript or TypeScript, sometimes you will encounter the problem of serializing undefined values and causing errors.\n\nFor example, In [next.js]() developing when you pass an object with key of undefined value in `getStaticProps` or `getServerSideProps`, it will throw such the error:\n\n```\nerror - SerializableError: \nError serializing '.Prop.value returned fram 'getStaticProps’in \"/page/[..slug]\".\nReason: \"undefined’ cannot be serialized as JSON.\nPlease use 'null’or omit this value.\n```\n\nThe bad thing is: many of the Props passed wrote in TypeScript are Optional Keys, and there are a lot of structured sub-data.\n\nSo when you accidentally pass in a key whose value is undefined, an error will be raised. This places a large burden on program checking.\n\nSo in order to safely serialize an object or a value, you can convert all Undefined to null, which is what this package does.\n\n### Install\n\n```bash\nnpm install nullify-undefined\n```\n\n### Usage\n\nThis library provides two modular reference methods of `ESM` and `CommonJS module`. To import this library,\n\n```javascript\nimport Nullify from 'nullify-undefined/esm'     // For esm\n\nvar Nullify = require('nullify-undefined/cjs')  //For cjs\n```\n\nFor example, I need to transform all `undefined` values into `null`:\n\n```javascript\nvar obj = {\n  a: \"the value of a\",\n  b: {\n    c: undefined,\n    d: [{ e: undefined }, undefined],\n  },\n  f: null,\n};\n```\n\nuse `nullifyUndefined` function\n\n```javascript\nNullify.nullifyUndefined(obj);\n```\n\nOutput:\n\n```javascript\nobj = {\n  a: \"the value of a\",\n  b: {\n    c: null,\n    d: [{ e: null }, null],\n  },\n  f: null,\n};\n\n```\n\nThis function changes the value of the object passed in, and the return value is a reference to the passed object. If you don't want to change the passed object, you can make a deep copy of the passed object. like this:\n\n```javascript\nNullify.nullifyUndefined({...obj});\n```\n\nIn addition, this library also provides some other functions. For example:\n\n+ undefineNull : Replaces null values in JavaScript objects with undefined.\n+ removeEmptyValue : Remove all empty values in JavaScript objects. Contains `null` and `undefined` value.\n+ removeNull : Replaces all `null` values in JavaScript objects.\n+ removeUndefined : Replaces all `undefined` values in JavaScript objects.\n\nTheir usage is similar to the example above.\n\n### LICENSE\n\nThis project is MIT licensed.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinorange%2Fnullify-undefined","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprinorange%2Fnullify-undefined","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprinorange%2Fnullify-undefined/lists"}