i18next-fs-backend
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -31,3 +31,34 @@ "use strict"; | ||
function dirname(path) { | ||
if (path.length === 0) return '.'; | ||
var code = path.charCodeAt(0); | ||
var hasRoot = code === 47; | ||
var end = -1; | ||
var matchedSlash = true; | ||
for (var i = path.length - 1; i >= 1; --i) { | ||
code = path.charCodeAt(i); | ||
if (code === 47) { | ||
if (!matchedSlash) { | ||
end = i; | ||
break; | ||
} | ||
} else { | ||
matchedSlash = false; | ||
} | ||
} | ||
if (end === -1) return hasRoot ? '/' : '.'; | ||
if (hasRoot && end === 1) return '//'; | ||
return path.slice(0, end); | ||
} | ||
var writeFileInNodeSync = function writeFileInNodeSync(filename, payload) { | ||
try { | ||
fs.mkdirSync(dirname(filename), { | ||
recursive: true | ||
}); | ||
} catch (err) {} | ||
return fs.writeFileSync(filename, payload, 'utf8'); | ||
@@ -38,4 +69,8 @@ }; | ||
return new Promise(function (resolve, reject) { | ||
return fs.writeFile(filename, payload, 'utf8', function (err, data) { | ||
return err ? reject(err) : resolve(data); | ||
fs.mkdir(dirname(filename), { | ||
recursive: true | ||
}, function () { | ||
fs.writeFile(filename, payload, 'utf8', function (err, data) { | ||
return err ? reject(err) : resolve(data); | ||
}); | ||
}); | ||
@@ -60,2 +95,9 @@ }); | ||
var data = encoder.encode(payload); | ||
try { | ||
Deno.mkdirSync(dirname(filename), { | ||
recursive: true | ||
}); | ||
} catch (err) {} | ||
Deno.writeFileSync(filename, data); | ||
@@ -67,3 +109,11 @@ }; | ||
var data = encoder.encode(payload); | ||
return Deno.writeFile(filename, data); | ||
return new Promise(function (resolve, reject) { | ||
Deno.mkdir(dirname(filename), { | ||
recursive: true | ||
}).then(function () { | ||
Deno.writeFile(filename, data).then(resolve, reject); | ||
}).catch(function () { | ||
Deno.writeFile(filename, data).then(resolve, reject); | ||
}); | ||
}); | ||
}; | ||
@@ -70,0 +120,0 @@ |
@@ -9,3 +9,34 @@ import JSON5 from './formats/json5.js'; | ||
function dirname(path) { | ||
if (path.length === 0) return '.'; | ||
var code = path.charCodeAt(0); | ||
var hasRoot = code === 47; | ||
var end = -1; | ||
var matchedSlash = true; | ||
for (var i = path.length - 1; i >= 1; --i) { | ||
code = path.charCodeAt(i); | ||
if (code === 47) { | ||
if (!matchedSlash) { | ||
end = i; | ||
break; | ||
} | ||
} else { | ||
matchedSlash = false; | ||
} | ||
} | ||
if (end === -1) return hasRoot ? '/' : '.'; | ||
if (hasRoot && end === 1) return '//'; | ||
return path.slice(0, end); | ||
} | ||
var writeFileInNodeSync = function writeFileInNodeSync(filename, payload) { | ||
try { | ||
fs.mkdirSync(dirname(filename), { | ||
recursive: true | ||
}); | ||
} catch (err) {} | ||
return fs.writeFileSync(filename, payload, 'utf8'); | ||
@@ -16,4 +47,8 @@ }; | ||
return new Promise(function (resolve, reject) { | ||
return fs.writeFile(filename, payload, 'utf8', function (err, data) { | ||
return err ? reject(err) : resolve(data); | ||
fs.mkdir(dirname(filename), { | ||
recursive: true | ||
}, function () { | ||
fs.writeFile(filename, payload, 'utf8', function (err, data) { | ||
return err ? reject(err) : resolve(data); | ||
}); | ||
}); | ||
@@ -38,2 +73,9 @@ }); | ||
var data = encoder.encode(payload); | ||
try { | ||
Deno.mkdirSync(dirname(filename), { | ||
recursive: true | ||
}); | ||
} catch (err) {} | ||
Deno.writeFileSync(filename, data); | ||
@@ -45,3 +87,11 @@ }; | ||
var data = encoder.encode(payload); | ||
return Deno.writeFile(filename, data); | ||
return new Promise(function (resolve, reject) { | ||
Deno.mkdir(dirname(filename), { | ||
recursive: true | ||
}).then(function () { | ||
Deno.writeFile(filename, data).then(resolve, reject); | ||
}).catch(function () { | ||
Deno.writeFile(filename, data).then(resolve, reject); | ||
}); | ||
}); | ||
}; | ||
@@ -48,0 +98,0 @@ |
@@ -10,3 +10,30 @@ import JSON5 from './formats/json5.js' | ||
function dirname (path) { | ||
if (path.length === 0) return '.' | ||
let code = path.charCodeAt(0) | ||
const hasRoot = code === 47 | ||
let end = -1 | ||
let matchedSlash = true | ||
for (let i = path.length - 1; i >= 1; --i) { | ||
code = path.charCodeAt(i) | ||
if (code === 47) { | ||
if (!matchedSlash) { | ||
end = i | ||
break | ||
} | ||
} else { | ||
// We saw the first non-path separator | ||
matchedSlash = false | ||
} | ||
} | ||
if (end === -1) return hasRoot ? '/' : '.' | ||
if (hasRoot && end === 1) return '//' | ||
return path.slice(0, end) | ||
} | ||
const writeFileInNodeSync = (filename, payload) => { | ||
try { | ||
fs.mkdirSync(dirname(filename), { recursive: true }) | ||
} catch (err) {} | ||
return fs.writeFileSync(filename, payload, 'utf8') | ||
@@ -16,3 +43,7 @@ } | ||
const writeFileInNode = (filename, payload) => { | ||
return new Promise((resolve, reject) => fs.writeFile(filename, payload, 'utf8', (err, data) => err ? reject(err) : resolve(data))) | ||
return new Promise((resolve, reject) => { | ||
fs.mkdir(dirname(filename), { recursive: true }, () => { | ||
fs.writeFile(filename, payload, 'utf8', (err, data) => err ? reject(err) : resolve(data)) | ||
}) | ||
}) | ||
} | ||
@@ -31,2 +62,6 @@ | ||
const data = encoder.encode(payload) | ||
try { | ||
// eslint-disable-next-line no-undef | ||
Deno.mkdirSync(dirname(filename), { recursive: true }) | ||
} catch (err) {} | ||
// eslint-disable-next-line no-undef | ||
@@ -39,4 +74,12 @@ Deno.writeFileSync(filename, data) | ||
const data = encoder.encode(payload) | ||
// eslint-disable-next-line no-undef | ||
return Deno.writeFile(filename, data) | ||
return new Promise((resolve, reject) => { | ||
// eslint-disable-next-line no-undef | ||
Deno.mkdir(dirname(filename), { recursive: true }).then(() => { | ||
// eslint-disable-next-line no-undef | ||
Deno.writeFile(filename, data).then(resolve, reject) | ||
}).catch(() => { | ||
// eslint-disable-next-line no-undef | ||
Deno.writeFile(filename, data).then(resolve, reject) | ||
}) | ||
}) | ||
} | ||
@@ -43,0 +86,0 @@ |
{ | ||
"name": "i18next-fs-backend", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
484919
13590