New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@nteract/commutable

Package Overview
Dependencies
Maintainers
18
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nteract/commutable - npm Package Compare versions

Comparing version 7.5.0 to 7.5.1

33

__tests__/v3.spec.ts

@@ -1,2 +0,2 @@

import { fromJS, isNotebookV3 } from "../src/v3";
import { CodeCell, NotebookV3, fromJS, isNotebookV3 } from "../src/v3";

@@ -157,2 +157,33 @@ describe("isNotebookV3", () => {

});
const getCell = (source: string): CodeCell => {
return {
cell_type: "code",
collapsed: false,
input: [source],
language: "python",
metadata: {},
outputs: [],
prompt_number: 7
};
};
it("normalizes line endings to LF for all cell sources", () => {
const notebook: NotebookV3 = {
worksheets: [{
cells: [
getCell("line1\nline2\r\nline3\r\n"),
getCell("line1\r\nline2\r\nline3\n")
],
metadata: {}
}],
metadata: {},
nbformat: 3,
nbformat_minor: 0
};
const out = fromJS(notebook);
expect(out.cellMap.get(out.cellOrder.get(0))?.source).toEqual("line1\nline2\nline3\n");
expect(out.cellMap.get(out.cellOrder.get(1))?.source).toEqual("line1\nline2\nline3\n");
});
});

@@ -231,2 +231,27 @@ import Immutable, { Record } from "immutable";

});
describe("fromJS", () => {
const getCell = (id: string, source: string) => {
return {
id,
cell_type: "code",
execution_count: null,
source,
outputs: []
};
};
it("normalizes line endings to LF for all cell sources", () => {
const notebook = getNotebook({
cells: [
getCell("cell1", "line1\nline2\r\nline3\r\n"),
getCell("cell2", "line1\r\nline2\r\nline3\n")
]
});
const out = fromJS(notebook);
expect(out.cellMap.get("cell1")?.source).toEqual("line1\nline2\nline3\n");
expect(out.cellMap.get("cell2")?.source).toEqual("line1\nline2\nline3\n");
});
});
});

24

lib/cells.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeRawCell = exports.makeMarkdownCell = exports.makeCodeCell = void 0;
const primitives_1 = require("./primitives");
const immutable_1 = require("immutable");
exports.makeCodeCell = immutable_1.Record({
function normalizedSourceCellRecord(recordFn) {
// Transparently wrap the factory, but overwrite the source with its normalized value
function factory(...args) {
const res = recordFn.apply(this, args);
return res.set("source", primitives_1.normalizeLineEndings(res.source));
}
;
factory.prototype = recordFn.prototype;
factory.displayName = recordFn.displayName;
return factory;
}
exports.makeCodeCell = normalizedSourceCellRecord(immutable_1.Record({
cell_type: "code",

@@ -21,4 +33,4 @@ execution_count: null,

outputs: immutable_1.List(),
});
exports.makeMarkdownCell = immutable_1.Record({
}));
exports.makeMarkdownCell = normalizedSourceCellRecord(immutable_1.Record({
attachments: undefined,

@@ -34,4 +46,4 @@ cell_type: "markdown",

source: "",
});
exports.makeRawCell = immutable_1.Record({
}));
exports.makeRawCell = normalizedSourceCellRecord(immutable_1.Record({
cell_type: "raw",

@@ -46,3 +58,3 @@ metadata: immutable_1.Map({

source: "",
});
}));
//# sourceMappingURL=cells.js.map

@@ -114,2 +114,6 @@ import * as Immutable from "immutable";

/**
* Normalize line endings to \n line feed to be consistent across OS platforms.
*/
export declare function normalizeLineEndings(text?: string): string | undefined;
/**
* Turn nbformat multiline strings (arrays of strings for simplifying diffs)

@@ -116,0 +120,0 @@ * into strings

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createOnDiskMediaBundle = exports.createFrozenMediaBundle = exports.deepFreeze = exports.remultiline = exports.demultiline = exports.createCellId = void 0;
exports.createOnDiskMediaBundle = exports.createFrozenMediaBundle = exports.deepFreeze = exports.remultiline = exports.demultiline = exports.normalizeLineEndings = exports.createCellId = void 0;
const uuid_1 = require("uuid");

@@ -10,2 +10,9 @@ function createCellId() {

/**
* Normalize line endings to \n line feed to be consistent across OS platforms.
*/
function normalizeLineEndings(text) {
return text ? text.replace(/\r\n/g, "\n") : text;
}
exports.normalizeLineEndings = normalizeLineEndings;
/**
* Turn nbformat multiline strings (arrays of strings for simplifying diffs)

@@ -12,0 +19,0 @@ * into strings

{
"name": "@nteract/commutable",
"version": "7.5.0",
"version": "7.5.1",
"description": "library for immutable notebook operations",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

import { ImmutableOutput } from "./outputs";
import { ExecutionCount, MimeBundle } from "./primitives";
import { ExecutionCount, MimeBundle, normalizeLineEndings } from "./primitives";

@@ -12,2 +12,13 @@ import {

function normalizedSourceCellRecord<T extends { source?: string }>(recordFn: Record.Factory<T>): Record.Factory<T> {
// Transparently wrap the factory, but overwrite the source with its normalized value
function factory(this: ThisType<typeof recordFn>, ...args: Parameters<typeof recordFn>) {
const res = recordFn.apply(this, args);
return res.set("source", normalizeLineEndings(res.source));
};
factory.prototype = recordFn.prototype;
factory.displayName = recordFn.displayName;
return factory as Record.Factory<T>;
}
/* CodeCell Record Boilerplate */

@@ -25,3 +36,3 @@

export const makeCodeCell = Record<CodeCellParams>({
export const makeCodeCell = normalizedSourceCellRecord(Record<CodeCellParams>({
cell_type: "code",

@@ -42,3 +53,3 @@ execution_count: null,

outputs: ImmutableList(),
});
}));

@@ -57,3 +68,3 @@ export type ImmutableCodeCell = RecordOf<CodeCellParams>;

export const makeMarkdownCell = Record<MarkdownCellParams>({
export const makeMarkdownCell = normalizedSourceCellRecord(Record<MarkdownCellParams>({
attachments: undefined,

@@ -69,3 +80,3 @@ cell_type: "markdown",

source: "",
});
}));

@@ -83,3 +94,3 @@ export type ImmutableMarkdownCell = RecordOf<MarkdownCellParams>;

export const makeRawCell = Record<RawCellParams>({
export const makeRawCell = normalizedSourceCellRecord(Record<RawCellParams>({
cell_type: "raw",

@@ -94,3 +105,3 @@ metadata: ImmutableMap({

source: "",
});
}));

@@ -97,0 +108,0 @@ export type ImmutableRawCell = RecordOf<RawCellParams>;

@@ -119,2 +119,9 @@ import * as Immutable from "immutable";

/**
* Normalize line endings to \n line feed to be consistent across OS platforms.
*/
export function normalizeLineEndings(text?: string): string | undefined {
return text ? text.replace(/\r\n/g, "\n") : text;
}
/**
* Turn nbformat multiline strings (arrays of strings for simplifying diffs)

@@ -121,0 +128,0 @@ * into strings

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc