serialize-as-code
Advanced tools
Comparing version 1.3.1 to 2.0.0
@@ -5,10 +5,6 @@ 'use strict'; | ||
const NOP = () => {}; | ||
const NOP = () => undefined; | ||
const forEach = (o, handler) => Object.keys(o).forEach(k => handler(o[k], k)); | ||
const __getTypeOfObject = o => Object.prototype.toString.call(o).split(' ')[1].slice(0, -1); | ||
const __typePattern = /^\[object ([^\]]+)]$/; | ||
const __getTypeOfObject = o => (__typePattern.exec(Object.prototype.toString.call(o)) || [undefined])[1]; | ||
const __serializeProp = (key, value, custom, serialized) => typeof value === 'string' ? `${key}="${value}"` : `${key}={${__serialize(value, custom, serialized)}}`; | ||
@@ -19,3 +15,3 @@ | ||
const props = []; | ||
forEach(elemProps, (v, k) => { | ||
Object.entries(elemProps).forEach(([k, v]) => { | ||
if (v !== undefined && k !== 'children') props.push(__serializeProp(k, v, custom, serialized)); | ||
@@ -100,2 +96,7 @@ }); | ||
const __serializeHTML = o => { | ||
const objectType = o.constructor.name; | ||
if (/^HTML[a-zA-Z]*Element$/.test(objectType)) return objectType; | ||
}; | ||
const __serializeObject = (o, custom, serialized) => { | ||
@@ -122,6 +123,7 @@ const oKeys = Object.keys(o); | ||
react: __serializeIfReact, | ||
array: __serializeOptArray | ||
array: __serializeOptArray, | ||
HTML: __serializeHTML | ||
}; | ||
const __serialize = (o, custom, serialized) => Serialize.custom(o, custom, serialized) || Serialize.undefOrNull(o, custom, serialized) || Serialize.flat(o, custom, serialized) || Serialize.cyclomatic(o, custom, serialized) || (nextSerialized => Serialize.react(o, custom, nextSerialized) || Serialize.array(o, custom, nextSerialized) || __serializeObject(o, custom, nextSerialized))([...serialized, o]); | ||
const __serialize = (o, custom, serialized) => Serialize.custom(o, custom, serialized) || Serialize.undefOrNull(o, custom, serialized) || Serialize.flat(o, custom, serialized) || Serialize.cyclomatic(o, custom, serialized) || (nextSerialized => Serialize.react(o, custom, nextSerialized) || Serialize.array(o, custom, nextSerialized) || Serialize.HTML(o, custom, nextSerialized) || __serializeObject(o, custom, nextSerialized))([...serialized, o]); | ||
@@ -128,0 +130,0 @@ const _serialize = (o, custom) => __serialize(o, custom, []); |
@@ -1,9 +0,5 @@ | ||
const NOP = () => {}; | ||
const NOP = () => undefined; | ||
const forEach = (o, handler) => Object.keys(o).forEach(k => handler(o[k], k)); | ||
const __getTypeOfObject = o => Object.prototype.toString.call(o).split(' ')[1].slice(0, -1); | ||
const __typePattern = /^\[object ([^\]]+)]$/; | ||
const __getTypeOfObject = o => (__typePattern.exec(Object.prototype.toString.call(o)) || [undefined])[1]; | ||
const __serializeProp = (key, value, custom, serialized) => typeof value === 'string' ? `${key}="${value}"` : `${key}={${__serialize(value, custom, serialized)}}`; | ||
@@ -14,3 +10,3 @@ | ||
const props = []; | ||
forEach(elemProps, (v, k) => { | ||
Object.entries(elemProps).forEach(([k, v]) => { | ||
if (v !== undefined && k !== 'children') props.push(__serializeProp(k, v, custom, serialized)); | ||
@@ -95,2 +91,7 @@ }); | ||
const __serializeHTML = o => { | ||
const objectType = o.constructor.name; | ||
if (/^HTML[a-zA-Z]*Element$/.test(objectType)) return objectType; | ||
}; | ||
const __serializeObject = (o, custom, serialized) => { | ||
@@ -117,6 +118,7 @@ const oKeys = Object.keys(o); | ||
react: __serializeIfReact, | ||
array: __serializeOptArray | ||
array: __serializeOptArray, | ||
HTML: __serializeHTML | ||
}; | ||
const __serialize = (o, custom, serialized) => Serialize.custom(o, custom, serialized) || Serialize.undefOrNull(o, custom, serialized) || Serialize.flat(o, custom, serialized) || Serialize.cyclomatic(o, custom, serialized) || (nextSerialized => Serialize.react(o, custom, nextSerialized) || Serialize.array(o, custom, nextSerialized) || __serializeObject(o, custom, nextSerialized))([...serialized, o]); | ||
const __serialize = (o, custom, serialized) => Serialize.custom(o, custom, serialized) || Serialize.undefOrNull(o, custom, serialized) || Serialize.flat(o, custom, serialized) || Serialize.cyclomatic(o, custom, serialized) || (nextSerialized => Serialize.react(o, custom, nextSerialized) || Serialize.array(o, custom, nextSerialized) || Serialize.HTML(o, custom, nextSerialized) || __serializeObject(o, custom, nextSerialized))([...serialized, o]); | ||
@@ -123,0 +125,0 @@ const _serialize = (o, custom) => __serialize(o, custom, []); |
{ | ||
"name": "serialize-as-code", | ||
"version": "1.3.1", | ||
"version": "2.0.0", | ||
"description": "Serialize any Javascript object as its source code", | ||
@@ -9,15 +9,7 @@ "main": "dist/cjs/index.js", | ||
"files": [ | ||
"dist/cjs", | ||
"dist/esm", | ||
"dist/cjs", | ||
"src" | ||
"src", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"dist": "rm -rf dist && rollup -c", | ||
"eslint": "eslint src/ test/", | ||
"flow": "flow --quiet", | ||
"test": "yarn run flow && yarn run eslint && yarn run test-coverage", | ||
"test-coverage": "jest --all --coverage", | ||
"prettier": "prettier --config .prettierrc --write src/**/*.js test/**/*.js", | ||
"coveralls": "cat ./coverage/lcov.info | coveralls" | ||
}, | ||
"repository": { | ||
@@ -35,25 +27,33 @@ "type": "git", | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@babel/core": "^7.7.7", | ||
"@babel/plugin-proposal-class-properties": "^7.7.4", | ||
"@babel/preset-env": "^7.7.7", | ||
"@babel/preset-flow": "^7.7.4", | ||
"@babel/preset-react": "^7.7.4", | ||
"babel-eslint": "^10.0.3", | ||
"babel-jest": "^24.9.0", | ||
"coveralls": "^3.0.9", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.9.0", | ||
"eslint-plugin-flowtype": "^4.5.3", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"eslint-plugin-react": "^7.17.0", | ||
"flow-bin": "^0.114.0", | ||
"jest": "^24.9.0", | ||
"prettier": "^1.19.1", | ||
"react": "^16.12.0", | ||
"rollup": "^1.27.14", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-flow-entry": "^0.3.3" | ||
"@babel/core": "^7.15.0", | ||
"@babel/preset-env": "^7.15.0", | ||
"@babel/preset-react": "^7.14.5", | ||
"@babel/preset-typescript": "^7.15.0", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-node-resolve": "^13.0.4", | ||
"@types/jest": "^27.0.1", | ||
"@types/react": "^17.0.19", | ||
"@typescript-eslint/eslint-plugin": "^4.29.3", | ||
"@typescript-eslint/parser": "^4.29.3", | ||
"babel-jest": "^27.0.6", | ||
"coveralls": "^3.1.1", | ||
"eslint": "^7.32.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^3.4.1", | ||
"eslint-plugin-react": "^7.24.0", | ||
"jest": "^27.0.6", | ||
"prettier": "^2.3.2", | ||
"react": "^17.0.2", | ||
"rollup": "^2.56.3", | ||
"typescript": "^4.3.5" | ||
}, | ||
"scripts": { | ||
"dist": "rm -rf dist && rollup -c && cp index.ts index.d.ts", | ||
"eslint": "eslint --cache --cache-location 'build/.eslintcache' --ext .ts,.tsx src/ test/", | ||
"tsc": "tsc", | ||
"test": "pnpm tsc && pnpm eslint && pnpm test:coverage", | ||
"test:coverage": "jest --all --coverage", | ||
"coveralls": "cat ./coverage/lcov.info | coveralls" | ||
} | ||
} | ||
} |
@@ -15,3 +15,3 @@ [![GitHub license][license-image]][license-url] | ||
### Some aspects | ||
- `flow` support included | ||
- `TypeScript` support included | ||
- ~ 1 kB (gzipped) (see [bundlephobia](https://bundlephobia.com/result?p=serialize-as-code)) | ||
@@ -62,3 +62,3 @@ | ||
console.log({canBe: 'nested', here: someObjectToMatch}); | ||
console.log({ canBe: 'nested', here: someObjectToMatch }); | ||
// prints: {canBe: 'nested', here: FOO} | ||
@@ -71,3 +71,3 @@ ``` | ||
[build-image]: https://img.shields.io/travis/fdc-viktor-luft/serialize-as-code/master.svg?style=flat-square | ||
[build-url]: https://travis-ci.org/fdc-viktor-luft/serialize-as-code | ||
[build-url]: https://app.travis-ci.com/github/fdc-viktor-luft/serialize-as-code | ||
[npm-image]: https://img.shields.io/npm/v/serialize-as-code.svg?style=flat-square | ||
@@ -74,0 +74,0 @@ [npm-url]: https://www.npmjs.org/package/serialize-as-code |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22210
21
7
1