Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dot-properties

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dot-properties - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

2

package.json
{
"name": "dot-properties",
"version": "0.1.0",
"version": "0.2.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -27,3 +27,3 @@ # dot-properties

If `input` is a hierarchical object, keys will consist of the path parts joined by `.` characters. With array input, string values represent blank or comment lines and string arrays are `[key, value]` pairs. Control characters and `\` will be appropriately escaped. If the `ascii` option is true, all non-ASCII characters will also be `\u` escaped.
If `input` is a hierarchical object, keys will consist of the path parts joined by `.` characters. With array input, string values represent blank or comment lines and string arrays are `[key, value]` pairs. Control characters and `\` will be appropriately escaped. If the `latin1` option is not set to false, all non-Latin-1 characters will also be `\u` escaped.

@@ -33,3 +33,2 @@ Output styling is controlled by the second (optional) `options` parameter; by default a spaced `=` separates the key from the value, `\n` is the newline separator, lines are folded at 80 characters (at most, splitting at nice places), with subsequent lines indented by four spaces, and comment lines are prefixed with a `#`. `''` as a key value is considered the default, and set as the value of a key corresponding to its parent object's path:

const defaultOptions = {
ascii: false, // control chars are always escaped
commentPrefix: '# ', // could also use e.g. '!'

@@ -39,2 +38,3 @@ defaultKey: '', // YAML uses '='

keySep: ' = ', // should have at most one = or :
latin1: true, // default encoding for .properties files
lineWidth: 80, // use null to disable

@@ -41,0 +41,0 @@ newline: '\n', // Windows uses \r\n

@@ -1,3 +0,3 @@

const escapeNonPrintable = (str, ascii) => {
const re = ascii ? /[^\t\n\f\r -~]/g : /[\0-\b\v\x0e-\x1f]/g
const escapeNonPrintable = (str, latin1) => {
const re = latin1 !== false ? /[^\t\n\f\r -~\xa1-\xff]/g : /[\0-\b\v\x0e-\x1f]/g
return String(str).replace(re, (ch) => {

@@ -20,5 +20,5 @@ const esc = ch.charCodeAt(0).toString(16)

const getFold = ({ ascii, indent, lineWidth, newline }) => (line) => {
const getFold = ({ indent, latin1, lineWidth, newline }) => (line) => {
if (!lineWidth || lineWidth < 0) return line
line = escapeNonPrintable(line, ascii)
line = escapeNonPrintable(line, latin1)
let start = 0

@@ -97,4 +97,4 @@ let split = undefined

* comment lines and string arrays are [key, value] pairs. The characters \, \n
* and \r will be appropriately escaped. If the ascii option is true, all
* non-ASCII-printable characters will also be \u escaped.
* and \r will be appropriately escaped. If the `latin1` option is not set to
* false, all non-Latin-1 characters will also be `\u` escaped.
*

@@ -110,3 +110,2 @@ * Output styling is controlled by the second options parameter; by default a

* @param {Object} [options={}]
* @param {boolean} [options.ascii=false]
* @param {string} [options.commentPrefix='# ']

@@ -116,2 +115,3 @@ * @param {string} [options.defaultKey='']

* @param {string} [options.keySep=' = ']
* @param {boolean} [options.latin1=true]
* @param {number} [options.lineWidth=80]

@@ -122,3 +122,2 @@ * @param {string} [options.newline='\n']

function stringify (input, {
ascii = false,
commentPrefix = '# ',

@@ -128,2 +127,3 @@ defaultKey = '',

keySep = ' = ',
latin1 = true,
lineWidth = 80,

@@ -135,4 +135,4 @@ newline = '\n',

if (!Array.isArray(input)) input = toLines(input, pathSep, defaultKey)
const foldLine = getFold({ ascii, indent, lineWidth, newline: '\\' + newline })
const foldComment = getFold({ ascii, indent: commentPrefix, lineWidth, newline })
const foldLine = getFold({ indent, latin1, lineWidth, newline: '\\' + newline })
const foldComment = getFold({ indent: commentPrefix, latin1, lineWidth, newline })
return input

@@ -139,0 +139,0 @@ .map(line => Array.isArray(line) ? (

@@ -42,8 +42,8 @@ const fs = require('fs')

test('ascii', () => {
const src = 'ipsum áá éé lore\0'
const exp = 'ipsum \\u00e1\\u00e1 \\u00e9\\u00e9 lore\\u0000'
const src = 'ipsum áé ĐѺ lore\0'
const exp = 'ipsum áé \\u0110\\u047a lore\\u0000'
const res0 = stringify([['', src]], { keySep: '' })
const res1 = stringify([['', src]], { ascii: true, keySep: '' })
expect(res0).toBe(src.slice(0, -1) + '\\u0000')
expect(res1).toBe(exp)
const res1 = stringify([['', src]], { latin1: false, keySep: '' })
expect(res0).toBe(exp)
expect(res1).toBe(src.slice(0, -1) + '\\u0000')
})

@@ -50,0 +50,0 @@

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