From 0290ff510e7ec6a49829bc4a4ff0c3b72c270c3d Mon Sep 17 00:00:00 2001 From: Phil Gold Date: Sat, 14 Apr 2018 12:58:47 -0400 Subject: [PATCH 1/6] Add fork explanation to README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 0a5e290..e1092f5 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ JsonML-related tools. +## Forked Library + +From from [benjycui/jsonml.js](https://github.com/benjycui/jsonml.js) since it is used by many CondeNast applications but not actively supported. Fork created by [pgoldrbx](https://github.com/pgoldrbx). + ## Usage ```bash From fe176f44d202be6f0d5fd8dd9ba8fa2c80eaa59c Mon Sep 17 00:00:00 2001 From: Phil Gold Date: Mon, 16 Apr 2018 14:28:02 -0400 Subject: [PATCH 2/6] chore: add nyc for coverage reports (#1) --- .gitignore | 2 ++ .nycrc | 8 ++++++++ package.json | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .nycrc diff --git a/.gitignore b/.gitignore index 7d88016..674672f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ *\.sh /node_modules /npm-debug.log +.nyc_output +coverage diff --git a/.nycrc b/.nycrc new file mode 100644 index 0000000..699d713 --- /dev/null +++ b/.nycrc @@ -0,0 +1,8 @@ +{ + "all": true, + "cache": false, + "reporter": [ + "lcov", + "text" + ] +} diff --git a/package.json b/package.json index ea73efe..d496f9c 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "eslint-fix": "eslint --fix ./lib/utils.js ./test", "babel": "babel src --out-dir lib", "pub": "npm run babel && npm publish && rm -rf lib", - "test": "mocha" + "test": "nyc mocha" }, "babel": { "presets": [ @@ -40,6 +40,7 @@ "babel-preset-es2015": "^6.6.0", "eslint": "^2.10.2", "eslint-config-egg": "^2.0.0", - "mocha": "^2.4.5" + "mocha": "^2.4.5", + "nyc": "^11.6.0" } } From e96a2def92bac787473562bc0fd516c39031931f Mon Sep 17 00:00:00 2001 From: Phil Gold Date: Mon, 16 Apr 2018 14:28:36 -0400 Subject: [PATCH 3/6] Cleanup badges in README and missing package info (#4) --- README.md | 5 +---- package.json | 14 +++++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e1092f5..dcf9d7a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ # jsonml.js -[![](https://img.shields.io/travis/benjycui/jsonml.js.svg?style=flat-square)](https://travis-ci.org/benjycui/jsonml.js) -[![npm package](https://img.shields.io/npm/v/jsonml.js.svg?style=flat-square)](https://www.npmjs.org/package/jsonml.js) -[![NPM downloads](http://img.shields.io/npm/dm/jsonml.js.svg?style=flat-square)](https://npmjs.org/package/jsonml.js) -[![Dependency Status](https://david-dm.org/benjycui/jsonml.js.svg?style=flat-square)](https://david-dm.org/benjycui/jsonml.js) +[![Build Status](https://travis-ci.org/CondeNast/jsonml.js.svg?branch=master)](https://travis-ci.org/CondeNast/jsonml.js) JsonML-related tools. diff --git a/package.json b/package.json index d496f9c..ba9a5f3 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "jsonml.js", + "name": "@condenast/jsonml.js", "version": "0.1.1", "description": "JsonML-related tools.", "main": "index.js", @@ -21,6 +21,14 @@ "xml", "html" ], + "repository": { + "type": "git", + "url": "https://github.com/CondeNast/jsonml.js" + }, + "bugs": { + "url": "https://github.com/CondeNast/jsonml.js/issues" + }, + "homepage": "https://github.com/CondeNast/jsonml.js", "contributors": [ { "name": "Stephen M. McKamey" @@ -28,6 +36,10 @@ { "name": "Benjy Cui", "email": "benjytrys@gmail.com" + }, + { + "name": "Phil Gold", + "email": "pgold@rubixmedia.com" } ], "license": "MIT", From 5d51cda1a44fa8345f5c61c569fa924ec7058b21 Mon Sep 17 00:00:00 2001 From: Phil Gold Date: Mon, 16 Apr 2018 14:28:56 -0400 Subject: [PATCH 4/6] Update travis config for node LTS and disable emails (#5) --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3f308e8..c9ff00f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: node_js node_js: - "4" - - "5" - "6" + - "8" + +notifications: + email: false From 9d0c9e21cb41def5b2b710bd587e9a7054483a20 Mon Sep 17 00:00:00 2001 From: Phil Gold Date: Mon, 16 Apr 2018 14:33:37 -0400 Subject: [PATCH 5/6] fix: use html.isRaw method when appending child Markup instances (#3) --- lib/utils.js | 4 +++- test/utils.test.js | 11 +++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index f7e7bc7..542c0a0 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,5 +1,7 @@ 'use strict'; +const isRaw = require('./html').isRaw; + const isArray = Array.isArray || function isArray(val) { return val instanceof Array; }; @@ -110,7 +112,7 @@ exports.appendChild = function appendChild(parent, child) { // result was a JsonML node parent.push(child); - } else if (exports.isRaw(child)) { + } else if (isRaw(child)) { // result was a JsonML node parent.push(child); diff --git a/test/utils.test.js b/test/utils.test.js index 6e0d946..e4d2d3b 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -1,6 +1,7 @@ 'use strict'; const assert = require('assert'); +const html = require('../lib/html'); const utils = require('../lib/utils'); describe('utils', function() { @@ -311,18 +312,16 @@ describe('utils', function() { }); describe('when appending a raw child', function() { - // @TODO - this will currently throw an error due to missing function `isRaw` - xit('should append to the parent', function() { + it('should append to the parent', function() { const jml = ['div']; - const child = new function RawChild() {}; + const child = html.raw('string value'); utils.appendChild(jml, child); - assert.strictEqual(jml, ['div', child]); + assert.deepEqual(jml, ['div', child]); }); }); describe('when appending attributes', function() { - // @TODO - this will currently throw an error due to missing function `isRaw` - xit('should add attributes to the parent element', function() { + it('should add attributes to the parent element', function() { const jml = ['div']; const attrs = { a: 1 }; utils.appendChild(jml, attrs); From df4b4e051f9838566420efbdf94a5448a1231325 Mon Sep 17 00:00:00 2001 From: Phil Gold Date: Sun, 22 Oct 2017 09:43:21 -0400 Subject: [PATCH 6/6] fix: prevent mutation if fragment param when appending --- lib/utils.js | 6 +++--- test/utils.test.js | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 542c0a0..5635a55 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -91,11 +91,11 @@ exports.appendChild = function appendChild(parent, child) { if (isArray(child) && child[0] === '') { // result was multiple JsonML sub-trees (i.e. documentFragment) - child.shift();// remove fragment ident + const fragments = child.slice(1); // directly append children - while (child.length) { - appendChild(parent, child.shift(), arguments[2]); + while (fragments.length) { + appendChild(parent, fragments.shift(), arguments[2]); } } else if (child && 'object' === typeof child) { diff --git a/test/utils.test.js b/test/utils.test.js index e4d2d3b..c556e8d 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -262,15 +262,17 @@ describe('utils', function() { assert.deepEqual(jml, ['div', ['em', 'hello'], ['strong', 'world']]); }); - // @TODO - is this an intentional mutation? - it('should remove fragment contents', function() { + it('should not mutate child fragment param', function() { const jml = ['div']; const fragment = ['', ['em', 'hello'], ['strong', 'world'], ]; utils.appendChild(jml, fragment); - assert.deepEqual(fragment, []); + assert.deepEqual(fragment, ['', + ['em', 'hello'], + ['strong', 'world'], + ]); }); });