Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Demo of the `convert()` method in JavaScript.
// This file can be directly run:
// - first install `unix-permissions`
// - then `node node_modules/unix-permissions/examples/methods/convert.js`
// An online demo is also available at:
// https://repl.it/@ehmicky/unix-permissions
'use strict'
// Ignore the following line: this is only needed for internal purposes.
require('../utils.js')
const { convert, positive } = require('unix-permissions')
console.log(convert.symbolic('111')) // 'a=x'
console.log(positive(convert.symbolic('111'))) // 'a+x'
console.log(convert.octal('o+x')) // '+0001'
console.log(convert.octal('o=x')) // '0001'
try {
convert.octal('z+x') // Throws an exception (permission syntax is invalid)
} catch (error) {
console.log(error.message)
}
const { convert } = require('unix-permissions')
console.log(convert.stat('720')) // 'rwx-w----'
console.log(convert.stat('7000')) // '--S--S--T'
console.log(convert.stat('\\720')) // 'rwx-w----'
console.log(convert.stat('0720')) // 'rwx-w----'
console.log(convert.stat('0o720')) // 'rwx-w----'
console.log(convert.symbolic('+720')) // 'u+rwx,g+w'
console.log(convert.symbolic('-720')) // 'u-rwx,g-w'
console.log(convert.symbolic('=720')) // 'u=rwx,g=w,o='
console.log(convert.stat('720')) // 'rwx-w----'
console.log(convert.stat('7000')) // '--S--S--T'
console.log(convert.stat('\\720')) // 'rwx-w----'
console.log(convert.stat('0720')) // 'rwx-w----'
console.log(convert.stat('0o720')) // 'rwx-w----'
console.log(convert.symbolic('+720')) // 'u+rwx,g+w'
console.log(convert.symbolic('-720')) // 'u-rwx,g-w'
console.log(convert.symbolic('=720')) // 'u=rwx,g=w,o='
// Ignore the following line: this is only needed for internal purposes.
require('../utils.js')
const { convert } = require('unix-permissions')
console.log(convert.stat('720')) // 'rwx-w----'
console.log(convert.stat('7000')) // '--S--S--T'
console.log(convert.stat('\\720')) // 'rwx-w----'
console.log(convert.stat('0720')) // 'rwx-w----'
console.log(convert.stat('0o720')) // 'rwx-w----'
console.log(convert.symbolic('+720')) // 'u+rwx,g+w'
console.log(convert.symbolic('-720')) // 'u-rwx,g-w'
console.log(convert.symbolic('=720')) // 'u=rwx,g=w,o='
// Demo of the `object` permission type in JavaScript.
// This file can be directly run:
// - first install `unix-permissions`
// - then `node node_modules/unix-permissions/examples/types/object.js`
// An online demo is also available at:
// https://repl.it/@ehmicky/unix-permissions
'use strict'
// Ignore the following line: this is only needed for internal purposes.
require('../utils.js')
const { convert } = require('unix-permissions')
console.log(convert.symbolic({ others: { read: true, execute: true } }))
// 'o+rx'
console.log(convert.symbolic({ others: { read: true, execute: false } }))
// 'o+r,o-x'
console.log(convert.symbolic({ others: { read: true, execute: undefined } }))
// 'o+r'
console.log(convert.symbolic({ all: { read: true } }))
// 'a+r'
console.log(convert.symbolic({}))
// 'a+'
console.log(
convert.symbolic({ special: { setuid: true, setgid: true, sticky: true } }),