libshv-js 3.6.4 → 3.6.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cpon.ts +12 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libshv-js",
3
- "version": "3.6.4",
3
+ "version": "3.6.5",
4
4
  "description": "Typescript implementation of libshv",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/src/cpon.ts CHANGED
@@ -674,7 +674,7 @@ class CponWriter {
674
674
  ctx: PackContext;
675
675
  nestLevel = 0;
676
676
 
677
- constructor(private readonly indentString?: string) {
677
+ constructor(private readonly indentString?: string, private oneLiners: OneLiners = OneLiners.Yes) {
678
678
  this.ctx = new PackContext();
679
679
  }
680
680
 
@@ -949,6 +949,10 @@ class CponWriter {
949
949
  }
950
950
 
951
951
  private isOneLiner(value: MetaMap | ShvMap | IMap | List) {
952
+ if (this.oneLiners === OneLiners.No) {
953
+ return false;
954
+ }
955
+
952
956
  const keyThreshold = Array.isArray(value) ? 10 : 5;
953
957
 
954
958
  if (Array.isArray(value)) {
@@ -971,8 +975,13 @@ class CponWriter {
971
975
  }
972
976
  }
973
977
 
974
- const toCpon = (value: RpcValue, indentString?: string) => {
975
- const wr = new CponWriter(indentString);
978
+ export enum OneLiners {
979
+ Yes,
980
+ No,
981
+ }
982
+
983
+ const toCpon = (value: RpcValue, indentString?: string, oneLiners: OneLiners = OneLiners.Yes) => {
984
+ const wr = new CponWriter(indentString, oneLiners);
976
985
  wr.write(value);
977
986
  return new TextDecoder().decode(wr.ctx.buffer());
978
987
  };