marko 2.11.2 → 2.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@
16
16
  'use strict';
17
17
  var createError = require('raptor-util').createError;
18
18
  var nodePath = require('path');
19
- var stringify = require('raptor-json/stringify');
19
+ var stringify = require('./util/stringify');
20
20
  var StringBuilder = require('raptor-strings/StringBuilder');
21
21
  var Expression = require('./Expression');
22
22
  var arrayFromArguments = require('raptor-util').arrayFromArguments;
@@ -16,7 +16,7 @@
16
16
  'use strict';
17
17
  var createError = require('raptor-util').createError;
18
18
  var expressionParser = require('./expression-parser');
19
- var stringify = require('raptor-json/stringify');
19
+ var stringify = require('./util/stringify');
20
20
  var Expression = require('./Expression');
21
21
  function TypeConverter() {
22
22
  }
@@ -17,7 +17,7 @@
17
17
  var createError = require('raptor-util').createError;
18
18
  var Expression = require('./Expression');
19
19
  var strings = require('raptor-strings');
20
- var stringify = require('raptor-json/stringify');
20
+ var stringify = require('./util/stringify');
21
21
  var regexp = require('raptor-regexp');
22
22
  var ok = require('assert').ok;
23
23
 
@@ -0,0 +1,169 @@
1
+ /*
2
+ * Copyright 2011 eBay Software Foundation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * Defines a "stringify" function that can be pulled in using require.
19
+ *
20
+ * Example:
21
+ * <js>
22
+ * var stringify = require('raptor/json/stringify');
23
+ * var json = stringify({hello: "world"});
24
+ * //Output: {"hello":"world"}
25
+ * </js>
26
+ *
27
+ * The Raptor stringify function supports additional options not provided
28
+ * by the builtin JSON object:
29
+ * <b>special</b>: A regular expression to indicate "special" characters that must be escaped
30
+ * <b>useSingleQuote</b>: If true, then single quotes will be used for strings instead of double quotes (helpful if the the string values contain a lot of double quotes)
31
+ *
32
+ */
33
+
34
+ var raptorStrings = require("raptor-strings");
35
+ var unicodeEncode = raptorStrings.unicodeEncode; //Pick up the unicodeEncode method from the strings module
36
+ var COMMA = ",";
37
+ var NULL = "null";
38
+ var ARRAY = Array;
39
+ var SPECIAL = /([^ -~]|(["'\\]))/g;
40
+ var REPLACE_CHARS = {
41
+ "\b": "\\b",
42
+ "\t": "\\t",
43
+ "\n": "\\n",
44
+ "\f": "\\f",
45
+ "\r": "\\r",
46
+ "\\": "\\\\",
47
+ };
48
+
49
+ function stringify(o, options) {
50
+ if (!options) {
51
+ options = {};
52
+ }
53
+
54
+ var specialRegExp = options.special || SPECIAL;
55
+ var replace = options.replace || REPLACE_CHARS;
56
+
57
+ var buffer = raptorStrings.createStringBuilder();
58
+
59
+ function append(str) {
60
+ buffer.append(str);
61
+ }
62
+
63
+ var useSingleQuote = options.useSingleQuote === true;
64
+ var strChar = useSingleQuote === true ? "'" : '"';
65
+ function encodeString(s) {
66
+ return (
67
+ strChar +
68
+ s.replace(specialRegExp, function (c) {
69
+ var replacement = replace[c];
70
+
71
+ if (replacement) {
72
+ return replacement;
73
+ }
74
+
75
+ if (c === '"') {
76
+ return useSingleQuote ? '"' : '\\"';
77
+ } else if (c === "'") {
78
+ return useSingleQuote ? "\\'" : "'";
79
+ } else {
80
+ return unicodeEncode(c);
81
+ }
82
+ }) +
83
+ strChar
84
+ );
85
+ }
86
+
87
+ function serialize(o) {
88
+ if (o == null) {
89
+ append(NULL);
90
+ return;
91
+ }
92
+
93
+ var constr = o.constructor,
94
+ i,
95
+ len;
96
+
97
+ if (typeof o.toJSON === "function") {
98
+ if (constr !== Date) {
99
+ // Dates are handled later
100
+ o = o.toJSON();
101
+ if (o == null) {
102
+ append(NULL);
103
+ return;
104
+ }
105
+
106
+ constr = o.constructor;
107
+ }
108
+ }
109
+
110
+ if (o === true || o === false || constr === Boolean) {
111
+ append(o.toString());
112
+ } else if (constr === ARRAY) {
113
+ append("[");
114
+
115
+ len = o.length;
116
+ for (i = 0; i < len; i++) {
117
+ if (i !== 0) {
118
+ append(COMMA);
119
+ }
120
+
121
+ serialize(o[i]);
122
+ }
123
+
124
+ append("]");
125
+ } else if (constr === Date) {
126
+ append(o.getTime());
127
+ } else {
128
+ var type = typeof o;
129
+ switch (type) {
130
+ case "string":
131
+ append(encodeString(o));
132
+ break;
133
+ case "number":
134
+ append(isFinite(o) ? o + "" : NULL);
135
+ break;
136
+ case "object":
137
+ append("{");
138
+ var first = true,
139
+ v;
140
+ for (var k in o) {
141
+ if (o.hasOwnProperty(k)) {
142
+ v = o[k];
143
+ if (v == null || typeof v === "function") continue;
144
+
145
+ if (first === false) {
146
+ append(COMMA);
147
+ } else {
148
+ first = false;
149
+ }
150
+
151
+ append(encodeString(k));
152
+ append(":");
153
+ serialize(v);
154
+ }
155
+ }
156
+ append("}");
157
+ break;
158
+ default:
159
+ append(NULL);
160
+ }
161
+ }
162
+ }
163
+
164
+ serialize(o);
165
+
166
+ return buffer.toString();
167
+ }
168
+
169
+ module.exports = stringify;
package/package.json CHANGED
@@ -35,7 +35,6 @@
35
35
  "minimatch": "^9.0.0",
36
36
  "property-handlers": "^1.0.0",
37
37
  "raptor-args": "^1.0.0",
38
- "raptor-json": "^1.0.1",
39
38
  "raptor-logging": "^1.0.1",
40
39
  "raptor-modules": "^1.0.5",
41
40
  "raptor-polyfill": "^1.0.0",
@@ -69,5 +68,5 @@
69
68
  "logo": {
70
69
  "url": "https://raw.githubusercontent.com/marko-js/branding/master/marko-logo-small.png"
71
70
  },
72
- "version": "2.11.2"
71
+ "version": "2.11.3"
73
72
  }
@@ -35,7 +35,7 @@ function convertNumber(str) {
35
35
  }
36
36
  }
37
37
 
38
- var stringify = require('raptor-json/stringify').stringify;
38
+ var stringify = require('../../compiler/util/stringify');
39
39
  function parseForEach(value) {
40
40
  var match = value.match(forEachRegEx);
41
41
  if (match) {
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  'use strict';
17
- var stringify = require('raptor-json/stringify');
17
+ var stringify = require('../../compiler/util/stringify');
18
18
  var nodePath = require('path');
19
19
  var req = require;
20
20
  var fs;
@@ -16,7 +16,7 @@
16
16
  'use strict';
17
17
  var extend = require('raptor-util').extend;
18
18
  var forEachEntry = require('raptor-util').forEachEntry;
19
- var stringify = require('raptor-json/stringify');
19
+ var stringify = require('../../compiler/util/stringify');
20
20
  var isObjectEmpty = require('raptor-util/isObjectEmpty');
21
21
  var requireVarName = require('./requireVarName');
22
22